Skip to content

Commit 1f43340

Browse files
authored
bpo-42151: don't set specified_attributes=1 in pure Python ElementTree (GH-22987)
1 parent b9fe16a commit 1f43340

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Lib/test/test_xml_etree.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@
108108
<document>&entity;</document>
109109
"""
110110

111+
ATTLIST_XML = """\
112+
<?xml version="1.0" encoding="UTF-8"?>
113+
<!DOCTYPE Foo [
114+
<!ELEMENT foo (bar*)>
115+
<!ELEMENT bar (#PCDATA)*>
116+
<!ATTLIST bar xml:lang CDATA "eng">
117+
<!ENTITY qux "quux">
118+
]>
119+
<foo>
120+
<bar>&qux;</bar>
121+
</foo>
122+
"""
123+
111124
def checkwarnings(*filters, quiet=False):
112125
def decorator(test):
113126
def newtest(*args, **kwargs):
@@ -1354,6 +1367,12 @@ def test_tree_write_attribute_order(self):
13541367
self.assertEqual(serialize(root, method='html'),
13551368
'<cirriculum status="public" company="example"></cirriculum>')
13561369

1370+
def test_attlist_default(self):
1371+
# Test default attribute values; See BPO 42151.
1372+
root = ET.fromstring(ATTLIST_XML)
1373+
self.assertEqual(root[0].attrib,
1374+
{'{http://www.w3.org/XML/1998/namespace}lang': 'eng'})
1375+
13571376

13581377
class XMLPullParserTest(unittest.TestCase):
13591378

Lib/xml/etree/ElementTree.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,6 @@ def __init__(self, *, target=None, encoding=None):
15601560
# Configure pyexpat: buffering, new-style attribute handling.
15611561
parser.buffer_text = 1
15621562
parser.ordered_attributes = 1
1563-
parser.specified_attributes = 1
15641563
self._doctype = None
15651564
self.entity = {}
15661565
try:
@@ -1580,7 +1579,6 @@ def _setevents(self, events_queue, events_to_report):
15801579
for event_name in events_to_report:
15811580
if event_name == "start":
15821581
parser.ordered_attributes = 1
1583-
parser.specified_attributes = 1
15841582
def handler(tag, attrib_in, event=event_name, append=append,
15851583
start=self._start):
15861584
append((event, start(tag, attrib_in)))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Make the pure Python implementation of :mod:`xml.etree.ElementTree` behave
2+
the same as the C implementation (:mod:`_elementree`) regarding default
3+
attribute values (by not setting ``specified_attributes=1``).

0 commit comments

Comments
 (0)