[XML-SIG] Re: PyExpat update

Paul Prescod paul@prescod.net
Mon, 07 Feb 2000 15:30:10 -0600

"Andrew M. Kuchling" wrote:
> I'd really much rather write:
> if foo is pyexpat.UNCLOSED_TOKEN:
>      print 'Oops:', pyexpat.errors[ foo ]
> That makes it clear that UNCLOSED_TOKEN is a constant.  (Losing the
> 'XML_' prefix from all the errors is definitely a good idea; losing
> the 'ERROR_' prefix might be not.  The above might be clearer if it

Upper case is one issue. Naming is a second. A third is whether the
referent is an integer or a string. In your example above you make no
use of the fact that it is an integer and it could just as easily be a
string. The only thing making an integer does is force an extra list
lookup in the common case of wanting to report the string error.

if foo is pyexpat.UNCLOSED_TOKEN:
     print 'Oops:', foo

> I have no problem with cluttering the module's namespace with error
> constants, if that's the only reason for the change.  How would you
> code error checks with an 'errors' dictionary?

Well I've been thinking it should be an instance instead of a dictionary

if foo is pyexpat.errors.UNCLOSED_TOKEN:
    print 'Ooops:', foo

Note that there are NO occurrences of dependence on the English
"spelling" of these messages in the code. 

If you want to localize for spanish then you just do:

spanish_errors={pyexpat.errors.UNCLOSED_TOKEN: "Something in Spanish", 

if foo is pyexpat.errors.UNCLOSED_TOKEN:
    print 'Ooops:', spanish_errors[ foo ]

 Paul Prescod  - ISOGEN Consulting Engineer speaking for himself
"If I say something, yet it does not fill you with the immediate
burning desire to voluntarily show it to everyone you know, well then,
it's probably not all that important."
    - http://www.bespoke.org/viridian/