[issue8047] Serialiser in ElementTree returns unicode strings in Py3k

Florent Xicluna report at bugs.python.org
Sun Mar 14 11:59:42 CET 2010


Florent Xicluna <florent.xicluna at gmail.com> added the comment:

Currently "tree.write(file)" returns Unicode in 3.1 (and 3.x).
I would propose the following change:

>>> tree.write(file)
#  ==>  encode to ASCII without xml declaration (compatible 2.x)
>>> tree.write(file, encoding="utf-8")
#  ==>  encode to UTF-8 without xml declaration (compatible 2.x + 3.1)
>>> tree.write(file, encoding=False)
#  ==>  output Unicode, without xml declaration (compatible 3.1)

The "xml_declaration" keyword argument can be set to True explicitly.

For compatibility with lxml.etree, "encoding=str" returns the same as "encoding=False".

Functions tostring() and tostringlist() will inherit the same behavior.
This change could be backported to 2.7, because it is backward compatible.

See proposed patch for implementation details.

----------
keywords: +patch
Added file: http://bugs.python.org/file16543/issue8047_etree_encoding.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8047>
_______________________________________


More information about the Python-bugs-list mailing list