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

Serhiy Storchaka webhook-mailer at python.org
Mon Oct 29 13:31:10 EDT 2018


https://github.com/python/cpython/commit/3b05ad7be09af1d4510eb698b0a70d36387f296e
commit: 3b05ad7be09af1d4510eb698b0a70d36387f296e
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-10-29T19:31:04+02:00
summary:

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

files:
M Lib/test/test_xml_etree.py
M Lib/xml/etree/ElementTree.py

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



More information about the Python-checkins mailing list