"""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())
|