Added attribute checks when parsing wrmap.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 15 Aug 2013 11:24:14 +0000 (11:24 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 15 Aug 2013 11:24:14 +0000 (11:24 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@1520 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrpylib/wrmwmarkup.py

index f54e8ebf0a993b4e92ffd3630e1ba8f4658f09c6..28ac1538887800f07a344dd78b8482759af5f7cf 100644 (file)
@@ -467,13 +467,28 @@ def parse_wrmap(wikitext):
         'type': 'FeatureCollection',
         'features': json_features}
 
         'type': 'FeatureCollection',
         'features': json_features}
 
-    # attributes # TODO: check
+    # attributes
     attributes = {}
     attributes = {}
-    attributes['lat']    = float(wrmap_xml.attrib.get('lat', 47.267648)) # center lat
-    attributes['lon']    = float(wrmap_xml.attrib.get('lon', 11.404655)) # center lon
-    attributes['zoom']   = int(wrmap_xml.attrib.get('zoom', 10))         # Google Zoom Level
-    attributes['width']  = int(wrmap_xml.attrib['width']) if wrmap_xml.attrib.has_key('width') else None # None corresponds to 100%
-    attributes['height'] = int(wrmap_xml.attrib.get('height', 450))      # map height in px
+    try:
+        attributes['lat'] = float(wrmap_xml.attrib.get('lat', 47.267648)) # center lat
+    except ValueError:
+        raise RuntimeError('Attribute "lat" has to be a float value.')
+    try:
+        attributes['lon'] = float(wrmap_xml.attrib.get('lon', 11.404655)) # center lon
+    except ValueError:
+        raise RuntimeError('Attribute "lon" has to be a float value.')
+    try:
+        attributes['zoom'] = int(wrmap_xml.attrib.get('zoom', 10)) # Google Zoom Level
+    except ValueError:
+        raise RuntimeError('Attribute "zoom" has to be an integer value.')
+    try:
+        attributes['width'] = int(wrmap_xml.attrib['width']) if wrmap_xml.attrib.has_key('width') else None # None corresponds to 100%
+    except ValueError:
+        raise RuntimeError('Attribute "width" has to be an integer value.')
+    try:
+        attributes['height'] = int(wrmap_xml.attrib.get('height', 450)) # map height in px
+    except ValueError:
+        raise RuntimeError('Attribute "height" has to be an integer value.')
     # show_sledruns = (wrmap_xml.tag == 'wrgmap')
 
     return attributes, json
     # show_sledruns = (wrmap_xml.tag == 'wrgmap')
 
     return attributes, json