Message 158907 - Python tracker

Message158907

Author dabrahams
Recipients dabrahams, effbot, hugesmile
Date 2012-04-21.02:05:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1334973924.15.0.33877044084.issue1572710@psf.upfronthosting.co.za>
In-reply-to
Content
@effbot, I think you may have misread the OP's example.  The first two arguments /are/ being passed positionally.  In any case, there's a real bug here.  cElementTree seems to choke on uses of attrib.  Change cElementTree to ElementTree below and this one works, too.

>>> from xml.etree.cElementTree import Element, tostring
>>> print tostring(Element('foo', attrib={}))
Traceback (most recent call last):
  File "bug.py", line 2, in <module>
    print tostring(Element('foo', attrib={}))
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1127, in tostring
    ElementTree(element).write(file, encoding, method=method)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 821, in write
    serialize(write, self._root, encoding, qnames, namespaces)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 933, in _serialize_xml
    v = _escape_attrib(v, encoding)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1093, in _escape_attrib
    _raise_serialization_error(text)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1053, in _raise_serialization_error
    "cannot serialize %r (type %s)" % (text, type(text).__name__)
TypeError: cannot serialize {} (type dict)
History
Date User Action Args
2012-04-21 02:05:24dabrahamssetrecipients: + dabrahams, effbot, hugesmile
2012-04-21 02:05:24dabrahamssetmessageid: <1334973924.15.0.33877044084.issue1572710@psf.upfronthosting.co.za>
2012-04-21 02:05:23dabrahamslinkissue1572710 messages
2012-04-21 02:05:23dabrahamscreate