[Zope-Coders] cannot import name SecureModuleImporter
Martijn Faassen
faassen@vet.uu.nl
Tue, 12 Mar 2002 18:35:17 +0100
Hi there,
I'm being a good programmer and I'm writing some more unittests. I seem
to run into a little problem, however:
I have a Zope product called XPathIndex. It's not important right now
what it does. So, it's a package XPathIndex. It has an __init__.py,
which happens to import a module which I'm not testing at all that
in turn does the following import:
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
(and only that in my current testing).
Now, in order to placate something evil inside Zope, I already need to
do the magic incantation in my unit test imports before importing
XPathIndex:
import ZODB
otherwise it'll bail out saying something like:
ImportError: cannot import name Persistent
Fine, I knew that, it's evil, but I can live with that. Importing ZODB
isn't that much of a hassle.
Unfortunately, once I cross that hurdle, and import my XPathIndex,
it tries to import the whole PageTemplateFile thing (completely unused
in my tests, of course, but __init__.py needs it), and it says:
Traceback (most recent call last):
File "testXPathIndex.py", line 4, in ?
from Products.XPathIndex.XPathIndex import XPathIndex
File "/home/faassen/XMLZope/lib/python/Products/XPathIndex/__init__.py", line 1, in ?
import ZXPathIndex
File "/home/faassen/XMLZope/lib/python/Products/XPathIndex/ZXPathIndex.py", line 1, in ?
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
File "/home/faassen/XMLZope/lib/python/Products/PageTemplates/PageTemplateFile.py", line 29, in ?
from Expressions import SecureModuleImporter
Try as I might, I can't seem to placate this particular vile evil unless
I do an 'import Zope' in my unit tests. It seems rather wrong that I
should have to import Zope just because I want to import a product that
needs PageTemplateFile..
Am I doing something wrong? Is there something more lightweight than the
whole beast itself that I can import in my unit tests that makes this go
away? Please deliver me from the import evil..
(this all in Zope 2.5.1b1, by the way)
Regards,
Martijn