[mod_python] apache.import_module picks wrong module

Toms Baugis toms.baugis at tietoenator.com
Fri Mar 26 12:02:51 EST 2004


funny, didn't notice that the last part of my e-mail was missing 
(http://www.modpython.org/pipermail/mod_python/2004-March/015284.html 
contains my full email)
Here is the rest of my e-mail (i was asking for help to write it 
correctly in python):

        # 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





Toms Baugis wrote:

> 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:
>


More information about the Mod_python mailing list