1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Output formatters for API version v1.
10 from nominatim.api.result_formatting import FormatDispatcher
11 from nominatim.api import StatusResult
12 from nominatim.utils.json_writer import JsonWriter
14 dispatch = FormatDispatcher()
16 @dispatch.format_func(StatusResult, 'text')
17 def _format_status_text(result: StatusResult) -> str:
19 return f"ERROR: {result.message}"
24 @dispatch.format_func(StatusResult, 'json')
25 def _format_status_json(result: StatusResult) -> str:
29 .keyval('status', result.status)\
30 .keyval('message', result.message)\
31 .keyval_not_none('data_updated', result.data_updated,
32 lambda v: v.isoformat())\
33 .keyval('software_version', str(result.software_version))\
34 .keyval_not_none('database_version', result.database_version, str)\