Apache/mod_python: Registering a request handler dynamically

Samuel newsgroups at debain.org
Sun Dec 28 20:29:35 CET 2008


Is there a way to dynamically overwrite the request handler from within 
mod_python scripts? Something along those lines:

from mod_python import apache

def myhandler(request):
    request.content_type = 'text/plain'
    request.write('Hello world')


I specifically want to avoid changing the Apache directive, as this code 
is supposed to function in a place where the user has no permission to 
override the Apache directive.

The reason is that I am trying to hide the difference between different 
environments (such as mod_python or CGI) from the developer, such that 
the following is possible:

import os, os.path
from PleaseHideMyEnvironment import RequestHandler

def index(request):
    request.write('Hello World')


So at the time at which RequestHandler() is created, I need a way to make 
sure that mod_python calls to the RequestHandler instead of the normal 
handler, whenever a new request is made.

Any idea?


More information about the Python-list mailing list