Commit 0f882d7b authored by Jason Helland's avatar Jason Helland

Handle case where Document booleans (visibility,isopen) are 'true' or 'false' when

parsing from string
parent 272c6d25
......@@ -493,10 +493,16 @@ class _Feature(_BaseObject):
self.description = description.text
visibility = element.find('%svisibility' % self.ns)
if visibility is not None:
self.visibility = int(visibility.text)
if visibility.text in ['1', 'true']:
self.visibility = 1
else:
self.visibility = 0
isopen = element.find('%sopen' % self.ns)
if isopen is not None:
self.isopen = int(isopen.text)
if isopen.text in ['1', 'true']:
self.isopen = 1
else:
self.isopen = 0
styles = element.findall('%sStyle' % self.ns)
for style in styles:
s = Style(self.ns)
......
......@@ -362,6 +362,30 @@ class KmlFromStringTestCase(unittest.TestCase):
k2.from_string(k.to_string())
self.assertEqual(k.to_string(), k2.to_string())
def test_document_booleans(self):
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document targetId="someTargetId">
<name>Document.kml</name>
<visibility>true</visibility>
<open>1</open>
</Document>
</kml>"""
k = kml.KML()
k.from_string(doc)
self.assertEqual(list(k.features())[0].visibility, 1)
self.assertEqual(list(k.features())[0].isopen, 1)
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Document targetId="someTargetId">
<name>Document.kml</name>
<visibility>0</visibility>
<open>false</open>
</Document>
</kml>"""
k = kml.KML()
k.from_string(doc)
self.assertEqual(list(k.features())[0].visibility, 0)
self.assertEqual(list(k.features())[0].isopen, 0)
def test_folders(self):
doc = """<kml xmlns="http://www.opengis.net/kml/2.2">
<Folder>
......
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