Apache/mod_python: Registering a request handler dynamically

S

Samuel

Hi,

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')

apache.set_default_handler(myhandler)
---------------

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:

---------------
#!/usr/bin/python
import os, os.path
os.chdir(os.path.dirname(__file__))
from PleaseHideMyEnvironment import RequestHandler

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

RequestHandler(index)
---------------

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?

-Samuel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top