self.assertEqual(result.getvalue(), start + "<doc> </doc>")
+ def test_xmlgen_encoding_bytes(self):
+ encodings = ('iso-8859-15', 'utf-8',
+ 'utf-16be', 'utf-16le',
+ 'utf-32be', 'utf-32le')
+ for encoding in encodings:
+ result = self.ioclass()
+ gen = XMLGenerator(result, encoding=encoding)
+
+ gen.startDocument()
+ gen.startElement("doc", {"a": u'\u20ac'})
+ gen.characters(u"\u20ac".encode(encoding))
+ gen.ignorableWhitespace(" ".encode(encoding))
+ gen.endElement("doc")
+ gen.endDocument()
+
+ self.assertEqual(result.getvalue(), (
+ u'<?xml version="1.0" encoding="%s"?>\n'
+ u'<doc a="\u20ac">\u20ac </doc>' % encoding
+ ).encode(encoding, 'xmlcharrefreplace'))
+
def test_xmlgen_ns(self):
result = self.ioclass()
gen = XMLGenerator(result)
self._write(u'</%s>' % self._qname(name))
def characters(self, content):
- self._write(escape(unicode(content)))
+ if not isinstance(content, unicode):
+ content = unicode(content, self._encoding)
+ self._write(escape(content))
def ignorableWhitespace(self, content):
- self._write(unicode(content))
+ if not isinstance(content, unicode):
+ content = unicode(content, self._encoding)
+ self._write(content)
def processingInstruction(self, target, data):
self._write(u'<?%s %s?>' % (target, data))
Library
-------
+- Issue #17606: Fixed support of encoded byte strings in the XMLGenerator
+ .characters() and ignorableWhitespace() methods. Original patch by Sebastian
+ Ortiz Vasquez.
+
- Issue #16601: Restarting iteration over tarfile no more continues from where
it left off. Patch by Michael Birtwell.