Software: Apache/2.0.54 (Fedora). PHP/5.0.4 uname -a: Linux mina-info.me 2.6.17-1.2142_FC4smp #1 SMP Tue Jul 11 22:57:02 EDT 2006 i686 uid=48(apache) gid=48(apache) groups=48(apache) Safe-mode: OFF (not secure) /var/www/manual/mod/mod_python/ drwxr-xr-x |
Viewing file: Select action/file-type:
|
req, [, filename, string, vars]) |
req is a request object; filename and string are
optional keyword arguments which indicate the source of the PSP
code. Only one of these can be specified. If neither is specified,
req.filename
is used as filename.
vars is a dictionary of global variables. Vars passed in the run() method will override vars passed in here.
This class is used internally by the PSP handler, but can also be used as a general purpose templating tool.
When a file is used as the source, the code object resulting from the specified file is stored in a memory cache keyed on file name and file modification time. The cache is global to the Python interpreter. Therefore, unless the file modification time changes, the file is parsed and resulting code is compiled only once per interpreter.
The cache is limited to 512 pages, which depending on the size of
the pages could potentially occupy a significant amount 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''
Unlike with files, the code objects resulting from a string are cached in memory only. There is no option to cache in a dbm file at this time.
[vars]) |
Additionally, the PSP code will be given global 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.
) |
Here is an example of how PSP can be used as a templating mechanism:
The template file:
<html> <!-- This is a simple psp template called template.html --> <h1>Hello, <%=what%>!</h1> </html>
from mod_python import apache, psp def handler(req): template = psp.PSP(req, filename='template.html') template.run({'what':'world'}) return apache.OK
) |
psp
to
the PSP code. Objects of this class are instantiated internally and
the interface to __init__ is purposely undocumented.
filename) |
exception
, which is a 3-tuple returned by
sys.exc_info()
.
object[, **kw]) |
location[, permanent=0]) |
Example:
<% # note that the '<' above is the first byte of the page! psp.redirect('http://www.modpython.org') %>
Additionally, the psp module provides the following low level functions:
filename[, dir]) |
This function will open file named filename, read and parse its content and return a string of resulting Python code.
If dir is specified, then the ultimate filename to be parsed
is constructed by concatenating dir and filename, and
the argument to include
directive can be specified as a
relative path. (Note that this is a simple concatenation, no path
separator will be inserted if dir does not end with one).
string) |
This function will parse contents of string and return a string of resulting Python code.
:: Command execute :: | |
--[ c99shell v. 1.0 pre-release build #16 powered by Captain Crunch Security Team | http://ccteam.ru | Generation time: 0.0032 ]-- |