- Cannot serialize
int
. I can see the value in not automatically serializing every possible object with a__str__
method. But, not converting an int? C'mon! - Cannot serilaize
None
. Wouldn'tNone
be the perfect value to indicate "don't serialize this attribute"?
Examples:
>>> import xml.etree.ElementTree as et >>> et.tostring(et.Element('Foo', attrib={ 'a': 1})) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 1009, in tostring ElementTree(element).write(file, encoding) File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 663, in write self._write(file, self._root, encoding, {}) File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 698, in _write _escape_attrib(v, encoding))) File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 830, in _escape_attrib _raise_serialization_error(text) File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 777, in _raise_serialization_error "cannot serialize %r (type %s)" % (text, type(text).__name__) TypeError: cannot serialize 1 (type int) >>> et.tostring(et.Element('Foo', attrib={ 'a': None})) Traceback (most recent call last): File " ", line 1, in File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 1009, in tostring ElementTree(element).write(file, encoding) File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 663, in write self._write(file, self._root, encoding, {}) File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 698, in _write _escape_attrib(v, encoding))) File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 830, in _escape_attrib _raise_serialization_error(text) File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 777, in _raise_serialization_error "cannot serialize %r (type %s)" % (text, type(text).__name__) TypeError: cannot serialize None (type NoneType)