Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1378)

Unified Diff: Lib/test/test_xml_etree.py

Issue 664043: Issue 8047: Serialiser in ElementTree returns unicode strings in Py3k Base URL: http://svn.python.org/view/*checkout*/python/branches/py3k/
Patch Set: Use encoding="unicode" Created 13 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Doc/library/xml.etree.elementtree.rst ('k') | Lib/xml/etree/ElementTree.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Lib/test/test_xml_etree.py
===================================================================
--- Lib/test/test_xml_etree.py (revision 83346)
+++ Lib/test/test_xml_etree.py (working copy)
@@ -66,14 +66,14 @@
if not hasattr(method, '__call__'):
print(method, "not callable")
-def serialize(elem, to_string=True, **options):
+def serialize(elem, to_string=True, encoding='unicode', **options):
import io
- if options.get("encoding"):
+ if encoding != 'unicode':
file = io.BytesIO()
else:
file = io.StringIO()
tree = ET.ElementTree(elem)
- tree.write(file, **options)
+ tree.write(file, encoding=encoding, **options)
if to_string:
return file.getvalue()
else:
@@ -532,7 +532,7 @@
>>> elem.set('testa', 'testval')
>>> elem.set('testb', 'test2')
>>> ET.tostring(elem)
- '<test testa="testval" testb="test2">aa</test>'
+ b'<test testa="testval" testb="test2">aa</test>'
>>> sorted(elem.keys())
['testa', 'testb']
>>> sorted(elem.items())
@@ -542,7 +542,7 @@
>>> elem.attrib['testb'] = 'test1'
>>> elem.attrib['testc'] = 'test2'
>>> ET.tostring(elem)
- '<test testa="testval" testb="test1" testc="test2">aa</test>'
+ b'<test testa="testval" testb="test1" testc="test2">aa</test>'
"""
def makeelement():
@@ -582,7 +582,7 @@
>>> tree = ET.parse(SIMPLE_XMLFILE)
>>> normalize_crlf(tree)
- >>> tree.write(sys.stdout)
+ >>> tree.write(sys.stdout, encoding='unicode')
<root>
<element key="value">text</element>
<element>text</element>tail
@@ -590,7 +590,7 @@
</root>
>>> tree = ET.parse(SIMPLE_NS_XMLFILE)
>>> normalize_crlf(tree)
- >>> tree.write(sys.stdout)
+ >>> tree.write(sys.stdout, encoding='unicode')
<ns0:root xmlns:ns0="namespace">
<ns0:element key="value">text</ns0:element>
<ns0:element>text</ns0:element>tail
@@ -631,17 +631,17 @@
def parseliteral():
"""
>>> element = ET.XML("<html><body>text</body></html>")
- >>> ET.ElementTree(element).write(sys.stdout)
+ >>> ET.ElementTree(element).write(sys.stdout, encoding='unicode')
<html><body>text</body></html>
>>> element = ET.fromstring("<html><body>text</body></html>")
- >>> ET.ElementTree(element).write(sys.stdout)
+ >>> ET.ElementTree(element).write(sys.stdout, encoding='unicode')
<html><body>text</body></html>
>>> sequence = ["<html><body>", "text</bo", "dy></html>"]
>>> element = ET.fromstringlist(sequence)
>>> print(ET.tostring(element))
- <html><body>text</body></html>
- >>> print("".join(ET.tostringlist(element)))
- <html><body>text</body></html>
+ b'<html><body>text</body></html>'
+ >>> print(b"".join(ET.tostringlist(element)))
+ b'<html><body>text</body></html>'
>>> ET.tostring(element, "ascii")
b"<?xml version='1.0' encoding='ascii'?>\\n<html><body>text</body></html>"
>>> _, ids = ET.XMLID("<html><body>text</body></html>")
@@ -870,10 +870,10 @@
"""
>>> elem = ET.XML("<html><body>text</body></html>")
>>> ET.tostring(elem)
- '<html><body>text</body></html>'
+ b'<html><body>text</body></html>'
>>> elem = ET.fromstring("<html><body>text</body></html>")
>>> ET.tostring(elem)
- '<html><body>text</body></html>'
+ b'<html><body>text</body></html>'
"""
def check_encoding(encoding):
@@ -1228,14 +1228,14 @@
Test ProcessingInstruction directly
>>> ET.tostring(ET.ProcessingInstruction('test', 'instruction'))
- '<?test instruction?>'
+ b'<?test instruction?>'
>>> ET.tostring(ET.PI('test', 'instruction'))
- '<?test instruction?>'
+ b'<?test instruction?>'
Issue #2746
>>> ET.tostring(ET.PI('test', '<testing&>'))
- '<?test <testing&>?>'
+ b'<?test <testing&>?>'
>>> ET.tostring(ET.PI('test', '<testing&>\xe3'), 'latin1')
b"<?xml version='1.0' encoding='latin1'?>\\n<?test <testing&>\\xe3?>"
"""
@@ -1638,11 +1638,11 @@
>>> e = ET.Element('SomeTag', text="def _f():\n return 3\n")
>>> ET.tostring(e)
- '<SomeTag text="def _f():&#10; return 3&#10;" />'
+ b'<SomeTag text="def _f():&#10; return 3&#10;" />'
>>> ET.XML(ET.tostring(e)).get("text")
'def _f():\n return 3\n'
>>> ET.tostring(ET.XML(ET.tostring(e)))
- '<SomeTag text="def _f():&#10; return 3&#10;" />'
+ b'<SomeTag text="def _f():&#10; return 3&#10;" />'
"""
@@ -1693,15 +1693,15 @@
"""
>>> ET.tostring(ET.Element("{http://namespace.invalid/does/not/exist/}title"))
- '<ns0:title xmlns:ns0="http://namespace.invalid/does/not/exist/" />'
+ b'<ns0:title xmlns:ns0="http://namespace.invalid/does/not/exist/" />'
>>> ET.register_namespace("foo", "http://namespace.invalid/does/not/exist/")
>>> ET.tostring(ET.Element("{http://namespace.invalid/does/not/exist/}title"))
- '<foo:title xmlns:foo="http://namespace.invalid/does/not/exist/" />'
+ b'<foo:title xmlns:foo="http://namespace.invalid/does/not/exist/" />'
And the Dublin Core namespace is in the default list:
>>> ET.tostring(ET.Element("{http://purl.org/dc/elements/1.1/}title"))
- '<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/" />'
+ b'<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/" />'
"""
@@ -1787,7 +1787,7 @@
'{${stuff}}localname'
>>> t = ET.ElementTree(e)
>>> ET.tostring(e)
- '<ns0:localname xmlns:ns0="${stuff}" />'
+ b'<ns0:localname xmlns:ns0="${stuff}" />'
"""
« no previous file with comments | « Doc/library/xml.etree.elementtree.rst ('k') | Lib/xml/etree/ElementTree.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b