From 08231a9c6aeb8315803ede4ba3fecd378cfb1e3f Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Sat, 18 May 2013 15:47:16 -0700 Subject: [PATCH] Issue #17901: fix TreeBuilder construction for an explicit element_factory=None Based on report and patch by Aaron Oakley. --- Lib/test/test_xml_etree.py | 6 ++++++ Misc/ACKS | 1 + Modules/_elementtree.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index f3683f2d7e0..7e0f25a460a 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1762,6 +1762,12 @@ class TreeBuilderTest(unittest.TestCase): parser.feed(self.sample1) self.assertIsNone(parser.close()) + def test_treebuilder_elementfactory_none(self): + parser = ET.XMLParser(target=ET.TreeBuilder(element_factory=None)) + parser.feed(self.sample1) + e = parser.close() + self._check_sample1_element(e) + def test_subclass(self): class MyTreeBuilder(ET.TreeBuilder): def foobar(self, x): diff --git a/Misc/ACKS b/Misc/ACKS index b47accffaa1..4eb8ef6f6a7 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -887,6 +887,7 @@ John O'Connor Kevin O'Connor Tim O'Malley Zooko O'Whielacronx +Aaron Oakley James Oakley Jon Oberheide Pascal Oberndoerfer diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 9caef99ea6a..a568cd3b305 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -2381,7 +2381,7 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag, self->data = NULL; } - if (self->element_factory) { + if (self->element_factory && self->element_factory != Py_None) { node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib); } else { node = create_new_element(tag, attrib);