# HG changeset patch # User paulb # Date 1190933407 0 # Node ID e9540f622fb68b1bdedf82b8ed7f5790d947ee7d # Parent 1d26a9057390d4b1e6583b15b532f80b1f63d065 [project @ 2007-09-27 22:50:07 by paulb] Added wsgiref support; renamed the existing WSGI over CGI deploy function to deploy_as_cgi. diff -r 1d26a9057390 -r e9540f622fb6 WebStack/Adapters/WSGI.py --- a/WebStack/Adapters/WSGI.py Thu Sep 27 22:49:16 2007 +0000 +++ b/WebStack/Adapters/WSGI.py Thu Sep 27 22:50:07 2007 +0000 @@ -3,7 +3,7 @@ """ WSGI adapter. -Copyright (C) 2004, 2005, 2006 Paul Boddie +Copyright (C) 2004, 2005, 2006, 2007 Paul Boddie This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -89,7 +89,7 @@ ) return [trans.get_wsgi_content()] -def deploy(resource, authenticator=None, address=None, handle_errors=1, error_resource=None): +def deploy_as_cgi(resource, authenticator=None, address=None, handle_errors=1, error_resource=None): """ Deploy the given 'resource', with the given optional 'authenticator', at the @@ -106,4 +106,28 @@ handler = WSGIAdapter(resource, authenticator, handle_errors, error_resource) run_with_cgi(handler) +try: + import wsgiref.simple_server +except ImportError: + pass +else: + default_address = ("", 8080) + + def deploy(resource, authenticator=None, address=None, handle_errors=1, error_resource=None): + + """ + Deploy the given 'resource', with the given optional 'authenticator', at the + given optional 'address', where 'address' is a 2-tuple of the form + (host_string, port_integer). + + The optional 'handle_errors' flag (true by default) specifies whether error + conditions are handled gracefully, and the optional 'error_resource' + specifies an alternative error message generation resource, if desired. + """ + + host, port = address or default_address + handler = WSGIAdapter(resource, authenticator, handle_errors, error_resource) + app = wsgiref.simple_server.make_server(host, port or default_address, handler) + app.serve_forever() + # vim: tabstop=4 expandtab shiftwidth=4