view wiki/server/test.wsgi @ 6133:a6283e189869 default tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents d811122349fb
line wrap: on
line source

#!/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 should be possible
to directly use this file.

If you start this script from the commandline, it will serve the content on
http://localhost:8000/ - this is mainly for debugging THIS script.

@copyright: 2008 by MoinMoin:ThomasWaldmann
@license: Python License, see LICENSE.Python for details.
import os.path
import os
import sys

except NameError:
    __file__ = '?'

html_template = """\
 <title>WSGI Test Script</title>
 <h1>WSGI test script is working!</h1>
 <table border=1>
  <tr><th colspan=2>1. System Information</th></tr>
  <tr><td>Python Path</td><td>%(python_path)s</td></tr>
  <tr><td>Absolute path of this script</td><td>%(abs_path)s</td></tr>
  <tr><th colspan=2>2. WSGI Environment</th></tr>

row_template = "  <tr><td>%s</td><td>%r</td></tr>"

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
        # create a simple WSGI server and run the application
        from wsgiref import simple_server
        print "Running test application - point your browser at http://localhost:8000/ ..."
        httpd = simple_server.WSGIServer(('', 8000), simple_server.WSGIRequestHandler)
    except ImportError:
        # wsgiref not installed, just output html to stdout
        for content in application({}, lambda status, headers: None):
            print content