Skip to content

Commit

Permalink
bpo-34160: Preserve user specified order of Element attributes in htm…
Browse files Browse the repository at this point in the history
…l. (GH-10190)
  • Loading branch information
serhiy-storchaka committed Oct 29, 2018
1 parent c93c58b commit 3b05ad7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions Lib/test/test_xml_etree.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Lib/xml/etree/ElementTree.py
Expand Up @@ -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):
Expand Down

0 comments on commit 3b05ad7

Please sign in to comment.