-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
xml.etree: Avoid XML declaration for the "ascii" encoding #72127
Comments
The ElementTree module (xml.etree) avoids the XML declaration for "utf-8" and "us-ascii" codecs, but not for the "ascii" encoding. Attached patch avoids the XML declaration for the "ascii" codec since it's a subset of UTF-8 and UTF-8 is the default encoding of XML. The patch also normalizes the encoding name to handle aliases like "utf8" (UTF-8) or "us_ascii" (ASCII). The patch adds unit tests. -- By the way, I'm surprised that the special encoding "unicode" relies on the *current* locale encoding when the XML declaration is requested. Why not alway susing UTF-8 for *unicode* instead of the locale encoding? My unit test tests different locale encodings. |
Note: I found the "us-ascii" special case when reviewing the issue bpo-27915 which proposed to replace "us-ascii" with "ascii" in the xml.etree module to use the Python fast-path for performance. |
Because it is usually outputs to sys.stdout or a file opened with default encoding. Agreed, the current locale encoding is not the best choice. It would be better to look at the encoding attribute of the file and fallback to utf-8 or ascii. |
That seems a weird choice. Since it serialises to a Unicode string, it shouldn't have any XML declaration at all, if only to make it easy for users to add one themselves if they feel like it. I guess it's too late to change that now, though... |
New patch:
|
I lost track of this change. I'm not sure why I proposed it, and I don't feel confortable to change the ElementTree code :-/ I fear a regression, so I prefer to abandon my change. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: