Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.support.flup.server.scgi 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 loggingLevel = logging.DEBUG).run()

Detailed Description

.. highlight:: python
   :linenothreshold: 5

.. highlight:: bash
   :linenothreshold: 5

scgi - an SCGI/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 SCGI and mod_scgi for Apache1/Apache2, see
http://www.mems-exchange.org/software/scgi/.

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 scgi 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

Function Documentation

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

Definition at line 169 of file scgi.py.

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


Variable Documentation

Definition at line 79 of file scgi.py.

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

Definition at line 69 of file scgi.py.

Definition at line 70 of file scgi.py.

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

Definition at line 198 of file scgi.py.

Definition at line 196 of file scgi.py.