[mod_python] Apache/mod_python: Registering a request handler dynamically

Graham Dumpleton graham.dumpleton at gmail.com
Sun Dec 28 19:26:53 EST 2008


2008/12/29 Samuel Abels <newsgroups at debain.org>:
> On Mon, 2008-12-29 at 10:26 +1100, Graham Dumpleton wrote:
>> Going back to your original request to be able to write:
>>
>>   apache.set_default_handler(myhandler)
>>
>> This can simply not work as the script file will not be loaded until a
>> request arrives which maps to that script, which is by then too late
>> to run that code.
>
> By that time it is mapped to the script, but is it also mapped to the
> specific function? In other words, perhaps there is a way to map all
> requests that are mapped to the file to one specific function? This
> would obviously have to interact with whatever handler was already
> selected.

One of the problems with mod_python is that it isn't resource based at
the lowest level. Thus you can't directly map URL to respective files
in a directory and have designated function in them called, without
having to create your own custom dispatcher. This is what
mod_python.publisher does, but it goes further and changes the API to
something different to basic mod_python handler and also allows URL to
map to different functions in file based on URL.

An example of a custom dispatcher that you may want to look at, in
respect of how it is implemented and thus take ideas from, is Vampire
custom handler for mod_python. It maps only the first part of the URL
to a specific file and then calls handler function in it, not mapping
any more of the URL to alternatives in the file like publisher does.

If you look at mod_wsgi it is more like mod_cgi and is resource based.
That is, without needing a custom dispatcher one can through multiple
WSGI script files in a directory and they will work, only requiring a
single AddHandler directive to do it. As a I said, to do this in
mod_python you need to write a custom dispatcher.

Graham


More information about the Mod_python mailing list