Commit 3068aed9 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #17606: Fixed support of encoded byte strings in the XMLGenerator

characters() and ignorableWhitespace() methods.  Original patch by Sebastian
Ortiz Vasquez.
parents 7025349a 3eab6b36
...@@ -319,6 +319,24 @@ class XmlgenTest: ...@@ -319,6 +319,24 @@ class XmlgenTest:
self.assertEqual(result.getvalue(), self.xml("<doc> </doc>")) self.assertEqual(result.getvalue(), self.xml("<doc> </doc>"))
def test_xmlgen_encoding_bytes(self):
encodings = ('iso-8859-15', 'utf-8', 'utf-8-sig',
'utf-16', 'utf-16be', 'utf-16le',
'utf-32', 'utf-32be', 'utf-32le')
for encoding in encodings:
result = self.ioclass()
gen = XMLGenerator(result, encoding=encoding)
gen.startDocument()
gen.startElement("doc", {"a": '\u20ac'})
gen.characters("\u20ac".encode(encoding))
gen.ignorableWhitespace(" ".encode(encoding))
gen.endElement("doc")
gen.endDocument()
self.assertEqual(result.getvalue(),
self.xml('<doc a="\u20ac">\u20ac </doc>', encoding=encoding))
def test_xmlgen_ns(self): def test_xmlgen_ns(self):
result = self.ioclass() result = self.ioclass()
gen = XMLGenerator(result) gen = XMLGenerator(result)
......
...@@ -209,11 +209,15 @@ class XMLGenerator(handler.ContentHandler): ...@@ -209,11 +209,15 @@ class XMLGenerator(handler.ContentHandler):
def characters(self, content): def characters(self, content):
if content: if content:
self._finish_pending_start_element() self._finish_pending_start_element()
if not isinstance(content, str):
content = str(content, self._encoding)
self._write(escape(content)) self._write(escape(content))
def ignorableWhitespace(self, content): def ignorableWhitespace(self, content):
if content: if content:
self._finish_pending_start_element() self._finish_pending_start_element()
if not isinstance(content, str):
content = str(content, self._encoding)
self._write(content) self._write(content)
def processingInstruction(self, target, data): def processingInstruction(self, target, data):
......
...@@ -1281,6 +1281,7 @@ Kyle VanderBeek ...@@ -1281,6 +1281,7 @@ Kyle VanderBeek
Andrew Vant Andrew Vant
Atul Varma Atul Varma
Dmitry Vasiliev Dmitry Vasiliev
Sebastian Ortiz Vasquez
Alexandre Vassalotti Alexandre Vassalotti
Nadeem Vawda Nadeem Vawda
Frank Vercruesse Frank Vercruesse
......
...@@ -91,6 +91,10 @@ Core and Builtins ...@@ -91,6 +91,10 @@ Core and Builtins
Library Library
------- -------
- Issue #17606: Fixed support of encoded byte strings in the XMLGenerator
.characters() and ignorableWhitespace() methods. Original patch by Sebastian
Ortiz Vasquez.
- Issue #17732: Ignore distutils.cfg options pertaining to install paths if a - Issue #17732: Ignore distutils.cfg options pertaining to install paths if a
virtual environment is active. virtual environment is active.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment