[XML-SIG] Problem with using _xmlplus

A.M. Kuchling akuchlin@mems-exchange.org
Fri, 15 Sep 2000 21:10:30 -0400

The code in Lib/xml/__init__.py seems to be insufficient to completely
delegate matters to the _xmlplus package.  Consider this session with
'python -v':

Script started on Fri Sep 15 21:02:59 2000
[amk@207-172-111-249 quotations]$ python -v
>>> from xml.sax import saxlib, saxexts
import xml # directory /usr/lib/python2.0/xml
import xml # precompiled from /usr/lib/python2.0/xml/__init__.pyc
import _xmlplus # directory /usr/lib/python2.0/site-packages/_xmlplus
import _xmlplus # from /usr/lib/python2.0/site-packages/_xmlplus/__init__.py
import xml.sax # directory /usr/lib/python2.0/site-packages/_xmlplus/sax
import xml.sax # from /usr/lib/python2.0/site-packages/_xmlplus/sax/__init__.py
import xml.sax.saxlib # from /usr/lib/python2.0/site-packages/_xmlplus/sax/saxlib.py
import xml.sax.saxexts # from /usr/lib/python2.0/site-packages/_xmlplus/sax/saxexts.py
import imp # builtin

So far, so good.  Now try creating a parser.  This fails; I've hacked
the code slightly so it doesn't swallow the responsible ImportError:

>>> p=saxexts.XMLParserFactory.make_parser("xml.sax.drivers.drv_pyexpat")
import xml # directory /usr/lib/python2.0/xml
import xml # precompiled from /usr/lib/python2.0/xml/__init__.pyc
import sax # directory /usr/lib/python2.0/xml/sax
import sax # precompiled from /usr/lib/python2.0/xml/sax/__init__.pyc
import sax.handler # precompiled from /usr/lib/python2.0/xml/sax/handler.pyc
import sax.expatreader # precompiled from /usr/lib/python2.0/xml/sax/expatreader.pyc
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.0/site-packages/_xmlplus/sax/saxexts.py", line 78, in make_parser
  File "/usr/lib/python2.0/site-packages/_xmlplus/sax/saxexts.py", line 25, in rec_find_module
  File "/usr/lib/python2.0/xml/sax/__init__.py", line 21, in ?
    from expatreader import ExpatParser
  File "/usr/lib/python2.0/xml/sax/expatreader.py", line 23, in ?
    from xml.sax import xmlreader
ImportError: cannot import name xmlreader

_xmlplus.sax.saxexts uses imp.find_module() and imp.load_module() to
load parser drives; it looks like those functions aren't looking at
sys.modules and therefore aren't being fooled by the sys.modules
hackery in Lib/xml/__init__.py, so the _xmlplus package isn't
completely overriding the xml/ package.

The guts of Python's import machinery have always been mysterious to
me; can anyone suggest how to fix this?