Commit e0b744e6 authored by Ian Lee's avatar Ian Lee

Added support for address

parent f959be0b
...@@ -6,6 +6,7 @@ Changelog ...@@ -6,6 +6,7 @@ Changelog
----------------- -----------------
- back to development - back to development
- Add support for address
0.7 (2014/08/01) 0.7 (2014/08/01)
---------------- ----------------
......
...@@ -199,7 +199,7 @@ class _Feature(_BaseObject): ...@@ -199,7 +199,7 @@ class _Feature(_BaseObject):
_atom_link = None _atom_link = None
# Specifies the URL of the website containing this KML or KMZ file. # Specifies the URL of the website containing this KML or KMZ file.
# TODO address = None _address = None
# A string value representing an unstructured address written as a # A string value representing an unstructured address written as a
# standard street, city, state address, and/or as a postal code. # standard street, city, state address, and/or as a postal code.
# You can use the <address> tag to specify the location of a point # You can use the <address> tag to specify the location of a point
...@@ -441,6 +441,20 @@ class _Feature(_BaseObject): ...@@ -441,6 +441,20 @@ class _Feature(_BaseObject):
"Snippet must be dict of {'text':t, 'maxLines':i} or string" "Snippet must be dict of {'text':t, 'maxLines':i} or string"
) )
@property
def address(self):
if self._address:
return self._address
@address.setter
def address(self, address):
if isinstance(address, basestring):
self._address = address
elif address is None:
self._address = None
else:
raise ValueError
def etree_element(self): def etree_element(self):
element = super(_Feature, self).etree_element() element = super(_Feature, self).etree_element()
if self.name: if self.name:
...@@ -481,6 +495,9 @@ class _Feature(_BaseObject): ...@@ -481,6 +495,9 @@ class _Feature(_BaseObject):
element.append(self._atom_author.etree_element()) element.append(self._atom_author.etree_element())
if self.extended_data is not None: if self.extended_data is not None:
element.append(self.extended_data.etree_element()) element.append(self.extended_data.etree_element())
if self._address is not None:
address = etree.SubElement(element, '%saddress' % self.ns)
address.text = self._address
return element return element
def from_element(self, element): def from_element(self, element):
...@@ -553,6 +570,9 @@ class _Feature(_BaseObject): ...@@ -553,6 +570,9 @@ class _Feature(_BaseObject):
# logger.warn( # logger.warn(
# 'arbitrary or typed extended data is not yet supported' # 'arbitrary or typed extended data is not yet supported'
# ) # )
address = element.find('%saddress' % self.ns)
if address is not None:
self.address = address.text
class _Container(_Feature): class _Container(_Feature):
...@@ -769,7 +789,7 @@ class _TimePrimitive(_BaseObject): ...@@ -769,7 +789,7 @@ class _TimePrimitive(_BaseObject):
RESOLUTIONS = ['gYear', 'gYearMonth', 'date', 'dateTime'] RESOLUTIONS = ['gYear', 'gYearMonth', 'date', 'dateTime']
def get_resolution(self, dt, resolution): def get_resolution(self, dt, resolution=None):
if resolution: if resolution:
if resolution not in self.RESOLUTIONS: if resolution not in self.RESOLUTIONS:
raise ValueError raise ValueError
......
...@@ -73,7 +73,7 @@ class BaseClassesTestCase(unittest.TestCase): ...@@ -73,7 +73,7 @@ class BaseClassesTestCase(unittest.TestCase):
self.assertEqual(f.isopen, 0) self.assertEqual(f.isopen, 0)
self.assertEqual(f._atom_author, None) self.assertEqual(f._atom_author, None)
self.assertEqual(f._atom_link, None) self.assertEqual(f._atom_link, None)
# self.assertEqual(f.address, None) self.assertEqual(f.address, None)
# self.assertEqual(f.phoneNumber, None) # self.assertEqual(f.phoneNumber, None)
self.assertEqual(f._snippet, None) self.assertEqual(f._snippet, None)
self.assertEqual(f.description, None) self.assertEqual(f.description, None)
...@@ -326,6 +326,13 @@ class BuildKmlTestCase(unittest.TestCase): ...@@ -326,6 +326,13 @@ class BuildKmlTestCase(unittest.TestCase):
self.assertEqual(d.to_string(), d2.to_string()) self.assertEqual(d.to_string(), d2.to_string())
d.link = None d.link = None
def test_address(self):
address = '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA'
d = kml.Document()
d.address = address
self.assertTrue(address in str(d.to_string()))
self.assertTrue('address>' in str(d.to_string()))
class KmlFromStringTestCase(unittest.TestCase): class KmlFromStringTestCase(unittest.TestCase):
def test_document(self): def test_document(self):
...@@ -811,6 +818,22 @@ class KmlFromStringTestCase(unittest.TestCase): ...@@ -811,6 +818,22 @@ class KmlFromStringTestCase(unittest.TestCase):
doc = kml.KML() doc = kml.KML()
self.assertRaises(TypeError, doc.from_string, '<xml></xml>') self.assertRaises(TypeError, doc.from_string, '<xml></xml>')
def test_address(self):
doc = kml.Document()
doc.from_string("""
<kml:Document xmlns:kml="http://www.opengis.net/kml/2.2" id="pm-id">
<kml:name>pm-name</kml:name>
<kml:description>pm-description</kml:description>
<kml:visibility>1</kml:visibility>
<kml:address>3901 Holly Dr, San Jose, CA 95060</kml:address>
</kml:Document>
""")
doc2 = kml.Document()
doc2.from_string(doc.to_string())
self.assertEqual(doc.to_string(), doc2.to_string())
class StyleTestCase(unittest.TestCase): class StyleTestCase(unittest.TestCase):
def test_styleurl(self): def test_styleurl(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment