Issue Details (XML | Word | Printable)

Key: MODPYTHON-161
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

Wrong interpreter chosen with req.add_handler()/PythonInterpPerDirective.

Created: 16/Apr/06 02:32 PM   Updated: 17/Apr/07 10:38 AM
Return to search
Component/s: core
Affects Version/s: 3.3.x
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

Resolution Date: 07/May/06 05:15 PM


 Description  « Hide
Having fixed MODPYTHON-160, if using:

# .htaccess

SetHandler mod_python
PythonInterpPerDirective On
PythonFixupHandler interpreter_1

# interpreter_1.py

from mod_python import apache
import os, sys

directory = os.path.dirname(__file__)

def fixuphandler(req):
    req.log_error("fixuphandler")
    req.log_error("interpreter=%s"%req.interpreter)
    req.log_error("directory=%s"%req.hlist.directory)
    req.add_handler("PythonHandler","interpreter_1",directory)
    return apache.OK

def handler(req):
    req.log_error("handler")
    req.log_error("interpreter=%s"%req.interpreter)
    req.log_error("directory=%s"%req.hlist.directory)
    req.content_type = 'text/plain'
    req.write('hello')
    return apache.OK

when select_interp_name() in src/mod_python.c tries to determine the interpreter name, for PythonInterPerDirective, it will use the value as supplied as directory argument to req.add_handler(). In doing this though, it doesn't consider the fact that the directory may not have a trailing slash and since interpreter names for PythonInterpPerDirective always have a trailing slash, the handler will not be executed in correct interpreter context.

[Sun Apr 16 17:20:00 2006] [notice] mod_python: (Re)importing module 'interpreter_1'
[Sun Apr 16 17:20:00 2006] [error] [client ::1] fixuphandler
[Sun Apr 16 17:20:00 2006] [error] [client ::1] interpreter=/Users/grahamd/Workspaces/testing/interpreter-1/
[Sun Apr 16 17:20:00 2006] [error] [client ::1] directory=/Users/grahamd/Workspaces/testing/interpreter-1/
[Sun Apr 16 17:20:00 2006] [notice] mod_python: (Re)importing module 'interpreter_1'
[Sun Apr 16 17:20:00 2006] [error] [client ::1] handler
[Sun Apr 16 17:20:00 2006] [error] [client ::1] interpreter=/Users/grahamd/Workspaces/testing/interpreter-1
[Sun Apr 16 17:20:00 2006] [error] [client ::1] directory=/Users/grahamd/Workspaces/testing/interpreter-1

A further problem is that normally the path indicating where a directive was defined is internally calculated from Apache configuration and thus always uses POSIX directory conventions, ie., forward slash. If the above code were run on Win32, the directory calculated from __file__ is going to most likely use DOS directory conventions, ie., backward slash. Thus, even if a trailing slash were to be added, it still will not work because the remainder of the path is going to use backward slash and thus the interpreter name still will not match what it probably should be.

The main purpose of the directory argument to req.add_handler() is to know where to find the module referenced in the handler argument. In this case it is also used to determine the Python interpreter name. The fix may be that the interpreter name be determined in some other way based on the interpreter in use when the req.add_handler() call was made.

This is just part of problems I can possibly see with calculation of interpreter names for handlers. More on this another time. :-)






 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #404748 Sun May 07 10:13:50 UTC 2006 grahamd Directory argument supplied to req.add_handler() is canonicalized and a
trailing slash added automatically. This is needed to ensure that the
directory is always in POSIX path style as used by Apache and that
convention where directories associated with directives always have
trailing slash is adhered to. If this is not done, a different interpreter
can be chosen to that expected when the PythonInterpPerDirective is used.
The same sort of modification was also made for the directory argument
of the req.register_input_filter() and req.register_output_filter()
functions. (MODPYTHON-161) (MODPYTHON-103)
Files Changed
MODIFY /httpd/mod_python/trunk/test/htdocs/tests.py
MODIFY /httpd/mod_python/trunk/test/test.py
MODIFY /httpd/mod_python/trunk/src/requestobject.c
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h