Issue 1470540: XMLGenerator creates a mess with UTF-16 (original) (raw)

When output encoding in xml.sax.saxutils.XMLGenerator is set to UTF-16, the result is a terrible mess. Namely:

A test illustrating the issue is attached. The issue is applicable to both stable (2.4.3) and current (2.5) versions of Python.


Looking in xml/sax/saxutils.py, I see the problem in XMLGenerator._write():

The issue is easy to fix by using StreamWriter instead of a plain stream as the output sink. I am going to submit a patch shortly.

Regards, Nikolai Grigoriev