[issue1470548] Bugfix for #1470540 (XMLGenerator cannot output UTF-16)

Serhiy Storchaka report at bugs.python.org
Wed May 30 09:57:38 CEST 2012


Serhiy Storchaka <storchaka at gmail.com> added the comment:

Oh, I see XMLGenerator completely outdated. It even has not been ported to Python 3. See function _write:

    def _write(self, text):
        if isinstance(text, str):
            self._out.write(text)
        else:
            self._out.write(text.encode(self._encoding, _error_handling))

In Python 2 there was a choice between bytes and unicode strings. But in Python 3 encoding never happens.

XMLGenerator does not distinguish between binary and text streams.

Here is a patch that fixes the work of XMLGenerator in Python 3. Unfortunately, it is impossible to avoid the loss of backward compatibility. I tried to keep the code to work for the most common cases, but some code which "worked" before may break (including I had to correct some tests).

----------
Added file: http://bugs.python.org/file25760/XMLGenerator.patch

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


More information about the Python-bugs-list mailing list