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.

classification
Title: Expat parser error constants are string descriptions
Type: behavior Stage: test needed
Components: XML Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: amaury.forgeotdarc, georg.brandl, suraj
Priority: normal Keywords:

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:46adminsetgithub: 49605
2010-10-15 15:25:44georg.brandlsetstatus: open -> closed

messages: + msg118782
2010-10-15 15:15:06amaury.forgeotdarcsetstatus: closed -> open

nosy: + amaury.forgeotdarc
messages: + msg118780

stage: test needed
2010-10-15 14:46:56georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg118779
2010-08-21 23:56:19georg.brandlsetversions: + Python 3.2, - Python 2.6
nosy: + georg.brandl

messages: + msg114613

assignee: georg.brandl
2009-02-23 23:43:03surajsetmessages: + msg82649
2009-02-23 23:40:43surajcreate