[Zope3-dev] Zope 3 needs pyexpat?

Martijn Faassen faassen@vet.uu.nl
Thu, 8 Aug 2002 19:03:35 +0200


Fred L. Drake, Jr. wrote:
> 
> Martijn Faassen writes:
>  > I think someone reported a bug at the Charleroi sprint involving all this --
>  > the expat situation is hopelessly confusing. I hope Python 2.3 will
>  > document somewhere (at least) the One True Way to import Expat so it'll
> 
> There's only one documented way to import Expat now -- look in the
> Library Reference, and you'll only find xml.parsers.expat.  Use that
> for normal applications.  Use that for Zope.  Use it with or without
> that PyXML.

Okay, good. And I saw you're checking in at least one change to Zope 3
to use the One True Way. I'll go and adjust Zope 2's ParsedXML to try
to use this One True Way as well, and someone also needs to fix test.py

People have just not been reading the documentation, I guess. :)

Thanks!

If I update this stuff, what's the difference between what I get from

from xml.parsers import pyexpat 

and

from xml.parsers import expat

Is it the same module or are there also differences?

> This approach to the import has only one limitation:  If the import
> fails and is tried again, the subsequent import will succeed, giving
> you an empty module, so you get an AttributeError when accessing
> specific contents of the module.  I've checked in a change for Python
> 2.2.2 (just this morning; no schedule or specific plans) so that
> multiple attempts to import xml.parsers.expat will result in an
> ImportError every time (which makes more sense)

Good, eliminate all weird magic. Heal expat of its curse. :)

> that is not needed
> for PyXML 0.8 or newer or in Python 2.3 and newer, since they each
> always provide their own pyexpat module.

>  > all work. Currently the situation involves way way too much magic;
>  > I believe PyXML even does not compile its own expat if it detects one
>  > installed already, or something along those lines, adding further to
>  > the absolute incomprehensibility of all this.
> 
> PyXML 0.8 always provides it's own pyexpat.

Good. Which I import with from "xml.parsers import expat", but it's called
pyexpat. Perhaps we should just call it 'expat' and not confuse people by
referring to 'pyexpat' lest they decide they should try to import that 
(and sometimes this works :).

>  > Yes, I've suffered with expat and python enough now to forget about being
>  > pollite -- in my opinion this is a godawful mess.
> 
> I think the problem is completely fixed in PyXML 0.8 and Python 2.2.2
> and 2.3.  Unfortunately, there's not schedule for either of the later
> two.

That'll be a tremendous help, however won't completely fix matters if
people still do things like:

import pyexpat

or 

from xml.parsers import pyexpat

which work for undefined circumstances. I shall attempt to banish such
usages from Zope at least, but the word should be spread -- there may be
more instances of this kind of thing about in other circumstances. Ah, 
I see there's a nice phrase in the documentation already:

  This module uses the pyexpat module to provide access to the Expat parser.
  Direct use of the pyexpat module is deprecated. 

>  Try upgrading to PyXML 0.8 if you're still having problems; that
> was tested under Python 2.x, including (at least) 2.0.1, 2.1.3, 2.2.1,
> and 2.3a0 (Python CVS current at the time of PyXML's release).

Thanks for the explanations! Sorry for my expressions of frustration. :)

Regards,

Martijn