address.py: changed update check of address string
authorFredrik Unger <fred@tree.se>
Fri, 18 Jan 2013 10:49:13 +0000 (11:49 +0100)
committerFredrik Unger <fred@tree.se>
Fri, 18 Jan 2013 10:49:13 +0000 (11:49 +0100)
If nominatim data does not exists (eg postcode is not there, but boundary or vice
versa) then the old code failed with NoneType object.
This addresses this but is not optimal.
Current tests works with the sites, so using this solution for now.

xinclude/address.py

index 30e8a0713efcfd546e1fc6fa20d5860a7a55b498..6a30d7accc13006f17d337ff30ddc6a2c86f8c18 100755 (executable)
@@ -135,7 +135,9 @@ def c(s):
     return s or ''
 
 def s(s,n):
-    return s or n
+    if n is not None:
+        return s or n.text
+    return s
 
 
 class Address(object):
@@ -181,10 +183,11 @@ class Address(object):
             places = int(root.xpath('count(//place[@place_id])'))
             if places == 1:
                 place = root.find("place")
-                self.postcode = s(self.postcode,place.find("boundary").text)
-                self.city = s(self.city,place.find("city").text)
-                self.country = s(self.country,place.find("country").text)
-                self.country_code = s(self.country_code,place.find("country_code").text)
+#                print etree.tostring(place,encoding='UTF-8',pretty_print=True)
+                self.postcode = s(self.postcode,place.find("postcode"))
+                self.city = s(self.city,place.find("city"))
+                self.country = s(self.country,place.find("country"))
+                self.country_code = s(self.country_code,place.find("country_code"))
                 self.coord=Coord(place.get("lat"),place.get("lon"))
                 return