PyExpat update

Andrew M. Kuchling akuchlin at mems-exchange.org
Mon Feb 7 15:02:14 EST 2000


Paul Prescod <paul at prescod.net> writes:
>I did some work on pyexpat over the weekend. Modulo bugs I have

Yay!  Thanks, Paul.

> 2. Errors will be returned as strings, not integers. You can check for
> 3. There will be no list of exceptions in the modules interface.  ...
> I would rather move all of these to an "errors" dictionary so they don't
> clutter up the main module namespace (after converting them to strings
> instead of integers).

What's the motivation for using strings instead of integers?  If you
take your example:

> foo = parser.Parse( data )
> if foo is pyexpat.unclosed_token:
> 	print "Oops:"+pyexpat.unclosed_token

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
was pyexpat.ERROR_UNCLOSED_TOKEN or UNCLOSED_TOKEN_ERROR.)  

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?

(BTW, did you really intend this for python-list?)

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
    "You cannot seek Destruction and return unscathed."
    "Delirium has."
    "Delirium has been scathed enough in her time."
    -- Despair and Desire, in SANDMAN #49: "Brief Lives:9"



More information about the Python-list mailing list