Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.support.flup.server.ajp Namespace Reference

Classes

class  WSGIServer

Functions

def test_app

Variables

string __author__ = 'Allan Saddi <allan@saddi.com>'
string __version__ = '$Revision$'
list __all__ = ['WSGIServer']
tuple test_app = validate.validator(test_app)
tuple bindAddress = ('', 8009)
tuple loggingLevel = logging.DEBUG).run()

Detailed Description

.. highlight:: python
   :linenothreshold: 5

.. highlight:: bash
   :linenothreshold: 5

ajp - an AJP 1.3/WSGI gateway.

:copyright: Copyright (c) 2005, 2006 Allan Saddi <allan@saddi.com>
  All rights reserved.
:license:

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS **AS IS** AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

For more information about AJP and AJP connectors for your web server, see
http://jakarta.apache.org/tomcat/connectors-doc/.

For more information about the Web Server Gateway Interface, see
http://www.python.org/peps/pep-0333.html.

Example usage::

  #!/usr/bin/env python
  import sys
  from myapplication import app # Assume app is your WSGI application object
  from ajp import WSGIServer
  ret = WSGIServer(app).run()
  sys.exit(ret and 42 or 0)

See the documentation for WSGIServer for more information.

About the bit of logic at the end:
Upon receiving SIGHUP, the python script will exit with status code 42. This
can be used by a wrapper script to determine if the python script should be
re-run. When a SIGINT or SIGTERM is received, the script exits with status
code 0, possibly indicating a normal exit.

Example wrapper script::

  #!/bin/sh
  STATUS=42
  while test $STATUS -eq 42; do
python "$@" that_script_above.py
STATUS=$?
  done

Example workers.properties (for mod_jk)::

  worker.list=foo
  worker.foo.port=8009
  worker.foo.host=localhost
  worker.foo.type=ajp13

Example httpd.conf (for mod_jk)::

  JkWorkersFile /path/to/workers.properties
  JkMount /* foo

Note that if you mount your ajp application anywhere but the root ("/"), you
SHOULD specifiy scriptName to the WSGIServer constructor. This will ensure
that SCRIPT_NAME/PATH_INFO are correctly deduced.

Function Documentation

def MoinMoin.support.flup.server.ajp.test_app (   environ,
  start_response 
)
Probably not the most efficient example.

Definition at line 176 of file ajp.py.

00176 
00177     def test_app(environ, start_response):
00178         """Probably not the most efficient example."""
00179         import cgi
00180         start_response('200 OK', [('Content-Type', 'text/html')])
00181         yield '<html><head><title>Hello World!</title></head>\n' \
00182               '<body>\n' \
00183               '<p>Hello World!</p>\n' \
00184               '<table border="1">'
00185         names = environ.keys()
00186         names.sort()
00187         for name in names:
00188             yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
00189                 name, cgi.escape(`environ[name]`))
00190 
00191         form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ,
00192                                 keep_blank_values=1)
00193         if form.list:
00194             yield '<tr><th colspan="2">Form data</th></tr>'
00195 
00196         for field in form.list:
00197             yield '<tr><td>%s</td><td>%s</td></tr>\n' % (
00198                 field.name, field.value)
00199 
00200         yield '</table>\n' \
00201               '</body></html>\n'


Variable Documentation

Definition at line 94 of file ajp.py.

string MoinMoin.support.flup.server.ajp.__author__ = 'Allan Saddi <allan@saddi.com>'

Definition at line 85 of file ajp.py.

Definition at line 86 of file ajp.py.

Definition at line 206 of file ajp.py.

tuple MoinMoin.support.flup.server.ajp.loggingLevel = logging.DEBUG).run()

Definition at line 207 of file ajp.py.

Definition at line 203 of file ajp.py.