changeset: 71096:e8eea84a90dc parent: 71094:77c589b27e90 parent: 71095:45e3dafb3dbe user: Victor Stinner date: Thu Jun 30 18:11:18 2011 +0200 files: Misc/NEWS description: (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. diff -r 77c589b27e90 -r e8eea84a90dc Lib/xml/etree/ElementInclude.py --- a/Lib/xml/etree/ElementInclude.py Thu Jun 30 17:39:17 2011 +0200 +++ b/Lib/xml/etree/ElementInclude.py Thu Jun 30 18:11:18 2011 +0200 @@ -67,7 +67,7 @@ # # @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 @@ # @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 -r 77c589b27e90 -r e8eea84a90dc Misc/NEWS --- a/Misc/NEWS Thu Jun 30 17:39:17 2011 +0200 +++ b/Misc/NEWS Thu Jun 30 18:11:18 2011 +0200 @@ -200,6 +200,11 @@ 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.

AltStyle によって変換されたページ (->オリジナル) /