Uh oh!
There was an error while loading. Please reload this page.
gh-91810: ElementTree: Use text file's encoding by default in XML declaration - #91903
Conversation
…ML declaration
ElementTree method write() and function tostring() now use the text file's
encoding ("UTF-8" if not available) instead of locale encoding in XML
declaration when encoding="unicode" is specified.miss-islington
commented
May 11, 2022
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10, 3.11. |
bedevere-bot
commented
May 11, 2022
GH-92663 is a backport of this pull request to the 3.11 branch. |
bedevere-bot
commented
May 11, 2022
GH-92664 is a backport of this pull request to the 3.10 branch. |
bedevere-bot
commented
May 11, 2022
GH-92665 is a backport of this pull request to the 3.9 branch. |
…ML declaration (pythonGH-91903) ElementTree method write() and function tostring() now use the text file's encoding ("UTF-8" if not available) instead of locale encoding in XML declaration when encoding="unicode" is specified. (cherry picked from commit 707839b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…ML declaration (pythonGH-91903) ElementTree method write() and function tostring() now use the text file's encoding ("UTF-8" if not available) instead of locale encoding in XML declaration when encoding="unicode" is specified. (cherry picked from commit 707839b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…ML declaration (pythonGH-91903) ElementTree method write() and function tostring() now use the text file's encoding ("UTF-8" if not available) instead of locale encoding in XML declaration when encoding="unicode" is specified. (cherry picked from commit 707839b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…XML declaration (GH-91903) (GH-92663) ElementTree method write() and function tostring() now use the text file's encoding ("UTF-8" if not available) instead of locale encoding in XML declaration when encoding="unicode" is specified. (cherry picked from commit 707839b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Automerge-Triggered-By: GH:serhiy-storchaka
…XML declaration (GH-91903) (GH-92664) ElementTree method write() and function tostring() now use the text file's encoding ("UTF-8" if not available) instead of locale encoding in XML declaration when encoding="unicode" is specified. (cherry picked from commit 707839b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Automerge-Triggered-By: GH:serhiy-storchaka
…ML declaration (GH-91903) (GH-92665) ElementTree method write() and function tostring() now use the text file's encoding ("UTF-8" if not available) instead of locale encoding in XML declaration when encoding="unicode" is specified. (cherry picked from commit 707839b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Automerge-Triggered-By: GH:serhiy-storchaka
Yhg1s
commented
Jun 1, 2022
FYI, @pablogsal@ambv: this change broke existing behaviour in a subtle way. I'm not sure if it's worth rolling back in 3.9, especially considering it went into the final regular bugfix release. It may be worth fixing the regression in 3.10 or 3.11, or it may be deemed to be a documentation issue. The documentation of ElementTree.write() says: Before this change, passing a file opened in text mode regardless of the encoding used and passing After this change, passing a file opened in text mode with UTF-8 or ascii as encoding, and passing ... will produce invalid XML because of this change: ... where before this change it would not emit the second XML declaration. (This is arguably problematic code, but unfortunately the file's encoding can of course be implicit, which makes it harder to tell what's going on. This was synthesized from real code found while upgrading to 3.9.13 at Google.) |
pablogsal
commented
Jun 1, 2022
I am a bit worried that for 3.10 people have already developed workarounds for this and we are going to break them again. On the other hand, one could argue that the situation is too specific and that's why nobody has raised issues so far. I am ok rolling it back, though, if that's the consensus. |
Yhg1s
commented
Jun 1, 2022
Actually, this change didn't make it into 3.10.4, so it's only in 3.9.13 and 3.11 at this point. |
serhiy-storchaka
commented
Jun 2, 2022
#93426 fixes this. |
…t in XML declaration (pythonGH-91903) (pythonGH-92665) ElementTree method write() and function tostring() now use the text file's encoding ("UTF-8" if not available) instead of locale encoding in XML declaration when encoding="unicode" is specified. (cherry picked from commit 707839b) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Automerge-Triggered-By: GH:serhiy-storchaka
ambv
commented
Jun 16, 2022
I think we should fix it in 3.9.14 as well since it's a regression only in 3.9.13. |
ambv
commented
Jun 16, 2022
(In the mean time we did release 3.10.5 with the bug which made this version affected too) |
ElementTree method write() and function tostring() now use the text file's
encoding ("UTF-8" if not available) instead of locale encoding in XML
declaration when encoding="unicode" is specified.
Closes#91810.