[mod_python] PSP Handler - related alternatives?

Graham Dumpleton grahamd at dscpl.com.au
Sun Jan 15 22:41:24 EST 2006


Eric Strand wrote ..
> Though this works just fine, I am not really using the PSP handler for
> it's intended use.  So I wonder whether there might be better techniques
> out there.  Primarily I just want to relate a URL to a file of python 
> code used to generate a page.  Any comments are appreciated!

There are a few alternatives.

First is to use mod_python.publisher. It effectively implements two
levels of URL mapping. At the first level, the leading portion of a URL
is mapped to a file containing your Python code. Thus, if you were using
AddHandler with the .py extension to trigger mod_python.publisher, and
it was enabled from the root of the document tree, a URL of "/file.py"
would target an actual file called "file.py" in your document tree. The
"index()" method in that file would then be called.

Note though that the functions mapped to by mod_python.publisher are not
written exactly as basic mod_python handlers. The main difference you
need to know is that the result of the function is what is translated
into the page content. The mod_python documentation covers the
differences.

The second level of URL mapping that mod_python.publisher implements
takes what appears after the port of the URL that targetted the file, and
maps that against functions/objects contained in the file. Thus if you URL
was "/file.py/index" it would also target the "index()" function. This just
happens to be the same as the default when on object identifier part
exists in the URL. Another example would be "/file.py/form". In this case
it would expect a function called "form()" to be present in the file and it
would call that instead.

If there are object instances present in the file, it can also traverse their
structure and call a member function of an object instance. If for example
you had an object of type "Database" and you an instance of it created and
named as the variable "database", with the class having a member function
called "drop()", you could use a URL "/file.py/database/drop" to access it.

The mod_python.publisher module is  a part of mod_python. For anything
else you need to explore outside of the core mod_python package. Two
worth considering are mpservlets and Vampire. Both provides multiple levels
of URL mapping through file to objects inside etc. In mpservlets it is your
traditional servlet based type system. In Vampire more traditional basic
mod_python handler calling mechanism is used.

Hope this helps.

Graham


More information about the Mod_python mailing list