Commit 905d6592 authored by Christian Ledermann's avatar Christian Ledermann

Merge pull request #15 from jwhelland/master

Handle case where Feature booleans are 'true' or 'false' during parsing, No need to preserve the original values if they are in violation of the specification, we may need to adjust isOpen and visibility so it defaults to the specifications default values
parents 272c6d25 0f882d7b
......@@ -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