homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Aaron.Oakley
Recipients Aaron.Oakley
Date 2013年05月03日.19:56:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1367611016.77.0.197383711231.issue17901@psf.upfronthosting.co.za>
In-reply-to
Content
When the _elementtree module is in use, the TreeBuilder class will raise an IndexError in treebuilder_handle_end if __init__ was passed "None".
I discovered this while writing a subclass of TreeBuilder with a modified __init__ method that delegated to TreeBuilder:
 class MyTreeBuilder(ET.TreeBuilder):
 def __init__(self, element_factory=None):
 super().__init__(element_factory)
Used as a target, this class (and also simply "TreeBuilder(None)") will cause the IndexError when "parser.feed(data)" is called.
>>> import xml.etree.ElementTree as ET
>>> parser = ET.XMLParser(target=ET.TreeBuilder(None))
>>> parser.feed('<file><line>22</line></file>')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
IndexError: pop from empty stack
The error is raised from treebuilder_handle_end, but the cause appears to be in treebuilder_handle_start.
 if (self->element_factory) {
 node = PyObject_CallFunction(self->element_factory, "OO", tag, attrib);
 } else {
 node = create_new_element(tag, attrib);
 }
I included a patch adding a check against Py_None to the "if" test above which seems to fix the issue. I also included a simple test case for it.
History
Date User Action Args
2013年05月03日 19:56:56Aaron.Oakleysetrecipients: + Aaron.Oakley
2013年05月03日 19:56:56Aaron.Oakleysetmessageid: <1367611016.77.0.197383711231.issue17901@psf.upfronthosting.co.za>
2013年05月03日 19:56:56Aaron.Oakleylinkissue17901 messages
2013年05月03日 19:56:56Aaron.Oakleycreate

AltStyle によって変換されたページ (->オリジナル) /