1.1 --- a/WebStack/Adapters/WSGI.py Thu Sep 27 22:49:16 2007 +0000
1.2 +++ b/WebStack/Adapters/WSGI.py Thu Sep 27 22:50:07 2007 +0000
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 WSGI adapter.
1.6
1.7 -Copyright (C) 2004, 2005, 2006 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2004, 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This library is free software; you can redistribute it and/or
1.11 modify it under the terms of the GNU Lesser General Public
1.12 @@ -89,7 +89,7 @@
1.13 )
1.14 return [trans.get_wsgi_content()]
1.15
1.16 -def deploy(resource, authenticator=None, address=None, handle_errors=1, error_resource=None):
1.17 +def deploy_as_cgi(resource, authenticator=None, address=None, handle_errors=1, error_resource=None):
1.18
1.19 """
1.20 Deploy the given 'resource', with the given optional 'authenticator', at the
1.21 @@ -106,4 +106,28 @@
1.22 handler = WSGIAdapter(resource, authenticator, handle_errors, error_resource)
1.23 run_with_cgi(handler)
1.24
1.25 +try:
1.26 + import wsgiref.simple_server
1.27 +except ImportError:
1.28 + pass
1.29 +else:
1.30 + default_address = ("", 8080)
1.31 +
1.32 + def deploy(resource, authenticator=None, address=None, handle_errors=1, error_resource=None):
1.33 +
1.34 + """
1.35 + Deploy the given 'resource', with the given optional 'authenticator', at the
1.36 + given optional 'address', where 'address' is a 2-tuple of the form
1.37 + (host_string, port_integer).
1.38 +
1.39 + The optional 'handle_errors' flag (true by default) specifies whether error
1.40 + conditions are handled gracefully, and the optional 'error_resource'
1.41 + specifies an alternative error message generation resource, if desired.
1.42 + """
1.43 +
1.44 + host, port = address or default_address
1.45 + handler = WSGIAdapter(resource, authenticator, handle_errors, error_resource)
1.46 + app = wsgiref.simple_server.make_server(host, port or default_address, handler)
1.47 + app.serve_forever()
1.48 +
1.49 # vim: tabstop=4 expandtab shiftwidth=4