diff options
author | Martin Panter <vadmium+py@gmail.com> | 2015-09-23 01:14:35 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2015-09-23 01:14:35 (GMT) |
commit | 89f76d3f913e0527fbcc0d15cb3c17fbf6ca8618 (patch) | |
tree | 424af9f48cbd50e1e1dc00aaa2230a57dd816a8b /Lib/xml/etree/ElementTree.py | |
parent | f94471c1401e06df3021eafdde99c9be2c344dcb (diff) | |
download | cpython-89f76d3f913e0527fbcc0d15cb3c17fbf6ca8618.zip cpython-89f76d3f913e0527fbcc0d15cb3c17fbf6ca8618.tar.gz cpython-89f76d3f913e0527fbcc0d15cb3c17fbf6ca8618.tar.bz2 |
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.
Diffstat (limited to 'Lib/xml/etree/ElementTree.py')
-rw-r--r-- | Lib/xml/etree/ElementTree.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index a8585b6..97eba8b 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -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() |