#
# This file is part of Nominatim. (https://nominatim.org)
#
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
# For a full list of authors see the git log.
"""
Classes wrapping HTTP responses from the Nominatim API.
else:
self.result = [self.result]
-
def _parse_geojson(self):
self._parse_json()
if self.result:
new['__' + k] = v
self.result.append(new)
-
def _parse_geocodejson(self):
self._parse_geojson()
if self.result:
inner = r.pop('geocoding')
r.update(inner)
-
def assert_address_field(self, idx, field, value):
""" Check that result rows`idx` has a field `field` with value `value`
in its address. If idx is None, then all results are checked.
address = self.result[idx]['address']
self.check_row_field(idx, field, value, base=address)
-
def match_row(self, row, context=None, field=None):
""" Match the result fields against the given behave table row.
"""
else:
self.check_row_field(i, name, Field(value), base=subdict)
-
def check_row(self, idx, check, msg):
""" Assert for the condition 'check' and print 'msg' on fail together
with the contents of the failing result.
assert check, _RowError(self.result[idx])
-
def check_row_field(self, idx, field, expected, base=None):
""" Check field 'field' of result 'idx' for the expected value
and print a meaningful error if the condition fails.
f"\nBad value for field '{field}'. Expected: {expected}, got: {value}")
-
class SearchResponse(GenericResponse):
""" Specialised class for search and lookup responses.
Transforms the xml response in a format similar to json.
assert 'namedetails' not in self.result[0], "More than one namedetails in result"
self.result[0]['namedetails'] = {}
for tag in child:
- assert len(tag) == 0, f"Namedetails element '{tag.attrib['desc']}' has subelements"
+ assert len(tag) == 0, \
+ f"Namedetails element '{tag.attrib['desc']}' has subelements"
self.result[0]['namedetails'][tag.attrib['desc']] = tag.text
elif child.tag == 'geokml':
assert 'geokml' not in self.result[0], "More than one geokml in result"