Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
982a08f8
Commit
982a08f8
authored
Sep 23, 2015
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #25047: Merge Element Tree encoding from 3.4 into 3.5
parents
5f62112d
89f76d3f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
12 deletions
+22
-12
Lib/test/test_xml_etree.py
Lib/test/test_xml_etree.py
+14
-7
Lib/xml/etree/ElementTree.py
Lib/xml/etree/ElementTree.py
+4
-5
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Lib/test/test_xml_etree.py
View file @
982a08f8
...
...
@@ -2396,14 +2396,21 @@ class IOTest(unittest.TestCase):
elem
=
ET
.
Element
(
"tag"
)
elem
.
text
=
"abc"
self
.
assertEqual
(
serialize
(
elem
),
'<tag>abc</tag>'
)
self
.
assertEqual
(
serialize
(
elem
,
encoding
=
"utf-8"
),
for
enc
in
(
"utf-8"
,
"us-ascii"
):
with
self
.
subTest
(
enc
):
self
.
assertEqual
(
serialize
(
elem
,
encoding
=
enc
),
b'<tag>abc</tag>'
)
self
.
assertEqual
(
serialize
(
elem
,
encoding
=
"us-ascii"
),
self
.
assertEqual
(
serialize
(
elem
,
encoding
=
enc
.
upper
()
),
b'<tag>abc</tag>'
)
for
enc
in
(
"iso-8859-1"
,
"utf-16"
,
"utf-32"
):
with
self
.
subTest
(
enc
):
self
.
assertEqual
(
serialize
(
elem
,
encoding
=
enc
),
(
"<?xml version='1.0' encoding='%s'?>
\
n
"
"<tag>abc</tag>"
%
enc
).
encode
(
enc
))
upper
=
enc
.
upper
()
self
.
assertEqual
(
serialize
(
elem
,
encoding
=
upper
),
(
"<?xml version='1.0' encoding='%s'?>
\
n
"
"<tag>abc</tag>"
%
upper
).
encode
(
enc
))
elem
=
ET
.
Element
(
"tag"
)
elem
.
text
=
"<&
\
"
\
'
>"
...
...
Lib/xml/etree/ElementTree.py
View file @
982a08f8
...
...
@@ -752,14 +752,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
enc
oding
not
in
(
"utf-8"
,
"us-ascii"
,
"unicode"
))):
enc
_lower
not
in
(
"utf-8"
,
"us-ascii"
,
"unicode"
))):
declared_encoding
=
encoding
if
enc
oding
==
"unicode"
:
if
enc
_lower
==
"unicode"
:
# Retrieve the default encoding for the xml declaration
import
locale
declared_encoding
=
locale
.
getpreferredencoding
()
...
...
Misc/NEWS
View file @
982a08f8
...
...
@@ -18,6 +18,10 @@ Core and Builtins
Library
-------
- Issue #25047: The XML encoding declaration written by Element Tree now
respects the letter case given by the user. This restores the ability to
write encoding names in uppercase like "UTF-8", which worked in Python 2.
- Issue #19143: platform module now reads Windows version from kernel32.dll to
avoid compatibility shims.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment