mirror of https://github.com/python/cpython
Issue #17901: fix TreeBuilder construction for an explicit element_factory=None
Based on report and patch by Aaron Oakley.
This commit is contained in:
commit
20c1cdd64a
|
@ -1896,6 +1896,12 @@ class TreeBuilderTest(unittest.TestCase):
|
||||||
parser.feed(self.sample1)
|
parser.feed(self.sample1)
|
||||||
self.assertIsNone(parser.close())
|
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):
|
def test_subclass(self):
|
||||||
class MyTreeBuilder(ET.TreeBuilder):
|
class MyTreeBuilder(ET.TreeBuilder):
|
||||||
def foobar(self, x):
|
def foobar(self, x):
|
||||||
|
|
|
@ -905,6 +905,7 @@ John O'Connor
|
||||||
Kevin O'Connor
|
Kevin O'Connor
|
||||||
Tim O'Malley
|
Tim O'Malley
|
||||||
Zooko O'Whielacronx
|
Zooko O'Whielacronx
|
||||||
|
Aaron Oakley
|
||||||
James Oakley
|
James Oakley
|
||||||
Jon Oberheide
|
Jon Oberheide
|
||||||
Pascal Oberndoerfer
|
Pascal Oberndoerfer
|
||||||
|
|
|
@ -2341,7 +2341,7 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
|
||||||
self->data = NULL;
|
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);
|
node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
|
||||||
} else {
|
} else {
|
||||||
node = create_new_element(tag, attrib);
|
node = create_new_element(tag, attrib);
|
||||||
|
|
Loading…
Reference in New Issue