Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-91810: Fix regression with writing an XML declaration with encoding='unicode'#93426
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -731,8 +731,7 @@ def write(self, file_or_filename, | ||
| with _get_writer(file_or_filename, encoding) as (write, declared_encoding): | ||
| if method == "xml" and (xml_declaration or | ||
| (xml_declaration is None and | ||
| encoding.lower() != "unicode" and | ||
| declared_encoding.lower() not in ("utf-8", "us-ascii"))): | ||
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. Why not just this?
MemberAuthor 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. Because it will write an invalid XML file when pass a file name on non-UTF-8 locale. Run When the default encoding in It can even be done earlier if open the file in UTF-8 instead of the default encoding with | ||
| write("<?xml version='1.0' encoding='%s'?>\n" % ( | ||
| declared_encoding,)) | ||
| @@ -759,13 +758,10 @@ def _get_writer(file_or_filename, encoding): | ||
| except AttributeError: | ||
| # file_or_filename is a file name | ||
| if encoding.lower() == "unicode": | ||
| encoding="utf-8" | ||
| with open(file_or_filename, "w", encoding=encoding, | ||
| errors="xmlcharrefreplace") as file: | ||
| yield file.write, encoding | ||
| else: | ||
| # file_or_filename is a file-like object | ||
| # encoding determines if it is a text or binary writer | ||