Skip to content
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

Manually sort XML attributes #59

Merged
merged 1 commit into from Jun 28, 2019
Merged

Conversation

vojtechtrefny
Copy link
Contributor

Since Python 3.8 attributes are no longer automatically sorted,
see https://bugs.python.org/issue34160


This was originally reported in #51 but I wasn't able to find the fix.

The test_pretty_xml test case is still failing on 3.8 even with this. Looks like running parseString and toprettyxml now moves the XML Namespace attributes. I don't know if this is intentional or if it can be considered bug in Python. I'd personally probably just move the xmlns attributes in the test to match the expected result but I'm not an XML/SVG expert.

Failed test with Python 3.8:

======================================================================
FAIL: test_pretty_print (test_pretty_xml.TestPrettyXML)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/svgwrite-1.3.0/tests/test_pretty_xml.py", line 20, in test_pretty_print
    self.assertEqual(e, r)
AssertionError: '<svg baseProfile="full" height="100%" version=[164 chars]nk">' != '<svg xmlns="http://www.w3.org/2000/svg" xmlns:[164 chars]0%">'
- <svg baseProfile="full" height="100%" version="1.1" viewBox="0,0,10000,10000" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" baseProfile="full" height="100%" version="1.1" viewBox="0,0,10000,10000" width="100%">

Since Python 3.8 attributes are no longer automatically sorted,
see https://bugs.python.org/issue34160
@mozman mozman merged commit f2807c3 into mozman:develop Jun 28, 2019
@mitar
Copy link
Contributor

mitar commented Jun 28, 2019

Shouldn't sorting be now done only if pretty-print is enabled?

@vojtechtrefny
Copy link
Contributor Author

Sorting is now (Python 3.8) disabled everywhere, including toprettyprint. My idea here was to simply keep current behaviour.

@mitar
Copy link
Contributor

mitar commented Jun 28, 2019

Yea. But current behavior is in my view a workaround around the fact that the order before Python 3.6/3.5 was not stable. So sorting makes it stable. Now, the output is stable without sorting. So sorting could be seen as pretty-printing feature.

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.

None yet

3 participants