Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.support.flup.server.scgi_fork 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_fork.test_app (   environ,
  start_response 
)
Probably not the most efficient example.

Definition at line 166 of file scgi_fork.py.

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


Variable Documentation

Definition at line 79 of file scgi_fork.py.

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

Definition at line 69 of file scgi_fork.py.

Definition at line 70 of file scgi_fork.py.

Definition at line 195 of file scgi_fork.py.

Definition at line 193 of file scgi_fork.py.