[mod_python] apache.import_module picks wrong module

Toms Baugis toms.baugis at tietoenator.com
Thu Mar 25 16:56:59 EST 2004


I am using mod_python 1.3.1

Have been using publisher handler for several days and got some problems.
Here is the situation:

In short, i have something like following directory structure

index.py
\dlu\index.py
\dlu\templates\index.py

all 3 files contain only one "def index" function

Now try following thing:
1. open index.py, then \dlu\index.py then \dlu\templates\index.py
2. now open index.py (try several times, if you have autoreload)

As result, sometimes in place of index.py you will get \dlu\index.py or 
\dlu\templates\index.py, also in place of \dlu\index.py you will 
sometimes get \dlu\templates\index.py

Found the problem in import_module function of mod_python.apache module:

.
        # of arbitrary already imported modules, such as os. The
        # reason we use startswith as opposed to exact match is that
        # modules inside packages are actually in subdirectories.

        if not file or (path and not filter(file.startswith, path)):
.

well if I do as i did in #1, then "import \dlu\index.py" will pick 
\dlu\templates\index.py - because "\dlu\templates" really startswith "\dlu\"

problem fixed by changing path checking to following:
        file_path = file[:file.rfind('/')]
        if not file or (path and (file_path <> path)):

(if something looks not good - sorry, i am new in python)

tm


More information about the Mod_python mailing list