aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-11-20 12:48:14 +0200
committerMatti Picus <matti.picus@gmail.com>2020-11-20 12:48:14 +0200
commitf6f6ffbda7dd7a2af8a615e937438bb1336ae7b7 (patch)
treef6f8bfaa46525f326409e24aae0cd26d5047581e
parentdocument merged branch (diff)
downloadpypy-f6f6ffbda7dd7a2af8a615e937438bb1336ae7b7.tar.gz
pypy-f6f6ffbda7dd7a2af8a615e937438bb1336ae7b7.tar.bz2
pypy-f6f6ffbda7dd7a2af8a615e937438bb1336ae7b7.zip
test, fix xml default attribute values (issue 3333) (thanks obfusk)
-rw-r--r--lib-python/2.7/test/test_xml_etree.py20
-rw-r--r--lib-python/2.7/xml/etree/ElementTree.py2
-rw-r--r--pypy/doc/whatsnew-head.rst4
3 files changed, 24 insertions, 2 deletions
diff --git a/lib-python/2.7/test/test_xml_etree.py b/lib-python/2.7/test/test_xml_etree.py
index f6d5d17fc3..f1f1c21cd1 100644
--- a/lib-python/2.7/test/test_xml_etree.py
+++ b/lib-python/2.7/test/test_xml_etree.py
@@ -87,6 +87,19 @@ ENTITY_XML = """\
<document>&entity;</document>
"""
+# backport from https://github.com/python/cpython/pull/22987
+ATTLIST_XML = """\
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE Foo [
+<!ELEMENT foo (bar*)>
+<!ELEMENT bar (#PCDATA)*>
+<!ATTLIST bar xml:lang CDATA "eng">
+<!ENTITY qux "quux">
+]>
+<foo>
+<bar>&qux;</bar>
+</foo>
+"""
def checkwarnings(*filters):
def decorator(test):
@@ -1002,6 +1015,13 @@ class ElementTreeTest(unittest.TestCase):
method='html')
self.assertEqual(serialized, expected)
+ # backported from https://github.com/python/cpython/pull/22987
+ def test_attlist_default(self):
+ # Test default attribute values; See BPO 42151.
+ root = ET.fromstring(ATTLIST_XML)
+ self.assertEqual(root[0].attrib,
+ {'{http://www.w3.org/XML/1998/namespace}lang': 'eng'})
+
#
# xinclude tests (samples from appendix C of the xinclude specification)
diff --git a/lib-python/2.7/xml/etree/ElementTree.py b/lib-python/2.7/xml/etree/ElementTree.py
index dca69106d1..4cae355398 100644
--- a/lib-python/2.7/xml/etree/ElementTree.py
+++ b/lib-python/2.7/xml/etree/ElementTree.py
@@ -1226,7 +1226,6 @@ class _IterParseIterator(object):
if event == "start":
try:
parser.ordered_attributes = 1
- parser.specified_attributes = 1
def handler(tag, attrib_in, event=event, append=append,
start=self._parser._start_list):
append((event, start(tag, attrib_in)))
@@ -1505,7 +1504,6 @@ class XMLParser(object):
# use new-style attribute handling, if supported
try:
self._parser.ordered_attributes = 1
- self._parser.specified_attributes = 1
parser.StartElementHandler = self._start_list
except AttributeError:
pass
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
index a1861f5bee..79a53575b6 100644
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -8,3 +8,7 @@ What's new in PyPy2.7 7.3.3+
.. branch: new-ci-image
CI: Add a Dockerfile for CI to prevent hitting pull limits on docker hub
+
+.. branch: issue-3333
+
+Fix xml.etree.ElementTree assigning default attribute values: issue 3333