Home | Trees | Index | Help |
|
---|
Module servlet :: Class Servlet |
|
HTMLPage
Abstract base class for all mod_python servlets.
You must subclass this class implementing, minimally,respond
, but you will probably want to
subclass HTMLPage
, which already subclasses Servlet
and has many added features for generating HTML output.
Method Summary | |
---|---|
Base constructor for all servlets. | |
Return a simple string representing an instance: | |
Wrapper around mod_python.Cookie.add_cookie(). | |
Basic HTTP authentication method. | |
Get the count of requests for this servlet. (Class method) | |
Send a redirect to the client via a Location HTTP header. | |
Utilily method which immediately flushes all buffered output to the client. | |
Wrapper around mod_python.Cookie.get_cookies(). | |
Redirect internally. | |
Utility method to write a message to the apache error log. | |
This is the second user method called by the handler ,
after auth , prior to respond . | |
Like write , but all output is immediately
flushed to the client and no string coercion is attempted on the
arguments. | |
This is the third user method called by the handler ,
after prep , before wrapup and is where the response is
generated. | |
Get the filename of the source file for this servlet. (Class method) | |
This is the fourth user method called by the handler ,
immediately after calling respond , before _finally . | |
Utility method to write the arguments to the client. | |
Like write , but in addition appends a newline to
the output. |
Instance Variable Summary | |
---|---|
str | auth_realm : Specifies the realm for basic HTTP authentication. |
str or None | content_type : Specifies the content type of the servlet, i.e.,
"text/html". |
instance of mod_python.util.FieldStorage | form : User data sent with request via form or url. |
list |
form_vars : This is the same as query_vars except these variables are only
processed for POST requests. |
float | instantiated : Timestamp of when the servlet was instantiated. |
list of unbound methods | ok_methods_to_call : list of methods that can be called directly via a POST. |
list of str | path_info : req.path_info canonicalized as a list: stripping beginning and
trailing "/" and splitting it on internal "/". |
list |
query_vars : List of arguments to be searched for in form
to be set as instance variables of the servlet. |
req : The apache request object. | |
bool | reusable : Flag (default: True) indicating whether or not an instance of this
servlet can be used for multiple requests. |
instance of mod_python.Session.Session or None | session : A Session (see the mod_python documentation for
mod_python.Session.Session). |
int | session_timeout : Length of time, in seconds, until session times out. |
bool |
use_session : If true, create (or reload) session for each request. |
Instance Method Details |
---|
__init__(self)
|
__str__(self)
|
add_cookie(self, cookie, value='', **kw)Wrapper around mod_python.Cookie.add_cookie(). See mod_python documentation for details. |
auth(self)Basic HTTP authentication method. This method is the first user method called by thehandler for each request, just before prep . It should return without exception
if authorization is granted (the return value is ignored) or raise
apache.SERVER_RETURN with
apache.HTTP_UNAUTHORIZED as a value if authorization is
denied. Typical implementation should use the _get_user_pw and _unauthorized helper methods:
def auth(self): user, pw = self._get_user_pw() # test user, pw for authorization; if OK, return self._unauthorized() See the source code for |
external_redirect(self, uri, permanently=True)Send a redirect to the client via a Location HTTP header.
|
flush(self)Utilily method which immediately flushes all buffered output to the client. Ifcontent_type has not already been written
it will be.
|
get_cookies(self, klass=<class 'mod_python.Cookie.Cookie'>, **kw)Wrapper around mod_python.Cookie.get_cookies(). See mod_python documentaion for details. |
internal_redirect(self, uri)Redirect internally. This does not send a redirect to the client (seeexternal_redirect ), but redirects
internally to the server. This is a wrapper around
req.internal_redirect(); see mod_python documentation for details.
|
log(self, msg)Utility method to write a message to the apache error log.
|
prep(self)This is the second user method called by the It should be used as a means to prep the servlet for The return value is ignored by the handler. If this method is implemented in a subclass, the superclass method must be called; e.g:class MyServlet(HTMLPage): ... def prep(self): HTMLPage.prep(self) ... ... |
raw_write(self, *args)Likewrite , but all output is immediately
flushed to the client and no string coercion is attempted on the
arguments.
|
respond(self)This is the third user method called by thehandler , after prep , before wrapup and is where the response is
generated. Typically, this will be by calls to write , writeln and/or raw_write . For example:
def respond(self): self.writeln("Hello, world!") For most developers, this method will not need to be written because
the version implemented in The base class implementation (which is called by
|
wrapup(self)This is the fourth user method called by the This method should be used to "tidy up" after a request, e.g., flush output data, create a log entry, etc. The base method flushes output to the client. If overridden, this
method should be called by the subclass if it does not call |
write(self, *args)Utility method to write the arguments to the client. Each arg is coerced to a string and buffered for output. The output is sent to the client whenflush is called explicitly or implicitly,
when the handler is finished with the request.
|
writeln(self, *args)Likewrite , but in addition appends a newline
to the output.
|
Class Method Details |
---|
count(klass)Get the count of requests for this servlet.
|
sourcefilename(klass)Get the filename of the source file for this servlet.
|
Instance Variable Details |
---|
auth_realmSpecifies the realm for basic HTTP authentication. Default: "Unspecified".
|
content_typeSpecifies the content type of the servlet, i.e., "text/html". If it is not set (None) then it defaults to "text/plain". Default: None
|
form_varsThis is the same asquery_vars except these variables are only
processed for POST requests. For all GET requests, these variables
will be set to their default values.
|
instantiatedTimestamp of when the servlet was instantiated. This is stored as seconds since the epoch; see the python documentation for time.time().
|
path_inforeq.path_info canonicalized as a list: stripping beginning and trailing "/" and splitting it on internal "/".
|
query_varsList of arguments to be searched for in (NAME, DEFAULT [,CONVERSION]) where NAME, a string, is the name of the variable and must be a legal
python identifier; DEFAULT, must be a string, list or dict, is the
default value for NAME if it does not appear in (NAME, '') That is, the default value for NAME, if not found in If DEFAULT is a string, the value will be retrieved from All string values retrieved from ["name", ("login", "", bool), ("items", []), ("map", {"foo" : "bar", "baz" : []})] query_vars should be contrasted to
|
reqThe apache request object. |
reusableFlag (default: True) indicating whether or not an instance of this servlet can be used for multiple requests. If False, instances will be recreated for every request of a servlet.
|
sessionA Session (see the mod_python documentation for mod_python.Session.Session). A session object is created for each request ifuse_session is True. If use_session is False, this variable will be
set to None.
|
session_timeoutLength of time, in seconds, until session times out. Default: 30 minutes.
|
use_sessionIf true, create (or reload)session for each request. Default:
False.
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.0 on Tue Mar 15 08:20:22 2005 | http://epydoc.sf.net |