diff options
author | Eli Bendersky <eliben@gmail.com> | 2012-07-17 02:45:11 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2012-07-17 02:45:11 (GMT) |
commit | 426e248febc4b86ea4512baaaa81966ab54c83da (patch) | |
tree | e328da11b7ab6473ef0e212e21d39b3fb2ceb025 | |
parent | daa4c6b2e68c8ab0d929d9f00db45819431b4e3d (diff) | |
download | cpython-426e248febc4b86ea4512baaaa81966ab54c83da.zip cpython-426e248febc4b86ea4512baaaa81966ab54c83da.tar.gz cpython-426e248febc4b86ea4512baaaa81966ab54c83da.tar.bz2 |
Preserve the invariant tostring(elem) == b''.join(tostringlist(elem)) and add a test to make sure it keeps working
-rw-r--r-- | Lib/test/test_xml_etree.py | 9 | ||||
-rw-r--r-- | Lib/xml/etree/ElementTree.py | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index d90f978..da1ad09 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -2286,6 +2286,15 @@ class IOTest(unittest.TestCase): '''<?xml version='1.0' encoding='utf-16'?>\n''' '''<site />'''.encode("utf-16")) + def test_tostringlist_invariant(self): + root = ET.fromstring('<tag>foo</tag>') + self.assertEqual( + ET.tostring(root, 'unicode'), + ''.join(ET.tostringlist(root, 'unicode'))) + self.assertEqual( + ET.tostring(root, 'utf-16'), + b''.join(ET.tostringlist(root, 'utf-16'))) + class ParseErrorTest(unittest.TestCase): def test_subclass(self): diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 10bf849..3981659 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1190,9 +1190,15 @@ def tostringlist(element, encoding=None, method=None): def writable(self): return True + def seekable(self): + return True + def write(self, b): data.append(b) + def tell(self): + return len(data) + ElementTree(element).write(DataStream(), encoding, method=method) return data |