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
bpo-37534: Adding ability to add Standalone Document Declaration when generating XML documents #14912
Conversation
Why are there no unit tests? |
Forgot to include those. :D See I'm all new in here. |
…thon into fix-issue-37534
@ZackerySpytz I've added the unit tests and made a few other changes. Can you please pay me a favour to review those? |
@scoder, you're about the closest we have to an xml.minidom expert as far as I can tell; would you mind to review this? |
Thanks, looks mostly good. Some more tests will uncover the missing space in formatting.
Docstrings would be nice. I'm aware that they are currently missing, but writing them shouldn't be all that much work, and we have to start somewhere.
The news entry seems a bit verbose, but it's your choice if you want to change it.
Lib/test/test_minidom.py
Outdated
self.assertEqual(doc.toxml(standalone=True), | ||
'<?xml version="1.0" standalone=\'yes\'?><foo>\u20ac</foo>') | ||
self.assertEqual(doc.toxml(standalone=False), | ||
'<?xml version="1.0" standalone=\'no\'?><foo>\u20ac</foo>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both values should use the same quotes here. Since both the version and the encoding used double quotes, please also use double quotes for standalone
.
Please also add a test that declares an encoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, missed the test case with an encoding.
Added and the quote styles are made consistent either.
Lib/xml/dom/minidom.py
Outdated
standalone = '' | ||
|
||
writer.write( | ||
'<?xml version="1.0" {encoding}{standalone}?>{newline}'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to use f-strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Done as well.
Lib/xml/dom/minidom.py
Outdated
standalone=None): | ||
# In case standalone declaration is set | ||
if standalone is not None: | ||
standalone = "standalone='{}'".format('yes' if standalone else 'no') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put a space before standalone=…
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. Added.
Misc/ACKS
Outdated
@@ -1883,3 +1883,4 @@ Robert Leenders | |||
Tim Hopper | |||
Dan Lidral-Porter | |||
Ngalim Siregar | |||
Henrik Harutyunyan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intended name sorting is alphabetically by last name. Please try to adhere to that.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
I have made the requested changes; please review again |
Thanks for making the requested changes! @scoder: please review the changes made to this pull request. |
The next thing I'm gonna do is to enhance the documentation for the module, so I'd rather leave it for now. |
Lib/test/test_minidom.py
Outdated
self.assertEqual(doc.toxml(standalone=None), | ||
'<?xml version="1.0" ?><foo>\u20ac</foo>') | ||
self.assertEqual(doc.toxml(standalone=True), | ||
'<?xml version="1.0" standalone="yes"?><foo>\u20ac</foo>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be a double space before standalone
. It's unfortunate that there is a space after the version even without further parameters, but then, maybe there should just be a space after each of the parameters?
In any case: we should keep the same serialisation as before for all cases without standalone
, and make the ones with the new parameter consistent with what was there before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scoder the double space there looks very much distracting, one the other hand adding a space after each of the parameters (i.e. encoding
) causes failures in some of the past tests.
How about doing something like this:
if encoding and standalone:
standalone = ' ' + standalone
@scoder Are you reviewing this sometime soon? :) |
The implementation is good now, but the documentation needs updating, since the signatures are wrong now. See |
@scoder I've updated the docs. You can have a look and merge now. |
Codecov Report
@@ Coverage Diff @@
## master #14912 +/- ##
===========================================
+ Coverage 82.86% 83.21% +0.35%
===========================================
Files 1860 1571 -289
Lines 568810 415181 -153629
Branches 41940 44478 +2538
===========================================
- Hits 471328 345493 -125835
+ Misses 88307 60039 -28268
- Partials 9175 9649 +474
Continue to review full report at Codecov.
|
Thanks! |
When using minidom module to generate XML documents the ability to add Standalone Document Declaration is added.
In case it's set to None, which is by default, the declaration is omitted, otherwise it is set to 'yes' when a True value is passed and 'no' when False is passed.
All the changes are made to generate a document in compliance with Extensible Markup Language (XML) 1.0 (Fifth Edition) W3C Recommendation (available here: https://www.w3.org/TR/xml/#sec-prolog-dtd).
As minidom module is missing documentation for document generator, no changes are made for current functionality. Documentation may be added separately later.
Resolves: 37534
https://bugs.python.org/issue37534