Repository navigation
bpo-34160: Make sorting attributes in XML serialization optional. #10452
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
Closed
+103
−50
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
93e49cb
bpo-34160: Make sorting attributes in XML serialization optional.
serhiy-storchaka 7c7bec9
Update Doc/library/xml.dom.minidom.rst
Mariatta abae8eb
Update Doc/library/xml.etree.elementtree.rst
Mariatta cf342fc
Update Doc/library/xml.etree.elementtree.rst
Mariatta 19c5ea3
Update Doc/library/xml.dom.minidom.rst
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -592,29 +592,34 @@ Functions | |||||
|
|
||||||
|
|
||||||
| .. function:: tostring(element, encoding="us-ascii", method="xml", *, \ | ||||||
| short_empty_elements=True) | ||||||
| short_empty_elements=True, sort_attrs=True) | ||||||
|
|
||||||
| Generates a string representation of an XML element, including all | ||||||
| subelements. *element* is an :class:`Element` instance. *encoding* [1]_ is | ||||||
| the output encoding (default is US-ASCII). Use ``encoding="unicode"`` to | ||||||
| generate a Unicode string (otherwise, a bytestring is generated). *method* | ||||||
| is either ``"xml"``, ``"html"`` or ``"text"`` (default is ``"xml"``). | ||||||
| *short_empty_elements* has the same meaning as in :meth:`ElementTree.write`. | ||||||
| *short_empty_elements* and *sort_attrs* have the same meaning as in | ||||||
| :meth:`ElementTree.write`. | ||||||
| Returns an (optionally) encoded string containing the XML data. | ||||||
|
|
||||||
| .. versionadded:: 3.4 | ||||||
| The *short_empty_elements* parameter. | ||||||
|
|
||||||
| .. versionadded:: 3.8 | ||||||
| The *sort_attrs* parameter. | ||||||
|
|
||||||
|
|
||||||
| .. function:: tostringlist(element, encoding="us-ascii", method="xml", *, \ | ||||||
| short_empty_elements=True) | ||||||
| short_empty_elements=True, sort_attrs=True) | ||||||
|
|
||||||
| Generates a string representation of an XML element, including all | ||||||
| subelements. *element* is an :class:`Element` instance. *encoding* [1]_ is | ||||||
| the output encoding (default is US-ASCII). Use ``encoding="unicode"`` to | ||||||
| generate a Unicode string (otherwise, a bytestring is generated). *method* | ||||||
| is either ``"xml"``, ``"html"`` or ``"text"`` (default is ``"xml"``). | ||||||
| *short_empty_elements* has the same meaning as in :meth:`ElementTree.write`. | ||||||
| *short_empty_elements* and *sort_attrs* have the same meaning as in | ||||||
| :meth:`ElementTree.write`. | ||||||
| Returns a list of (optionally) encoded strings containing the XML data. | ||||||
| It does not guarantee any specific sequence, except that | ||||||
| ``b"".join(tostringlist(element)) == tostring(element)``. | ||||||
|
|
@@ -624,6 +629,9 @@ Functions | |||||
| .. versionadded:: 3.4 | ||||||
| The *short_empty_elements* parameter. | ||||||
|
|
||||||
| .. versionadded:: 3.8 | ||||||
| The *sort_attrs* parameter. | ||||||
|
|
||||||
|
|
||||||
| .. function:: XML(text, parser=None) | ||||||
|
|
||||||
|
|
@@ -925,7 +933,7 @@ ElementTree Objects | |||||
|
|
||||||
| .. method:: write(file, encoding="us-ascii", xml_declaration=None, \ | ||||||
| default_namespace=None, method="xml", *, \ | ||||||
| short_empty_elements=True) | ||||||
| short_empty_elements=True, sort_attrs=True) | ||||||
|
|
||||||
| Writes the element tree to a file, as XML. *file* is a file name, or a | ||||||
| :term:`file object` opened for writing. *encoding* [1]_ is the output | ||||||
|
|
@@ -940,6 +948,8 @@ ElementTree Objects | |||||
| of elements that contain no content. If ``True`` (the default), they are | ||||||
| emitted as a single self-closed tag, otherwise they are emitted as a pair | ||||||
| of start/end tags. | ||||||
| If *sort_attrs* is true (by default), then element attributes will be | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| written in lexical order. | ||||||
|
|
||||||
| The output is either a string (:class:`str`) or binary (:class:`bytes`). | ||||||
| This is controlled by the *encoding* argument. If *encoding* is | ||||||
|
|
@@ -951,9 +961,8 @@ ElementTree Objects | |||||
| .. versionadded:: 3.4 | ||||||
| The *short_empty_elements* parameter. | ||||||
|
|
||||||
| .. versionchanged:: 3.8 | ||||||
| The :meth:`write` method now preserves the attribute order specified | ||||||
| by the user. | ||||||
| .. versionadded:: 3.8 | ||||||
| The *sort_attrs* parameter. | ||||||
|
|
||||||
|
|
||||||
| This is the XML file that is going to be manipulated:: | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.
No, the current wording is more correct. Element attributes will be sorted not only when sort_attrs is True, but when its boolean value is true.
"True" is a concrete bool instance, "true" is used when the boolean value should be true, and not just bool instances are accepted.