summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-06-30 18:11:18 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-06-30 18:11:18 +0200
commit3909da7fca2ef92b8483f39b7cf89cac4b6e4826 (patch)
tree2c4056e1b55a8b4f352d1ea1aa6407d2fae13f5f
parenta0b12a1ca7777f8b417b9753b48a443214331243 (diff)
parenteaf399e3355e6d62b1bb5810b66ad4ff431ece57 (diff)
downloadcpython-git-3909da7fca2ef92b8483f39b7cf89cac4b6e4826.tar.gz
(merge 3.2) Issue #12451: The XInclude default loader of xml.etree now decodes
files from UTF-8 instead of the locale encoding if the encoding is not specified. It now also opens XML files for the parser in binary mode instead of the text mode to avoid encoding issues.
-rw-r--r--Lib/xml/etree/ElementInclude.py9
-rw-r--r--Misc/NEWS5
2 files changed, 10 insertions, 4 deletions
diff --git a/Lib/xml/etree/ElementInclude.py b/Lib/xml/etree/ElementInclude.py
index 84fd7548b2..6cc1b44e95 100644
--- a/Lib/xml/etree/ElementInclude.py
+++ b/Lib/xml/etree/ElementInclude.py
@@ -67,7 +67,7 @@ class FatalIncludeError(SyntaxError):
#
# @param href Resource reference.
# @param parse Parse mode. Either "xml" or "text".
-# @param encoding Optional text encoding.
+# @param encoding Optional text encoding (UTF-8 by default for "text").
# @return The expanded resource. If the parse mode is "xml", this
# is an ElementTree instance. If the parse mode is "text", this
# is a Unicode string. If the loader fails, it can return None
@@ -75,13 +75,14 @@ class FatalIncludeError(SyntaxError):
# @throws IOError If the loader fails to load the resource.
def default_loader(href, parse, encoding=None):
- file = open(href)
if parse == "xml":
+ file = open(href, 'rb')
data = ElementTree.parse(file).getroot()
else:
+ if not encoding:
+ encoding = 'UTF-8'
+ file = open(href, 'r', encoding=encoding)
data = file.read()
- if encoding:
- data = data.decode(encoding)
file.close()
return data
diff --git a/Misc/NEWS b/Misc/NEWS
index 34f6b3d71a..f315c57b13 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -200,6 +200,11 @@ Core and Builtins
Library
-------
+- Issue #12451: The XInclude default loader of xml.etree now decodes files from
+ UTF-8 instead of the locale encoding if the encoding is not specified. It now
+ also opens XML files for the parser in binary mode instead of the text mode
+ to avoid encoding issues.
+
- Issue #12451: doctest.debug_script() doesn't create a temporary file
anymore to avoid encoding issues.