"""This is the base class for ``wsadaptor`` classes."""
__docformat__ = "restructuredtext"
# Created: Fri Apr 13 18:53:40 PDT 2001
# Author: Shannon -jj Behrens
# Email: jjinux@users.sourceforge.net
#
# Copyright (c) Shannon -jj Behrens. All rights reserved.
from aquarium.util import HTTPResponses
class WebServerAdaptor:
"""This is the base class for ``wsadaptor`` classes.
This class and its sub-classes act as abstraction layers for all the
different types of Web server setups. Although CGI is very flexible and
standardized, it's not very fast. Similarly, although mod_python_ is
very fast, it's not very standard. Furthermore, there will surely be
other environments one day. Hence it's our goal here to permit Aquarium
to be used in new environments without any environment-specific code
needing to be added to application-level code.
You'll notice that this class does not subclass AquariumClass_ (whose main
purpose is to receive an instance of Context_ on initialization). In fact,
this class is instantiated before the main `Aquarium class`_ is
instantiated, and the main Aquarium class will receive an instance of this
class in its constructor. That instance will be stored in
``self._ctx.wsa``. This permits the same site to be run under multiple
different environments without even a change to the ``AquariumProperties``
file.
The following methods should be overriden by subclasses:
``setResponseCode``, ``write``, ``writeHeaders``, ``getCgiEnv``,
``getForm``.
.. _mod_python: http://www.modpython.org
.. _AquariumClass: aquarium.util.AquariumClass.AquariumClass-class.html
.. _Context: aquarium.util.Context.Context-class.html
.. _Aquarium class: aquarium.util.Aquarium.Aquarium-class.html
"""
def setResponseCode(self, code=HTTPResponses.OK,
msg="Script output follows"):
"""Set the Web server response code and message.
Keword arguments:
code
The default means "OK".
msg
The default is "Script output follows".
This base class does nothing.
"""
pass
def write(self, s):
"""Output a string.
This base class simply uses ``print``.
"""
print s,
def writeHeaders(self, headersList):
"""Output a list of header strings.
The list will contains tuples like::
("Content-type", "text/html")
This base class simply uses ``self.write``.
If your environment requires a response code to be set before headers
are set, you should call ``setResponseCode`` with no arguments if it
hasn't already been called.
"""
for (name, value) in headersList:
self.write("%s: %s\r\n" % (name, value))
self.write("\r\n") # Signal end of headers.
def getCgiEnv(self):
"""Return CGI-like environmental variables."""
pass
def getForm(self):
"""Instantiate some ``cgi.FieldStorage`` and return the instance."""
pass
|