[Zope-Coders] expat fun & games
Martijn Faassen
faassen@vet.uu.nl
Wed, 13 Feb 2002 18:57:37 +0100
Fred L. Drake, Jr. wrote:
> Martijn Faassen writes:
> > But on Windows the dir() list (I'm not going to type it all in, try it
> > yourself), is different. For instance, StartDoctypeDeclHandler, which
> > ParsedXML uses, is missing..
> >
> > What's up with that? Now going to try to install PyXML 0.7 to see if
> > perhaps that fixes it on Windows..
>
> Installing PyXML 0.7 should be fine; it uses Expat 1.95.2, which is
> what I recommend. Python 2.1* on Windows uses Expat 1.2, which is
> old. Python 2.2* on Windows uses 1.95.2, so that's good too.
Okay, I'm happy with PyXML 0.7 so far (except that it's hard to
install for Zope's python in windows, but I can hack around that).
> The basic issue is that pyexpat is a low-level interface to the
> parser; I don't recommend it to application developers. Use SAX or
> the DOM instead. Yes, there's a slight performance penalty for the
> abstraction layer, but the APIs don't change according to the
> underlying Expat version.
But I'm maintaining ParsedXML, which does use pyexpat. I'd be happy to
accept patches which remove the dependency on it, of course. :)
> It might be interesting to add a SAX2 reader interface directly to
> pyexpat; that would certainly help avoid some of the performance
> problems associated with using a Python-level SAX driver. Alas, it
> would take time to implement and test.
>
> > This is pretty frustrating; portability of Python XML stuff to windows
> > shouldn't be this horrible!
>
> You can certainly re-build pyexpat on Windows using the 1.95.2
> release, if you have the requisite tools. It shouldn't take more than
> a few changes to the project files (can't check right now since I'm
> not in Windows-land).
I'm not in Windows-land either, which is my problem. :)
> On Unix, the Python installation will use whatever version of the
> Expat library is already available, but will not provide one. The API
> for the pyexpat module (esp. it's parser object) will depend on the
> Expat version for some of the less significant callbacks, but
> Parsed XML relies on these for completeness.
>
> Python 2.3* will include Expat 1.95.2 in the box for all platforms, so
> the API variation will go away, but that doesn't help pre-2.3
> versions. For Parsed XML, I might be able to make it use older
> versions of the pyexpat API, but I'm not sure it's worth it (and
> certainly won't be unless Jim or Guido say so).
Probably not worth it. I would like to get some help with the ParsedXML
parser crashes though. pyexpat seems to give unicode in Python 2.x land,
but if I actually modify the parser unit tests to work with unicode,
Python dumps core.
> It would be nice to have time to help fix up some of the problems that
> are plaguing Parsed XML users (Guido, Jim: hint, hint!).
That'd be very nice. :)
I've spent some time in acquisition hell the other day too. The ParsedXML
wrappers are *trying* to acquire from the persistent document, but that code
seems to always fail, and then they acquire from whatever other wrapper they're
being constructed from, resulting in long wrapper chains. The wrappers keep
a reference to the persistent document, but I think I can kick all of that
out by making wrapper *always* acquire from the document wrapper/persistent
doc only.
For some reason I have to change ComputedAttributes on the wrapper to use
the extra argument (1) though to make this work. I've never understood this
mysterious feature of ComputedAttribute - could anyone explain?
Anyway, as a result my modifications work from within Zope, but all the
unit tests for the wrapped DOM fail, due to the same ComputedAttribute
changes. What's going on there?
Regards,
Martijn