]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #12451: The XInclude default loader of xml.etree now decodes files from
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 30 Jun 2011 16:10:14 +0000 (18:10 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 30 Jun 2011 16:10:14 +0000 (18:10 +0200)
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.

Lib/xml/etree/ElementInclude.py
Misc/NEWS

index 84fd7548b28a0c5f51193caf28bdf045cc1ea3a7..6cc1b44e958e0d9179671afd1dd12458742d1914 100644 (file)
@@ -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
 
index e6c1293fa308a2d4823bd88bac104ec3dba49045..5fa463a2707214f171d8e977cac4b8821db5401c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,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.