# HG changeset patch # User Thomas Waldmann # Date 1219603897 -7200 # Node ID 8ced48dc0a3db5efbb3f80845c3e0d00aa022129 # Parent 404220520c638e4280443c8a2b98aa5c46bf951e added test.wsgi script diff -r 404220520c63 -r 8ced48dc0a3d wiki/server/test.wsgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wiki/server/test.wsgi Sun Aug 24 20:51:37 2008 +0200 @@ -0,0 +1,86 @@ +#!/usr/bin/env python +""" +A simple WSGI test application. + +Its main purpose is to show that WSGI support works (meaning that the +web server and the WSGI adaptor / support module are configured correctly). + +As a nice plus, it outputs some interesting system / WSGI values as a nice +HTML table. + +The main use of this script will be using the WSGI "application" defined +below within your production WSGI environment. You will use some code similar +to what you see at the end of this script to use the application from that +environment. For the special case of apache2/mod_wsgi, it shoud be possible +to directly use this file. + +If you start this script from the commandline either with python2.5 or with +and older python + wsgiref module installed, it will serve the content on +http://localhost:8000/ - this is mainly for debugging THIS script. + +@copyright: 2008 by MoinMoin:ThomasWaldmann +@license: GPL v2 or later, see COPYING for details. +""" +import os.path +import os +import sys + +try: + __file__ +except NameError: + __file__ = '?' + +html_template = """\ + + + WSGI Test Script working! + + + + + + + + + +%(wsgi_env)s +
1. System Information
Python%(python_version)s
Platform%(platform)s
Absolute path of this script%(abs_path)s
Filename%(filename)s
2. WSGI Environment
+ + +""" + +row_template = " %s%r" + + +def application(environ, start_response): + """ The WSGI test application """ + # emit status / headers + status = "200 OK" + headers = [('Content-Type', 'text/html'), ] + start_response(status, headers) + + # assemble and return content + content = html_template % { + 'python_version': sys.version, + 'platform': sys.platform, + 'abs_path': os.path.abspath('.'), + 'filename': __file__, + 'python path': repr(sys.path), + 'wsgi_env': '\n'.join([row_template % item for item in environ.items()]), + } + return [content] + + +if __name__ == '__main__': + # this runs when script is started directly from commandline + try: + # create a simple WSGI server and run the application + from wsgiref import simple_server + httpd = simple_server.WSGIServer(('', 8000), simple_server.WSGIRequestHandler) + httpd.set_app(application) + httpd.serve_forever() + except ImportError: + # wsgiref not installed, just output html to stdout + for content in application({}, lambda status, headers: None): + print content +