WebKit.HTTPContent | index /usr/local/share/webware/WebKit/HTTPContent.py

`Content producing HTTP servlet.`

Modules

``

WebUtils.Funcs |  |  |

Classes

``

WebKit.HTTPServlet.HTTPServlet(WebKit.Servlet.Servlet)
  HTTPContent
exceptions.Exception(exceptions.BaseException)
  HTTPContentError

class HTTPContent(WebKit.HTTPServlet.HTTPServlet)

``

`Content producing HTTP servlet.
HTTPContent is a type of HTTPServlet that is more convenient for
Servlets which represent content generated in response to
GET and POST requests. If you are generating HTML content, you
you probably want your servlet to inherit from Page, which contains
many HTML-related convenience methods.
If you are generating non-HTML content, it is appropriate to inherit
from this class directly.
Subclasses typically override defaultAction().
In `awake`, the page sets self attributes: `_transaction`, `_response`
and `_request` which subclasses should use as appropriate.
For the purposes of output, the `write` and `writeln`
convenience methods are provided.
If you plan to produce HTML content, you should start by looking
at Page instead of this lower-level class.
`

Method resolution order:
  HTTPContent
  WebKit.HTTPServlet.HTTPServlet
  WebKit.Servlet.Servlet
  __builtin__.object

Methods defined here:

actions(self)
  `The allowed actions.
  Returns a list or a set of method names that are allowable
  actions from HTML forms. The default implementation returns [].
  See `_respond` for more about actions.`

application(self)
  `The `Application` instance we're using.`

awake(self, transaction)
  `Let servlet awake.
  Makes instance variables from the transaction. This is
  where Page becomes unthreadsafe, as the page is tied to
  the transaction. This is also what allows us to
  implement functions like `write`, where you don't
  need to pass in the transaction or response.`

callMethodOfServlet(self, url, method, *args, **kwargs)
  `Call a method of another servlet.
  See `Application.callMethodOfServlet` for details.
  The main difference is that here you don't have
  to pass in the transaction as the first argument.`

canBeThreaded(self)
  `Declares whether servlet can be threaded.
  Returns False because of the instance variables we set up in `awake`.`

defaultAction(self)
  `Default action.
  The core method that gets called as a result of requests.
  Subclasses should override this.`

forward(self, url)
  `Forward request.
  Forwards this request to another servlet.
  See `Application.forward` for details.
  The main difference is that here you don't have
  to pass in the transaction as the first argument.`

handleAction(self, action)
  `Handle action.
  Invoked by `_respond` when a legitimate action has
  been found in a form. Invokes `preAction`, the actual
  action method and `postAction`.
  Subclasses rarely override this method.`

includeURL(self, url)
  `Include output from other servlet.
  Includes the response of another servlet
  in the current servlet's response.
  See `Application.includeURL` for details.
  The main difference is that here you don't have
  to pass in the transaction as the first argument.`

methodNameForAction(self, name)
  `Return method name for an action name.
  Invoked by _respond() to determine the method name for a given action
  name which has been derived as the value of an ``_action_`` field.
  Since this is usually the label of an HTML submit button in a form,
  it is often needed to transform it in order to get a valid method name
  (for instance, blanks could be replaced by underscores and the like).
  This default implementation of the name transformation is the identity,
  it simply returns the name. Subclasses should override this method
  when action names don't match their method names; they could "mangle"
  the action names or look the method names up in a dictionary.`

postAction(self, actionName)
  `Things to do after action.
  Invoked by self after invoking a action method.
  Subclasses may override to customize and may or may not
  invoke super as they see fit.
  The `actionName` is passed to this method,
  although it seems a generally bad idea to rely on this.
  However, it's still provided just in case you need that hook.
  By default this does nothing.`

preAction(self, actionName)
  `Things to do before action.
  Invoked by self prior to invoking a action method.
  The `actionName` is passed to this method,
  although it seems a generally bad idea to rely on this.
  However, it's still provided just in case you need that hook.
  By default this does nothing.`

request(self)
  `The request (`HTTPRequest`) we're handling.`

respondToGet(self, transaction)
  `Respond to GET.
  Invoked in response to a GET request method. All methods
  are passed to `_respond`.`

respondToPost(self, transaction)
  `Respond to POST.
  Invoked in response to a POST request method. All methods
  are passed to `_respond`.`

response(self)
  `The response (`HTTPResponse`) we're handling.`

sendRedirectAndEnd(self, url, status=None)
  `Send redirect and end.
  Sends a redirect back to the client and ends the response.
  This is a very popular pattern.`

sendRedirectPermanentAndEnd(self, url)
  `Send permanent redirect and end.`

sendRedirectSeeOtherAndEnd(self, url)
  `Send redirect to a URL to be retrieved with GET and end.
  This is the proper method for the Post/Redirect/Get pattern.`

sendRedirectTemporaryAndEnd(self, url)
  `Send temporary redirect and end.`

session(self)
  `The session object.
  This provides a state for the current user
  (associated with a browser instance, really).
  If no session exists, then a session will be created.`

sessionEncode(self, url=None)
  `Utility function to access `Session.sessionEncode`.
  Takes a url and adds the session ID as a parameter.
  This is for cases where you don't know if the client
  will accepts cookies.`

sleep(self, transaction)
  `Let servlet sleep again.
  We unset some variables. Very boring.`

transaction(self)
  `The `Transaction` we're currently handling.`

write(self, *args)
  `Write to output.
  Writes the arguments, which are turned to strings (with `str`)
  and concatenated before being written to the response.
  Unicode strings must be encoded before they can be written.`

writeExceptionReport(self, handler)
  `Write extra information to the exception report.
  The `handler` argument is the exception handler, and
  information is written there (using `writeTitle`,
  `write`, and `writeln`). This information is added
  to the exception report.
  See `WebKit.ExceptionHandler` for more information.`

writeln(self, *args)
  `Write to output with newline.
  Writes the arguments (like `write`), adding a newline after.
  Unicode strings must be encoded before they can be written.`

Static methods defined here:

endResponse()
  `End response.
  When this method is called during `awake` or `respond`,
  servlet processing will end immediately,
  and the accumulated response will be sent.
  Note that `sleep` will still be called, providing a
  chance to clean up or free any resources.`

urlDecode(s)
  `Turn special % characters into actual characters.
  This method does the same as the `urllib.unquote_plus()` function.`

urlEncode(s)
  `Quotes special characters using the % substitutions.
  This method does the same as the `urllib.quote_plus()` function.`

Methods inherited from WebKit.HTTPServlet.HTTPServlet:

__init__(self)

respond(self, trans)
  `Respond to a request.
  Invokes the appropriate respondToSomething() method depending on the
  type of request (e.g., GET, POST, PUT, ...).`

respondToHead(self, trans)
  `Respond to a HEAD request.
  A correct but inefficient implementation.`

Static methods inherited from WebKit.HTTPServlet.HTTPServlet:

lastModified(trans)
  `Get time of last modification.
  Return this object's Last-Modified time (as a float),
  or None (meaning don't know or not applicable).`

notImplemented(trans)

Methods inherited from WebKit.Servlet.Servlet:

close(self)

log(self, message)
  `Log a message.
  This can be invoked to print messages concerning the servlet.
  This is often used by self to relay important information back
  to developers.`

name(self)
  `Return the name which is simple the name of the class.
  Subclasses should *not* override this method.
  It is used for logging and debugging.`

open(self)

runMethodForTransaction(self, trans, method, *args, **kw)

serverSidePath(self, path=None)
  `Return the filesystem path of the page on the server.`

setFactory(self, factory)

Static methods inherited from WebKit.Servlet.Servlet:

canBeReused()
  `Returns whether a single servlet instance can be reused.
  The default is True, but subclasses con override to return False.
  Keep in mind that performance may seriously be degraded if instances
  can't be reused. Also, there's no known good reasons not to reuse
  an instance. Remember the awake() and sleep() methods are invoked
  for every transaction. But just in case, your servlet can refuse
  to be reused.`

runTransaction(trans)

Data descriptors inherited from WebKit.Servlet.Servlet:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

class HTTPContentError(exceptions.Exception)
`` | `HTTP content error`

Method resolution order:
  HTTPContentError
  exceptions.Exception
  exceptions.BaseException
  __builtin__.object

Data descriptors defined here:

__weakref__
  `list of weak references to the object (if defined)`

Methods inherited from exceptions.Exception:

__init__(...)
  `x.__init__(...) initializes x; see help(type(x)) for signature`

Data and other attributes inherited from exceptions.Exception:

__new__ = <built-in method __new__ of type object>
  `T.__new__(S, ...) -> a new object with type S, a subtype of T`

Methods inherited from exceptions.BaseException:

__delattr__(...)
  `x.__delattr__('name') <==> del x.name`

__getattribute__(...)
  `x.__getattribute__('name') <==> x.name`

__getitem__(...)
  `x.__getitem__(y) <==> x[y]`

__getslice__(...)
  `x.__getslice__(i, j) <==> x[i:j]
  Use of negative indices is not supported.`

__reduce__(...)

__repr__(...)
  `x.__repr__() <==> repr(x)`

__setattr__(...)
  `x.__setattr__('name', value) <==> x.name = value`

__setstate__(...)

__str__(...)
  `x.__str__() <==> str(x)`

__unicode__(...)

Data descriptors inherited from exceptions.BaseException:

__dict__

args

message