PSP handler is a handler that processes documents using the
mod_python._psp
module. For more details on the PSP syntax, see
Section 4.9.
To use it, simply add this to your httpd configuration:
AddHandler mod_python .psp PythonHandler mod_python.psp
The PSP code will be given local variables req
, psp
,
session
and form
. A session will be created and assigned
to session
variable only if session
is referenced in the
code (the PSP handler examines co_names
of the code object to
make that determination). Remember that a mere mention of
session
will generate cookies and turn on session locking,
which may or may not be what you want. Similarly, a mod_python
FieldStorage object will be instantiated if form
is
referenced in the code.
The object passed in psp
is an instance of PSPInstance.
exception
, which is a 3-tuple returned by
sys.exc_info()
.
Example:
<\% # note that the '<' above is the first byte of the page! psp.redirect('http://www.modpython.org') \%>
If PythonDebug
server configuration is On
, then by
appending an underscore ("_") to the end of the url you can get a
nice side-by-side listing of original PSP code and resulting Python
code generated by the psp
module. This is very useful for
debugging.
By default, compiled PSP pages are cached in memory. The cache is
limited to 512 pages, which depending on the size of the pages could
potentially occupy a lot of memory. If memory is of concern, then you
can switch to dbm file caching. Our simple tests showed only 20%
slower performance using bsd db. You will need to check which
implementation anydbm defaults to on your system as some dbm
libraries impose a limit on the size of the entry making them
unsuitable. Dbm caching can be enabled via PSPDbmCache
Python
option, e.g.:
PythonOption PSPDbmCache "/tmp/pspcache.dbm"