classification
Title: startElementNS in xml.sax.saxutils.XMLGenerator ignored encoding
Type: behavior Stage: test needed
Components: XML Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, ezio.melotti, gromgull
Priority: normal Keywords:

Created on 2011-03-23 13:30 by gromgull, last changed 2011-03-26 19:10 by ezio.melotti.

Files
File name Uploaded Description Edit
xmltest.py gromgull, 2011-03-25 10:34
Messages (3)
msg131863 - (view) Author: Gunnar Aastrand Grimnes (gromgull) Date: 2011-03-23 13:30
The startElementNS method in the XMLGenerator ignores the encoding set. 

it does: 

self._out.write(' xmlns:%s="%s"' % (prefix, uri))

whereas it should have done: 

self._write(' xmlns:%s="%s"' % (prefix, uri))

Issue 938076 was similar to this, but for a different method.
msg131879 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-03-23 14:45
Do you have a test or a small script which shows the incorrect output?
msg132077 - (view) Author: Gunnar Aastrand Grimnes (gromgull) Date: 2011-03-25 10:34
I came across the bug when trying to write XML documents to StringIO objects. This does not work, since the output contains a mix of unicode and str objects, and StringIO gets confused. 

A better alternative is to use io.BytesIO, since all output should be encoded, but this also throws an error since it gets some unicode objects. 

The attached file breaks for both cases (comment/uncomment StringIO to test)
History
Date User Action Args
2011-03-26 19:10:25ezio.melottisetnosy: + ezio.melotti
2011-03-25 10:34:28gromgullsetfiles: + xmltest.py

messages: + msg132077
2011-03-23 14:45:21amaury.forgeotdarcsetnosy: + amaury.forgeotdarc

messages: + msg131879
stage: test needed
2011-03-23 13:30:22gromgullcreate