Commit 3b05ad7b authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-34160: Preserve user specified order of Element attributes in html. (GH-10190)

parent c93c58b5
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
# For this purpose, the module-level "ET" symbol is temporarily # For this purpose, the module-level "ET" symbol is temporarily
# monkey-patched when running the "test_xml_etree_c" test suite. # monkey-patched when running the "test_xml_etree_c" test suite.
import contextlib
import copy import copy
import functools import functools
import html import html
...@@ -1056,13 +1055,10 @@ class ElementTreeTest(unittest.TestCase): ...@@ -1056,13 +1055,10 @@ class ElementTreeTest(unittest.TestCase):
def test_tree_write_attribute_order(self): def test_tree_write_attribute_order(self):
# See BPO 34160 # See BPO 34160
root = ET.Element('cirriculum', status='public', company='example') root = ET.Element('cirriculum', status='public', company='example')
tree = ET.ElementTree(root) self.assertEqual(serialize(root),
f = io.BytesIO() '<cirriculum status="public" company="example" />')
with contextlib.redirect_stdout(f): self.assertEqual(serialize(root, method='html'),
tree.write(f, encoding='utf-8', xml_declaration=True) '<cirriculum status="public" company="example"></cirriculum>')
self.assertEqual(f.getvalue(),
b"<?xml version='1.0' encoding='utf-8'?>\n"
b'<cirriculum status="public" company="example" />')
class XMLPullParserTest(unittest.TestCase): class XMLPullParserTest(unittest.TestCase):
......
...@@ -979,7 +979,7 @@ def _serialize_html(write, elem, qnames, namespaces, **kwargs): ...@@ -979,7 +979,7 @@ def _serialize_html(write, elem, qnames, namespaces, **kwargs):
k, k,
_escape_attrib(v) _escape_attrib(v)
)) ))
for k, v in sorted(items): # lexical order for k, v in items:
if isinstance(k, QName): if isinstance(k, QName):
k = k.text k = k.text
if isinstance(v, QName): if isinstance(v, QName):
......
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