Issue 5355: Expat parser error constants are string descriptions (original) (raw)

Created on 2009-02-23 23:40 by suraj, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg82648 - (view) Author: Suraj Barkale (suraj) Date: 2009-02-23 23:40
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
msg82649 - (view) Author: Suraj Barkale (suraj) Date: 2009-02-23 23:43
In the snippet `ElementTree.parse('')` should be replaced by `ElementTree.fromstring('')`.
msg114613 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-21 23:56
After talking to Fred, I'll add a "codes" attribute mapping the error constant strings to their codes. Changing the constants to integers would be very bad for b/w compatibility.
msg118779 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-15 14:46
Fixed in r85526.
msg118780 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-10-15 15:15
Please, add a tiny unit test for the presence of this feature. This is the only way for vm implementers to follow CPython development.
msg118782 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-15 15:25
You're completely correct, added one in r85528. Thanks!
History
Date User Action Args
2022-04-11 14:56:46 admin set github: 49605
2010-10-15 15:25:44 georg.brandl set status: open -> closedmessages: +
2010-10-15 15:15:06 amaury.forgeotdarc set status: closed -> opennosy: + amaury.forgeotdarcmessages: + stage: test needed
2010-10-15 14:46:56 georg.brandl set status: open -> closedresolution: fixedmessages: +
2010-08-21 23:56:19 georg.brandl set versions: + Python 3.2, - Python 2.6nosy: + georg.brandlmessages: + assignee: georg.brandl
2009-02-23 23:43:03 suraj set messages: +
2009-02-23 23:40:43 suraj create