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

bpo-37534: Adding ability to add Standalone Document Declaration when generating XML documents #14912

Merged
merged 18 commits into from Feb 29, 2020

Conversation

henryh9n
Copy link
Contributor

@henryh9n henryh9n commented Jul 22, 2019

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

@ZackerySpytz
Copy link
Contributor

ZackerySpytz commented Jul 23, 2019

Why are there no unit tests?

@henryh9n
Copy link
Contributor Author

henryh9n commented Aug 19, 2019

Why are there no unit tests?

Forgot to include those. :D See I'm all new in here.
Will add immediately.

@henryh9n
Copy link
Contributor Author

henryh9n commented Aug 20, 2019

@ZackerySpytz I've added the unit tests and made a few other changes. Can you please pay me a favour to review those?
Also the Azure Pipeline timed out and cancelled on the macOS PR Test without any failure and I guess there's nothing I can do.

@zware
Copy link
Member

zware commented Sep 18, 2019

@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?

@zware zware requested a review from scoder Sep 18, 2019
Copy link
Contributor

@scoder scoder left a comment

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.

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>')
Copy link
Contributor

@scoder scoder Sep 18, 2019

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.

Copy link
Contributor Author

@henryh9n henryh9n Sep 18, 2019

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.

standalone = ''

writer.write(
'<?xml version="1.0" {encoding}{standalone}?>{newline}'.format(
Copy link
Contributor

@scoder scoder Sep 18, 2019

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.

Copy link
Contributor Author

@henryh9n henryh9n Sep 18, 2019

Choose a reason for hiding this comment

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

Right. Done as well.

standalone=None):
# In case standalone declaration is set
if standalone is not None:
standalone = "standalone='{}'".format('yes' if standalone else 'no')
Copy link
Contributor

@scoder scoder Sep 18, 2019

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.

Copy link
Contributor Author

@henryh9n henryh9n Sep 18, 2019

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
Copy link
Contributor

@scoder scoder Sep 18, 2019

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.

@bedevere-bot
Copy link

bedevere-bot commented Sep 18, 2019

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@henryh9n
Copy link
Contributor Author

henryh9n commented Sep 18, 2019

I have made the requested changes; please review again

@bedevere-bot
Copy link

bedevere-bot commented Sep 18, 2019

Thanks for making the requested changes!

@scoder: please review the changes made to this pull request.

@henryh9n
Copy link
Contributor Author

henryh9n commented Sep 18, 2019

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 next thing I'm gonna do is to enhance the documentation for the module, so I'd rather leave it for now.

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>')
Copy link
Contributor

@scoder scoder Sep 21, 2019

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.

Copy link
Contributor Author

@henryh9n henryh9n Sep 22, 2019

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

@henryh9n henryh9n requested a review from scoder Oct 24, 2019
@henryh9n
Copy link
Contributor Author

henryh9n commented Nov 5, 2019

@scoder Are you reviewing this sometime soon? :)

@csabella csabella requested review from scoder and removed request for scoder Jan 25, 2020
scoder
scoder approved these changes Jan 28, 2020
@scoder
Copy link
Contributor

scoder commented Jan 28, 2020

The implementation is good now, but the documentation needs updating, since the signatures are wrong now. See xml.dom.minidon.rst.

@henryh9n
Copy link
Contributor Author

henryh9n commented Feb 23, 2020

The implementation is good now, but the documentation needs updating, since the signatures are wrong now. See xml.dom.minidon.rst.

@scoder I've updated the docs. You can have a look and merge now.

@csabella csabella requested a review from scoder Feb 25, 2020
Doc/library/xml.dom.minidom.rst Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 28, 2020

Codecov Report

Merging #14912 into master will increase coverage by 0.35%.
The diff coverage is n/a.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
Lib/test/test_binhex.py 13.33% <0.00%> (-79.78%) ⬇️
Lib/sqlite3/dbapi2.py 34.88% <0.00%> (-65.12%) ⬇️
Lib/binhex.py 17.84% <0.00%> (-58.49%) ⬇️
Lib/ctypes/test/test_structures.py 78.23% <0.00%> (-19.13%) ⬇️
Lib/test/test_audit.py 66.19% <0.00%> (-16.03%) ⬇️
Lib/pprint.py 77.42% <0.00%> (-15.81%) ⬇️
Lib/test/libregrtest/setup.py 54.32% <0.00%> (-5.14%) ⬇️
Lib/test/test_distutils.py 66.66% <0.00%> (-4.77%) ⬇️
Lib/crypt.py 82.85% <0.00%> (-4.45%) ⬇️
Lib/test/test_capi.py 89.42% <0.00%> (-4.43%) ⬇️
... and 836 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42acb7b...51a5f01. Read the comment docs.

@scoder
Copy link
Contributor

scoder commented Feb 29, 2020

Thanks!

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

6 participants