Commit 93bfe7d8 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #1470548: Do not buffer XMLGenerator output.

Add test for fragment producing with XMLGenerator.
parent 5b2cf5e6
......@@ -403,6 +403,21 @@ class XmlgenTest:
func(result)
self.assertFalse(result.closed)
def test_xmlgen_fragment(self):
result = self.ioclass()
gen = XMLGenerator(result)
# Don't call gen.startDocument()
gen.startElement("foo", {"a": "1.0"})
gen.characters("Hello")
gen.endElement("foo")
gen.startElement("bar", {"b": "2.0"})
gen.endElement("bar")
# Don't call gen.endDocument()
self.assertEqual(result.getvalue(),
'<foo a="1.0">Hello</foo><bar b="2.0"></bar>')
class StringXmlgenTest(XmlgenTest, unittest.TestCase):
ioclass = StringIO
......
......@@ -98,9 +98,13 @@ def _gettextwriter(out, encoding):
except AttributeError:
pass
# wrap a binary writer with TextIOWrapper
return io.TextIOWrapper(buffer, encoding=encoding,
errors='xmlcharrefreplace',
newline='\n')
class UnbufferedTextIOWrapper(io.TextIOWrapper):
def write(self, s):
super(UnbufferedTextIOWrapper, self).write(s)
self.flush()
return UnbufferedTextIOWrapper(buffer, encoding=encoding,
errors='xmlcharrefreplace',
newline='\n')
class XMLGenerator(handler.ContentHandler):
......
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