[mod_python] The new module loader

Dan Eloff dan.eloff at gmail.com
Fri Apr 21 21:03:54 EDT 2006

My exact setup is as follows:

PythonInterpreter pyserver
PythonOptimize Off
PythonDebug On
PythonAutoReload On
PythonOption mod_python.future.importer pyserver
# don't invoke our python handler if the file has an extension, it
doesn't handle any addresses like that
<Directory />
	SetHandler mod_python
	PythonHandler C:\Docume~1\Dan\MyDocu~1\PYROOT\pyserver\pyserver.py

<LocationMatch "^[^?]*?\.">
	SetHandler None

The document root is: My Documents/HTDOCS
And you can see that pyserver.py (and config.py) is located in:
My Documents/PYROOT/pyserver

By handler directory this is the one I'm referring too.

The _config.py that is unable to import the config.py is in:
My Documents/PYROOT/web

It is not an issue with your importer that it can't be found, but I
would like to know how to make it found with out editing every file
like _config.py, because the pyserver files are used often.

Thank you very much for taking the time to reply while obviously busy.

On 4/21/06, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
> On 22/04/2006, at 6:35 AM, Dan Eloff wrote:
> > Hey Graham,
> >
> > I'm running into one problem related to taking things out of the
> > packages. I've imported PyServer.module_name in many places in my
> > modules but of course now PyServer no longer exists and all it's
> > modules are in the directory with pyserver.py which contains the
> > handler. I changed import PyServer.config to just import config, but
> > it doesn't find it.
> >
> > I'm loathe to use absolute or even relative paths because of how many
> > different places I'd have to modify it. Is there some way to globally
> > add the handler's directory to the search path?
> I gotta run out the door, so no time to answer all questions right now.
> Can you clarify when you say "handler directory" whether you mean
> the directory that pserver.py is in, or the directory indicated by the
> Directory directive where you specified PythonHandler?
> Also, are you setting PythonPath directive?
> Oh, and give locations of pyserver.py and config.py, along with any path
> used with Directory directive so I have context.
> In a rush, so take note of comments in:
>    http://issues.apache.org/jira/browse/MODPYTHON-154
>    http://www.dscpl.com.au/articles/modpython-007.html#setting-of-
> pythonpath
> in the mean time.
> You may be coming up against preserved behaviour from old
> importer that frankly I think should not be kept.
> Thanks.
> Graham
> > On 4/21/06, Dan Eloff <dan.eloff at gmail.com> wrote:
> >> Whoops. I was looking over the code for import_module and I
> >> figured it
> >> out. path is meant to be a list, duh. Maybe add an
> >>
> >> assert not path or isinstance(path, list), 'path must be a list of
> >> paths to search for the module.'
> >>
> >> to your code near the top of the function. Otherwise if path is a
> >> string, search_path.extend(path) doesn't throw, but it makes a huge
> >> search_path of single character locations and fails utterly (and
> >> silently)
> >>
> >> -Dan
> >>

More information about the Mod_python mailing list