WebServerAdaptor.py :  » Web-Frameworks » Aquarium » aquarium-2.3 » aquarium » wsadaptor » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Aquarium 
Aquarium » aquarium 2.3 » aquarium » wsadaptor » WebServerAdaptor.py
"""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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.