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

`The standard web page template.`

Modules

``

WebUtils.Funcs |  |  |

Classes

``

WebKit.HTTPContent.HTTPContent(WebKit.HTTPServlet.HTTPServlet)
  Page

class Page(WebKit.HTTPContent.HTTPContent)

``

`The standard web page template.
Page is a type of HTTPContent that is more convenient for servlets
which represent HTML pages generated in response to GET and POST requests.
In fact, this is the most common type of Servlet.
Subclasses typically override `writeHeader`, `writeBody` and `writeFooter`.
They might also choose to override `writeHTML` entirely.
When developing a full-blown website, it's common to create a subclass of
`Page` called `SitePage` which defines the common look and feel of the
website and provides site-specific convenience methods. Then all other
pages in your application then inherit from `SitePage`.
`

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

Methods defined here:

defaultAction(self)
  `The default action in a Page is to writeHTML().`

htBodyArgs(self)
  `The atrributes for the <body> element.
  Returns the arguments used for the HTML <body> tag.
  Invoked by writeBody().
  With the prevalence of stylesheets (CSS), you can probably skip
  this particular HTML feature, but for historical reasons this sets
  the page to black text on white.`

htTitle(self)
  `The page title as HTML.
  Return title(). Subclasses sometimes override this to provide
  an HTML enhanced version of the title. This is the method that should
  be used when including the page title in the actual page contents.`

postAction(self, actionName)
  `Things to do after actions.
  Simply close the html tag (</html>).`

preAction(self, actionName)
  `Things to do before actions.
  For a page, we first writeDocType(), <html>, and then writeHead().`

title(self)
  `The page title.
  Subclasses often override this method to provide a custom title.
  This title should be absent of HTML tags. This implementation
  returns the name of the class, which is sometimes appropriate
  and at least informative.`

validateHTML(self, closingTags='</body></html>')
  `Validate the response.
  Validate the current response data using Web Design Group's
  HTML validator available at
  http://www.htmlhelp.com/tools/validator/
  Make sure you install the offline validator (called
  ``validate``) which can be called from the command-line.
  The ``validate`` script must be in your path.
  Add this method to your SitePage (the servlet from
  which all your servlets inherit), override
  Page.writeBodyParts() in your SitePage like so::
  def writeBodyParts(self):
  Page.writeBodyParts()
  validateHTML()
  The ``closingtags`` param is a string which is appended
  to the page before validation. Typically, it would be
  the string ``</body></html>``. At the point this method
  is called (e.g. from `writeBodyParts`) the page is not
  yet 100% complete, so we have to fake it.`

writeBody(self)
  `Write the <body> element of the page.
  Writes the ``<body>`` portion of the page by writing the
  ``<body>...</body>`` (making use of `htBodyArgs`) and
  invoking `writeBodyParts` in between.`

writeBodyParts(self)
  `Write the parts included in the <body> element.
  Invokes `writeContent`. Subclasses should only override this method
  to provide additional page parts such as a header, sidebar and footer,
  that a subclass doesn't normally have to worry about writing.
  For writing page-specific content, subclasses should override
  `writeContent`() instead. This method is intended to be overridden
  by your SitePage.
  See `SidebarPage` for an example override of this method.
  Invoked by `writeBody`.`

writeContent(self)
  `Write the unique, central content for the page.
  Subclasses should override this method (not invoking super) to write
  their unique page content.
  Invoked by `writeBodyParts`.`

writeDocType(self)
  `Write the DOCTYPE tag.
  Invoked by `writeHTML` to write the ``<!DOCTYPE ...>`` tag.
  By default this gives the HTML 4.01 Transitional DOCTYPE,
  which is a good guess for what most people send. Be
  warned, though, that some browsers render HTML differently
  based on the DOCTYPE (particular newer browsers, like
  Mozilla, do this).
  Subclasses may override to specify something else.
  You can find out more about doc types by searching for
  DOCTYPE on the web, or visiting:
  http://www.htmlhelp.com/tools/validator/doctype.html`

writeHTML(self)
  `Write all the HTML for the page.
  Subclasses may override this method (which is invoked by `_respond`)
  or more commonly its constituent methods, `writeDocType`, `writeHead`
  and `writeBody`.
  You will want to override this method if:
  * you want to format the entire HTML page yourself
  * if you want to send an HTML page that has already been generated
  * if you want to use a template that generates the entire page
  * if you want to send non-HTML content; in this case, be sure to call
  response().setHeader('Content-Type', 'mime/type').`

writeHead(self)
  `Write the <head> element of the page.
  Writes the ``<head>`` portion of the page by writing the
  ``<head>...</head>`` tags and invoking `writeHeadParts` in between.`

writeHeadParts(self)
  `Write the parts included in the <head> element.
  Writes the parts inside the ``<head>...</head>`` tags.
  Invokes `writeTitle` and then `writeMetaData`, `writeStyleSheet`
  and `writeJavaScript`. Subclasses should override the `title`
  method and the three latter methods only.`

writeJavaScript(self)
  `Write the JavaScript for the page.
  This default implementation does nothing.
  Subclasses should override if necessary.
  A typical implementation is:
  writeln(' <script type="text/javascript" src="ajax.js"></script>')`

writeMetaData(self)
  `Write the meta data for the page.
  This default implementation does nothing.
  Subclasses should override if necessary.
  A typical implementation is:
  writeln(' <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">')`

writeStyleSheet(self)
  `Write the CSS for the page.
  This default implementation does nothing.
  Subclasses should override if necessary.
  A typical implementation is:
  writeln(' <link rel="stylesheet" href="StyleSheet.css" type="text/css">')`

writeTitle(self)
  `Write the <title> element of the page.
  Writes the ``<title>`` portion of the page.
  Uses `title`, which is where you should override.`

Static methods defined here:

htmlDecode(s)
  `HTML decode special characters.
  Alias for `WebUtils.Funcs.htmlDecode`. Decodes HTML entities.`

htmlEncode(s)
  `HTML encode special characters.
  Alias for `WebUtils.Funcs.htmlEncode`, quotes the special characters
  &, <, >, and "`

Methods inherited from WebKit.HTTPContent.HTTPContent:

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`.`

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.`

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 inherited from WebKit.HTTPContent.HTTPContent:

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)`