[issue5355] Expat parser error constants are string descriptions
Suraj Barkale
report at bugs.python.org
Tue Feb 24 00:40:45 CET 2009
New submission from Suraj Barkale <suraj+python at barkale.com>:
All the error constants in `xml.parsers.expat.errors` are strings.
However, when expat raises an ExpatError exception, ExpatError.code
attribute is a number. There seems to be no way of associating
ExpatError with a corresponding error code from `xml.parsers.expat.errors.
Following code snippet should print "Ignore empty file" but in Python
2.6 it raises ExpatError.
from xml.etree import ElementTree
from xml.parsers import expat
try:
ElementTree.parse('')
except expat.ExpatError as e:
if e.code == expat.errors.XML_ERROR_NO_ELEMENTS:
print "Ignore empty file"
else:
raise
----------
components: XML
messages: 82648
nosy: suraj
severity: normal
status: open
title: Expat parser error constants are string descriptions
type: behavior
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5355>
_______________________________________
More information about the Python-bugs-list
mailing list