[mod_python] fixuphandler problem with mod_python-3.3.0b

m.banaouas banaouas.medialog at wanadoo.fr
Sun Dec 31 05:07:09 EST 2006


here is my directory organisation:
D:\mydir\
D:\mydir\fixuphandler.py
D:\mydir\api.py
there is no __init__.py at all.
however, I can make it change to match well practices ...

Graham Dumpleton a écrit :
> Read description of import_module() in:
>
>   
> http://www.modpython.org/live/mod_python-3.3.0b/doc-html/pyapi-apmeth.html 
>
>
> How 3.3.0b treats Python packages is a bit different.
>
> Your error and configuration suggests that what you had previously was:
>
>   ./fixuphandler/  # directory
>       __init__.py # package init file.
>       fixuphandler.py # handler file in directory
>           fixuphandler() # handler function in file
>
> A little messy, but the important thing is that it only worked before 
> because you
> had fixuphandler directory organised as a Python package with an 
> __init__.py
> file and mod_python had automatically add the parent handler directory 
> into
> sys.path. In 3.3.0b, it doesn't add the parent handler directory into 
> sys.path as
> that causes various problems. The new importer instead works out where to
> import things from in a different way. On consequence of this though 
> is that
> stuff organised as Python packages in a parent handler directory will 
> not be
> found.
>
> You have a few options.
>
> 1. Move 'fixuphandler' directory outside of document root and using 
> PythonPath
> to say where the parent directory of that directory now is.
>
> 2. If 'fixuphandler/__init__.py' is empty, then delete that file and 
> change
> configuration to:
>
>   PythonFixupHandler fixuphandler/fixuphandler
>
> 3. Remove 'fixuphandler/__init__.py' again, but use explicit reference 
> to handler
> file:
>
>   PythonFixupHandler ~/fixuphandler/fixuphandler.py
>
> If you had stuff in 'fixuphandler/__init__.py' and you expect it to be 
> executed, then
> you can only do 1 as is. You might want to reconsider restructuring 
> your files
> though anyway.
>
> BTW, if you do not have a 'fixuphandler/.htaccess' which has:
>
>   deny from all
>
> then easy for a user to access stuff in 'fixuphandler' directory that 
> they shouldn't.
> Ie. they could use URL of:
>
>   fixuphandler/fixuphandler.py/fixuphandler
>
> and mod_python.publisher will call the fixuphandler a second time. If 
> it was
> doing session stuff, that would cause a deadlock.
>
> If the only thing in 'fixuphandler' directory is 'fixuphandler.py', 
> you would perhaps
> be better off moving 'fixuphandler.py' to the parent directory and 
> call it '_handlers.py'.
> Because it now has a leading underscore, mod_python.publisher should 
> ignore
> it and not allow it to be accessed. The configuration would then be:
>
>   PythonFixupHandler _handlers
>
> or:
>
>   PythonFixupHandler ~/_handlers.py
>
> Anyway, read through the documentation I reference, noting that 
> import_module()
> is what is used to load modules for the Python*Handler directives.
>
> Graham
>




More information about the Mod_python mailing list