Skip to content

bpo-34160: Preserve user specified order of Element attributes in html. #10190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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