mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #25047: Respect case writing XML encoding declarations
This restores the ability to write encoding names in uppercase like "UTF-8", which worked in Python 2.
This commit is contained in:
parent
f94471c140
commit
89f76d3f91
3 changed files with 22 additions and 12 deletions
|
@ -756,14 +756,13 @@ class ElementTree:
|
|||
encoding = "utf-8"
|
||||
else:
|
||||
encoding = "us-ascii"
|
||||
else:
|
||||
encoding = encoding.lower()
|
||||
with _get_writer(file_or_filename, encoding) as write:
|
||||
enc_lower = encoding.lower()
|
||||
with _get_writer(file_or_filename, enc_lower) as write:
|
||||
if method == "xml" and (xml_declaration or
|
||||
(xml_declaration is None and
|
||||
encoding not in ("utf-8", "us-ascii", "unicode"))):
|
||||
enc_lower not in ("utf-8", "us-ascii", "unicode"))):
|
||||
declared_encoding = encoding
|
||||
if encoding == "unicode":
|
||||
if enc_lower == "unicode":
|
||||
# Retrieve the default encoding for the xml declaration
|
||||
import locale
|
||||
declared_encoding = locale.getpreferredencoding()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue