mirror of
https://github.com/python/cpython.git
synced 2025-07-26 04:34:20 +00:00
bpo-42151: don't set specified_attributes=1 in pure Python ElementTree (GH-22987)
This commit is contained in:
parent
b9fe16a027
commit
1f433406bd
3 changed files with 22 additions and 2 deletions
|
@ -108,6 +108,19 @@ EXTERNAL_ENTITY_XML = """\
|
||||||
<document>&entity;</document>
|
<document>&entity;</document>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
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, quiet=False):
|
def checkwarnings(*filters, quiet=False):
|
||||||
def decorator(test):
|
def decorator(test):
|
||||||
def newtest(*args, **kwargs):
|
def newtest(*args, **kwargs):
|
||||||
|
@ -1354,6 +1367,12 @@ class ElementTreeTest(unittest.TestCase):
|
||||||
self.assertEqual(serialize(root, method='html'),
|
self.assertEqual(serialize(root, method='html'),
|
||||||
'<cirriculum status="public" company="example"></cirriculum>')
|
'<cirriculum status="public" company="example"></cirriculum>')
|
||||||
|
|
||||||
|
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'})
|
||||||
|
|
||||||
|
|
||||||
class XMLPullParserTest(unittest.TestCase):
|
class XMLPullParserTest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -1560,7 +1560,6 @@ class XMLParser:
|
||||||
# Configure pyexpat: buffering, new-style attribute handling.
|
# Configure pyexpat: buffering, new-style attribute handling.
|
||||||
parser.buffer_text = 1
|
parser.buffer_text = 1
|
||||||
parser.ordered_attributes = 1
|
parser.ordered_attributes = 1
|
||||||
parser.specified_attributes = 1
|
|
||||||
self._doctype = None
|
self._doctype = None
|
||||||
self.entity = {}
|
self.entity = {}
|
||||||
try:
|
try:
|
||||||
|
@ -1580,7 +1579,6 @@ class XMLParser:
|
||||||
for event_name in events_to_report:
|
for event_name in events_to_report:
|
||||||
if event_name == "start":
|
if event_name == "start":
|
||||||
parser.ordered_attributes = 1
|
parser.ordered_attributes = 1
|
||||||
parser.specified_attributes = 1
|
|
||||||
def handler(tag, attrib_in, event=event_name, append=append,
|
def handler(tag, attrib_in, event=event_name, append=append,
|
||||||
start=self._start):
|
start=self._start):
|
||||||
append((event, start(tag, attrib_in)))
|
append((event, start(tag, attrib_in)))
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Make the pure Python implementation of :mod:`xml.etree.ElementTree` behave
|
||||||
|
the same as the C implementation (:mod:`_elementree`) regarding default
|
||||||
|
attribute values (by not setting ``specified_attributes=1``).
|
Loading…
Add table
Add a link
Reference in a new issue