Skip to content

bpo-42151: don't set specified_attributes=1 in pure Python ElementTree #22987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@
<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 decorator(test):
def newtest(*args, **kwargs):
Expand Down Expand Up @@ -1354,6 +1367,12 @@ def test_tree_write_attribute_order(self):
self.assertEqual(serialize(root, method='html'),
'<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):

Expand Down
2 changes: 0 additions & 2 deletions Lib/xml/etree/ElementTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,6 @@ def __init__(self, *, target=None, encoding=None):
# Configure pyexpat: buffering, new-style attribute handling.
parser.buffer_text = 1
parser.ordered_attributes = 1
parser.specified_attributes = 1
self._doctype = None
self.entity = {}
try:
Expand All @@ -1580,7 +1579,6 @@ def _setevents(self, events_queue, events_to_report):
for event_name in events_to_report:
if event_name == "start":
parser.ordered_attributes = 1
parser.specified_attributes = 1
def handler(tag, attrib_in, event=event_name, append=append,
start=self._start):
append((event, start(tag, attrib_in)))
Expand Down
Original file line number Diff line number Diff line change
@@ -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``).