czml
czml copied to clipboard
Demo broken in Python 3.6. czml.CZML().load() is not working
This is the code
# Import the library
from czml import czml
if __name__ == "__main__":
# Read an existing CZML file
filename = 'data/simple.czml'
with open(filename, 'r') as example:
doc = czml.CZML()
doc.loads(example.read())
print(doc)
pass
Its failing on isinstance(description, Description) on line 1393 in czml.py. It apparently a unicode string is not an instance of Description.
Errors here:
File "C:\Users\...\venv\lib\site-packages\czml\czml.py", line 1402, in description
raise TypeError
TypeError
Here is the CZML file (super_simple.czml).
[
{
"id":"document",
"name":"simple",
"version":"1.0",
"clock":{
"interval":"2012-03-15T10:00:00Z/2012-03-16T10:00:00Z",
"currentTime":"2012-03-15T10:00:00Z",
"multiplier":60,
"range":"LOOP_STOP",
"step":"SYSTEM_CLOCK_MULTIPLIER"
}
},
{
"id":"0653255a-81a7-4c2c-b154-f987e54767ac",
"name":"Accesses",
"description":"<p>List of Accesses</p>"
}
]
Apparently this patch will fix the issue:
class _CZMLBaseObject(object):
...
def load(self, data):
if hasattr(data, 'iteritems'):
# python 2
iterator = data.iteritems
elif hasattr(data, 'items'):
# python 3
iterator = data.items
for k, v in iterator():
if k:
if k in self.properties:
setattr(self, k, v)
else:
raise ValueError('The property "%s" is not defined for the class "%s"' % (k, self.__class__))
This is not specific to Python 3.6, happens to other versions of Python as well. The Cesium Sandcastle parses the CZML without complains, but in any case if there is any problem I agree the error should be more informative.
Simplest way to reproduce:
In [13]: CZMLPacket(description="DESCRIPTION")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-3275745c41cd> in <module>
----> 1 CZMLPacket(description="DESCRIPTION")
~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/czml/czml.py in __init__(self, **kwargs)
130 """Default init functionality is to load kwargs
131 """
--> 132 self.load(kwargs)
133
134 @property
~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/czml/czml.py in load(self, data)
1646 property_value = data.get(property_name, None)
1647 if property_value is not None:
-> 1648 setattr(self, property_name, property_value)
1649
1650
~/.miniconda36/envs/poliastro37/lib/python3.7/site-packages/czml/czml.py in description(self, description)
1400 self._description = None
1401 else:
-> 1402 raise TypeError
1403
1404 @property
TypeError:
Beacuse this is the expected way of doing it:
In [1]: from czml import CZMLPacket
In [2]: from czml.czml import Description
In [3]: CZMLPacket(description=Description("DESCRIPTION"))
Out[3]: <czml.czml.CZMLPacket at 0x7f6841e13cc0>
However, this was fixed in #28. I wonder if @cleder is still maintaining the project and willing to make a release?
updata it please, we need it