+ self.header = dict(et.attrib)
+ self.result = []
+
+ for child in et:
+ if child.tag == 'result':
+ eq_(0, len(self.result), "More than one result in reverse result")
+ self.result.append(dict(child.attrib))
+ elif child.tag == 'addressparts':
+ address = {}
+ for sub in child:
+ address[sub.tag] = sub.text
+ self.result[0]['address'] = address
+ elif child.tag == 'extratags':
+ self.result[0]['extratags'] = {}
+ for tag in child:
+ self.result[0]['extratags'][tag.attrib['key']] = tag.attrib['value']
+ elif child.tag == 'namedetails':
+ self.result[0]['namedetails'] = {}
+ for tag in child:
+ self.result[0]['namedetails'][tag.attrib['desc']] = tag.text
+ elif child.tag in ('geokml'):
+ self.result[0][child.tag] = True
+ else:
+ assert child.tag == 'error', \
+ "Unknown XML tag %s on page: %s" % (child.tag, self.page)
+
+
+class DetailsResponse(GenericResponse):
+
+ def __init__(self, page, fmt='json', errorcode=200):
+ self.page = page
+ self.format = fmt
+ self.errorcode = errorcode
+ self.result = []
+ self.header = dict()
+
+ if errorcode == 200:
+ getattr(self, 'parse_' + fmt)()
+
+ def parse_html(self):
+ content, errors = tidy_document(self.page,
+ options={'char-encoding' : 'utf8'})
+ self.result = {}
+
+ def parse_json(self):
+ self.result = [json.JSONDecoder(object_pairs_hook=OrderedDict).decode(self.page)]