Skip to content

Commit 3b05ad7

Browse files
bpo-34160: Preserve user specified order of Element attributes in html. (GH-10190)
1 parent c93c58b commit 3b05ad7

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

Lib/test/test_xml_etree.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# For this purpose, the module-level "ET" symbol is temporarily
66
# monkey-patched when running the "test_xml_etree_c" test suite.
77

8-
import contextlib
98
import copy
109
import functools
1110
import html
@@ -1056,13 +1055,10 @@ def test_dump_attribute_order(self):
10561055
def test_tree_write_attribute_order(self):
10571056
# See BPO 34160
10581057
root = ET.Element('cirriculum', status='public', company='example')
1059-
tree = ET.ElementTree(root)
1060-
f = io.BytesIO()
1061-
with contextlib.redirect_stdout(f):
1062-
tree.write(f, encoding='utf-8', xml_declaration=True)
1063-
self.assertEqual(f.getvalue(),
1064-
b"<?xml version='1.0' encoding='utf-8'?>\n"
1065-
b'<cirriculum status="public" company="example" />')
1058+
self.assertEqual(serialize(root),
1059+
'<cirriculum status="public" company="example" />')
1060+
self.assertEqual(serialize(root, method='html'),
1061+
'<cirriculum status="public" company="example"></cirriculum>')
10661062

10671063

10681064
class XMLPullParserTest(unittest.TestCase):

Lib/xml/etree/ElementTree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def _serialize_html(write, elem, qnames, namespaces, **kwargs):
979979
k,
980980
_escape_attrib(v)
981981
))
982-
for k, v in sorted(items): # lexical order
982+
for k, v in items:
983983
if isinstance(k, QName):
984984
k = k.text
985985
if isinstance(v, QName):

0 commit comments

Comments
 (0)