Here is a patch to ptl_import.py (Quixote 0.6) that allows correctly
importing of packages with an __init__.ptl package initialization file.
The patch has been tested running Quixote 0.6 on Apache 2.0.45 as
classical CGI script and with mod_python 3.0.3.
Python version is 2.2.1 (ActiveState).
Regards,
Franz.
--- Quixote-0.6\ptl_import.py Wed Mar 05 19:40:42 2003
+++ Quixote-0.6.patched\ptl_import.py Sun May 18 22:21:44 2003
@@ -96,17 +96,37 @@
def load_module (self, name, stuff):
file, filename, info = stuff
(suff, mode, type) = info
+ path = None
+ # Directory handling: this is mostly from
ihooks.FancyModuleLoader
+ if type == imp.PKG_DIRECTORY:
+ initstuff = self.find_module_in_dir("__init__", filename, 0)
+ if not initstuff:
+ raise ImportError, "No __init__ module in package %s" %
name
+ initfile, initfilename, initinfo = initstuff
+ initsuff, initmode, inittype = initinfo
+ if inittype in (PTLC_FILE, PTL_FILE):
+ path = [filename]
+ file = initfile
+ filename = initfilename
+ type = inittype
+
# If it's a PTL file, load it specially.
if type == PTLC_FILE:
- return _load_ptlc(name, filename, file)
+ m = _load_ptlc(name, filename, file)
elif type == PTL_FILE:
- return _load_ptl(name, filename, file)
+ m = _load_ptl(name, filename, file)
else:
# Otherwise, use the default handler for loading
return ihooks.ModuleLoader.load_module( self, name, stuff)
+
+ # If a package is imported then the __path__ attribute *must* be
set.
+ # At least some parts of the ihooks module rely on that.
+ if path:
+ m.__path__ = path
+ return m
try:
import cimport