[issue17024] cElementTree calls end() on parser taget even if start() fails
Stefan Behnel
report at bugs.python.org
Thu Jan 24 16:10:08 CET 2013
New submission from Stefan Behnel:
The following compatibility unit test fails for me in lxml since Py3.3.
etree = xml.etree.ElementTree
def test_parser_target_error_in_start(self):
assertEqual = self.assertEqual
events = []
class Target(object):
def start(self, tag, attrib):
events.append("start")
assertEqual("TAG", tag)
raise ValueError("TEST")
def end(self, tag):
events.append("end")
assertEqual("TAG", tag)
def close(self):
return "DONE"
parser = self.etree.XMLParser(target=Target())
try:
parser.feed("<TAG/>")
except ValueError:
self.assertTrue('TEST' in str(sys.exc_info()[1]))
else:
self.assertTrue(False)
# ERROR HERE - gives ["start", "end"] in Py3.3
self.assertEqual(["start"], events)
It seems like cET doesn't handle exceptions early enough and still calls the end() method. Neither Python ElementTree nor lxml do this.
Some more tests are here:
https://github.com/lxml/lxml/blob/master/src/lxml/tests/test_elementtree.py#L3446
(all tests in that file are known to work with ET)
----------
components: Library (Lib), XML
messages: 180526
nosy: eli.bendersky, scoder
priority: normal
severity: normal
status: open
title: cElementTree calls end() on parser taget even if start() fails
type: behavior
versions: Python 3.3, Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17024>
_______________________________________
More information about the Python-bugs-list
mailing list