from ..config import Configuration
from .. import logging as loglib
from ..core import NominatimAPIAsync
+from ..result_formatting import FormatDispatcher
CONTENT_TEXT = 'text/plain; charset=utf-8'
CONTENT_XML = 'text/xml; charset=utf-8'
"""
content_type: str = CONTENT_TEXT
+
@abc.abstractmethod
def get(self, name: str, default: Optional[str] = None) -> Optional[str]:
""" Return an input parameter as a string. If the parameter was
body of the response to 'output'.
"""
+
@abc.abstractmethod
def base_uri(self) -> str:
""" Return the URI of the original request.
"""
+ @abc.abstractmethod
+ def formatting(self) -> FormatDispatcher:
+ """ Return the formatting object to use.
+ """
+
+
def get_int(self, name: str, default: Optional[int] = None) -> int:
""" Return an input parameter as an int. Raises an exception if
the parameter is given but not in an integer format.
from ...config import Configuration
from ...core import NominatimAPIAsync
from ... import v1 as api_impl
+from ...result_formatting import FormatDispatcher
+from ...v1.format import dispatch as formatting
from ... import logging as loglib
from ..asgi_adaptor import ASGIAdaptor, EndpointFunc
""" Adaptor class for server glue to Falcon framework.
"""
- def __init__(self, req: Request, resp: Response,
- config: Configuration) -> None:
+ def __init__(self, req: Request, resp: Response, config: Configuration) -> None:
self.request = req
self.response = resp
self._config = config
def config(self) -> Configuration:
return self._config
+ def formatting(self) -> FormatDispatcher:
+ return formatting
+
class EndpointWrapper:
""" Converter for server glue endpoint functions to Falcon request handlers.
from ..errors import UsageError
from .. import logging as loglib
from ..core import NominatimAPIAsync
-from .format import dispatch as formatting
from .format import RawDataList
from ..types import DataLayer, GeometryFormat, PlaceRef, PlaceID, OsmID, Point
from ..status import StatusResult
fmt = adaptor.get('format', default=default)
assert fmt is not None
- if not formatting.supports_format(result_type, fmt):
+ if not adaptor.formatting().supports_format(result_type, fmt):
adaptor.raise_error("Parameter 'format' must be one of: " +
- ', '.join(formatting.list_formats(result_type)))
+ ', '.join(adaptor.formatting().list_formats(result_type)))
adaptor.content_type = CONTENT_TYPE.get(fmt, CONTENT_JSON)
return fmt
else:
status_code = 200
- return build_response(params, formatting.format_result(result, fmt, {}),
+ return build_response(params, params.formatting().format_result(result, fmt, {}),
status=status_code)
if result is None:
params.raise_error('No place with that OSM ID found.', status=404)
- output = formatting.format_result(result, fmt,
+ output = params.formatting().format_result(result, fmt,
{'locales': locales,
'group_hierarchy': params.get_bool('group_hierarchy', False),
'icon_base_url': params.config().MAPICON_URL})
'namedetails': params.get_bool('namedetails', False),
'addressdetails': params.get_bool('addressdetails', True)}
- output = formatting.format_result(ReverseResults([result] if result else []),
- fmt, fmt_options)
+ output = params.formatting().format_result(ReverseResults([result] if result else []),
+ fmt, fmt_options)
return build_response(params, output, num_results=1 if result else 0)
'namedetails': params.get_bool('namedetails', False),
'addressdetails': params.get_bool('addressdetails', True)}
- output = formatting.format_result(results, fmt, fmt_options)
+ output = params.formatting().format_result(results, fmt, fmt_options)
return build_response(params, output, num_results=len(results))
'namedetails': params.get_bool('namedetails', False),
'addressdetails': params.get_bool('addressdetails', False)}
- output = formatting.format_result(results, fmt, fmt_options)
+ output = params.formatting().format_result(results, fmt, fmt_options)
return build_response(params, output, num_results=len(results))
""")
results = RawDataList(r._asdict() for r in await conn.execute(sql))
- return build_response(params, formatting.format_result(results, fmt, {}))
+ return build_response(params, params.formatting().format_result(results, fmt, {}))
async def polygons_endpoint(api: NominatimAPIAsync, params: ASGIAdaptor) -> Any:
results = RawDataList(r._asdict() for r in await conn.execute(sql, sql_params))
- return build_response(params, formatting.format_result(results, fmt, {}))
+ return build_response(params, params.formatting().format_result(results, fmt, {}))
ROUTES = [