GlassAdaptor.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 » GlassAdaptor.py
"""This subclass of ``WebServerAdaptor`` is for the Glass Web server."""

__docformat__ = "restructuredtext"

# Created: Thu Feb  5 11:09:38 PST 2004
# Author: Shannon -jj Behrens
# Email: jjinux@users.sourceforge.net
#
# Copyright (c) Shannon -jj Behrens.  All rights reserved.

from aquarium.util import HTTPResponses
from WebServerAdaptor import WebServerAdaptor


class GlassAdaptor(WebServerAdaptor):

    """This subclass of WebServerAdaptor_ is for the Glass Web server.

    The following urlscheme modules can be used with this Web server adaptor:
    ScriptName_.

    The following attributes are used:

    mainGlobals
      This is a dict of ``globals()`` received from ``__main__``
      containing things such as ``stdin``, ``stdout``, ``env``, etc.

    The following private variables are used:

    _responseCode, _responseCodeMsg
      Save these until ``writeHeaders`` gets called.

    Hiding Glass Behind Apache
    ==========================

    Hiding Glass behind Apache (i.e. using Apache as a reverse proxy) is
    actually fairly simple:

    1. Get Glass working by itself.

    2. Configure Apache to act as a reverse proxy.  At the very simplest, do
       something like::

        #
        # This should be changed to whatever you set DocumentRoot to.
        #
        <Directory "/var/www/html">
            ...
        #
        # Redirect everything to Glass.  Match any uri and forward it on to
        # localhost at port 8000.
        #
            RewriteEngine On
            RewriteRule ^(.*)$ http://localhost:8000/$1 [P]
        </Directory>

    .. _WebServerAdaptor:
        aquarium.wsadaptor.WebServerAdaptor.WebServerAdaptor-class.html
    .. _ScriptName:
        aquarium.urlscheme.ScriptName.ScriptName-class.html

    """

    def __init__(self, mainGlobals):
        """Receive the ``mainGlobals`` from ``__main__``."""
        self.mainGlobals = mainGlobals
        self._responseCode = HTTPResponses.OK
        self._responseCodeMsg = "Request fulfilled, document follows"

    def setResponseCode(self, code, msg=""):
        """Save these until ``writeHeaders`` gets called."""
        self._responseCode = code
        self._responseCodeMsg = msg

    def write(self, s):
        """Output a string."""
        self.mainGlobals["stdout"].write(s)

    def writeHeaders(self, headersList):
        """Extend the base class in order to output the response code."""
        self.mainGlobals["send_response"](self._responseCode,
                                          self._responseCodeMsg)
        WebServerAdaptor.writeHeaders(self, headersList)

    def getCgiEnv(self):
        """Return CGI-like environmental variables."""
        return self.mainGlobals["env"]

    def getForm(self):
        """Instantiate some ``cgi.FieldStorage`` and return the instance."""
        from cgi import FieldStorage
        return FieldStorage(fp=self.mainGlobals["stdin"],
                            environ=self.getCgiEnv())
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.