Skip to content

bpo-34160: Preserve user specified order of Element attributes#10163

Merged
rhettinger merged 2 commits intopython:masterfrom
rhettinger:xml_attribute_order
Oct 28, 2018
Merged

bpo-34160: Preserve user specified order of Element attributes#10163
rhettinger merged 2 commits intopython:masterfrom
rhettinger:xml_attribute_order

Conversation

@rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Oct 28, 2018

Minidom should also be fixed but that can be done in a separate PR.

https://bugs.python.org/issue34160

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove sorting also from other output methods (html, text). Add a What's New entry (in "Porting to 3.8").

Would you mind to remove sorting also from minidom output in this PR?

_escape_attrib(v)
))
for k, v in sorted(items): # lexical order
for k, v in items: # lexical order
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this warrants a whatsnew entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If other modules are to be changed as well (minidom, html modules, etc), it will need to be done in another PR. I don't have the spare time for those right now. Perhaps the other contributor on the tracker issue will continue to show an interest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least remove sorting in other output methods in this module. And add tests for them.

root = ET.Element('cirriculum', status='public', company='example')
tree = ET.ElementTree(root)
try:
fo = open(support.TESTFN, "wb")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to use addCleanup(support.unlink, support.TESTFN) and with for working with files, or use io.StringIO. But it is better to use the serialize() helper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what serialize() is. Switched from the traditional test support code to a context manager that does make it a little nicer.

Copy link
Member

@serhiy-storchaka serhiy-storchaka Oct 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serialize() is a helper in this file which writes an XML to string/bytes/StringIO/BytesIO. It will allow you to use a single line instead of three or four lines.

self.assertEqual(serialize(tree),
                 '<cirriculum status="public" company="example" />')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants