1.1 --- a/examples/WSGI/CalendarHandler.py Thu Mar 24 17:41:03 2005 +0000
1.2 +++ b/examples/WSGI/CalendarHandler.py Thu Mar 24 17:41:17 2005 +0000
1.3 @@ -6,13 +6,9 @@
1.4 sys.path.append("/home/paulb/Software/Python/WebStack")
1.5 sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common")
1.6
1.7 -from WebStack.Adapters import WSGI
1.8 +from WebStack.Adapters.WSGI import deploy
1.9 from Calendar import DirectoryResource
1.10 -from wsgi_cgi import run_with_cgi
1.11
1.12 -# Special magic incantation.
1.13 -
1.14 -handler = WSGI.WSGIAdapter(DirectoryResource())
1.15 -run_with_cgi(handler)
1.16 +deploy(DirectoryResource())
1.17
1.18 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/examples/WSGI/CookiesHandler.py Thu Mar 24 17:41:03 2005 +0000
2.2 +++ b/examples/WSGI/CookiesHandler.py Thu Mar 24 17:41:17 2005 +0000
2.3 @@ -6,13 +6,9 @@
2.4 sys.path.append("/home/paulb/Software/Python/WebStack")
2.5 sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common")
2.6
2.7 -from WebStack.Adapters import WSGI
2.8 +from WebStack.Adapters.WSGI import deploy
2.9 from Cookies import CookiesResource
2.10 -from wsgi_cgi import run_with_cgi
2.11
2.12 -# Special magic incantation.
2.13 -
2.14 -handler = WSGI.WSGIAdapter(CookiesResource())
2.15 -run_with_cgi(handler)
2.16 +deploy(CookiesResource())
2.17
2.18 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/examples/WSGI/FormHandler.py Thu Mar 24 17:41:03 2005 +0000
3.2 +++ b/examples/WSGI/FormHandler.py Thu Mar 24 17:41:17 2005 +0000
3.3 @@ -6,13 +6,9 @@
3.4 sys.path.append("/home/paulb/Software/Python/WebStack")
3.5 sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common")
3.6
3.7 -from WebStack.Adapters import WSGI
3.8 +from WebStack.Adapters.WSGI import deploy
3.9 from Form import FormResource
3.10 -from wsgi_cgi import run_with_cgi
3.11
3.12 -# Special magic incantation.
3.13 -
3.14 -handler = WSGI.WSGIAdapter(FormResource())
3.15 -run_with_cgi(handler)
3.16 +deploy(FormResource())
3.17
3.18 # vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/examples/WSGI/LoginHandler.py Thu Mar 24 17:41:03 2005 +0000
4.2 +++ b/examples/WSGI/LoginHandler.py Thu Mar 24 17:41:17 2005 +0000
4.3 @@ -6,23 +6,19 @@
4.4 sys.path.append("/home/paulb/Software/Python/WebStack")
4.5 sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common")
4.6
4.7 -from WebStack.Adapters import WSGI
4.8 +from WebStack.Adapters.WSGI import deploy
4.9 from WebStack.Resources.Login import LoginResource, LoginAuthenticator
4.10 -from wsgi_cgi import run_with_cgi
4.11
4.12 -resource = LoginResource(
4.13 - LoginAuthenticator(
4.14 - secret_key="horses",
4.15 - credentials=(
4.16 - ("badger", "abc"),
4.17 - ("vole", "xyz"),
4.18 +deploy(
4.19 + LoginResource(
4.20 + LoginAuthenticator(
4.21 + secret_key="horses",
4.22 + credentials=(
4.23 + ("badger", "abc"),
4.24 + ("vole", "xyz"),
4.25 + )
4.26 )
4.27 )
4.28 )
4.29
4.30 -# Special magic incantation.
4.31 -
4.32 -handler = WSGI.WSGIAdapter(resource)
4.33 -run_with_cgi(handler)
4.34 -
4.35 # vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/examples/WSGI/SessionsHandler.py Thu Mar 24 17:41:03 2005 +0000
5.2 +++ b/examples/WSGI/SessionsHandler.py Thu Mar 24 17:41:17 2005 +0000
5.3 @@ -6,13 +6,9 @@
5.4 sys.path.append("/home/paulb/Software/Python/WebStack")
5.5 sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common")
5.6
5.7 -from WebStack.Adapters import WSGI
5.8 +from WebStack.Adapters.WSGI import deploy
5.9 from Sessions import SessionsResource
5.10 -from wsgi_cgi import run_with_cgi
5.11
5.12 -# Special magic incantation.
5.13 -
5.14 -handler = WSGI.WSGIAdapter(SessionsResource())
5.15 -run_with_cgi(handler)
5.16 +deploy(SessionsResource())
5.17
5.18 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/examples/WSGI/SimpleHandler.py Thu Mar 24 17:41:03 2005 +0000
6.2 +++ b/examples/WSGI/SimpleHandler.py Thu Mar 24 17:41:17 2005 +0000
6.3 @@ -6,13 +6,9 @@
6.4 sys.path.append("/home/paulb/Software/Python/WebStack")
6.5 sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common")
6.6
6.7 -from WebStack.Adapters import WSGI
6.8 +from WebStack.Adapters.WSGI import deploy
6.9 from Simple import SimpleResource
6.10 -from wsgi_cgi import run_with_cgi
6.11
6.12 -# Special magic incantation.
6.13 -
6.14 -handler = WSGI.WSGIAdapter(SimpleResource())
6.15 -run_with_cgi(handler)
6.16 +deploy(SimpleResource())
6.17
6.18 # vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/examples/WSGI/SimpleWithLoginHandler.py Thu Mar 24 17:41:03 2005 +0000
7.2 +++ b/examples/WSGI/SimpleWithLoginHandler.py Thu Mar 24 17:41:17 2005 +0000
7.3 @@ -6,23 +6,19 @@
7.4 sys.path.append("/home/paulb/Software/Python/WebStack")
7.5 sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common")
7.6
7.7 -from WebStack.Adapters import WSGI
7.8 +from WebStack.Adapters.WSGI import deploy
7.9 from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator
7.10 from Simple import SimpleResource
7.11 -from wsgi_cgi import run_with_cgi
7.12
7.13 -resource = LoginRedirectResource(
7.14 - login_url="http://localhost/wsgi/login",
7.15 - app_url="http://localhost",
7.16 - resource=SimpleResource(),
7.17 - authenticator=LoginRedirectAuthenticator(secret_key="horses"),
7.18 - anonymous_parameter_name="anonymous",
7.19 - logout_parameter_name="logout"
7.20 +deploy(
7.21 + LoginRedirectResource(
7.22 + login_url="http://localhost/wsgi/login",
7.23 + app_url="http://localhost",
7.24 + resource=SimpleResource(),
7.25 + authenticator=LoginRedirectAuthenticator(secret_key="horses"),
7.26 + anonymous_parameter_name="anonymous",
7.27 + logout_parameter_name="logout"
7.28 + )
7.29 )
7.30
7.31 -# Special magic incantation.
7.32 -
7.33 -handler = WSGI.WSGIAdapter(resource)
7.34 -run_with_cgi(handler)
7.35 -
7.36 # vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/examples/WSGI/UnicodeHandler.py Thu Mar 24 17:41:03 2005 +0000
8.2 +++ b/examples/WSGI/UnicodeHandler.py Thu Mar 24 17:41:17 2005 +0000
8.3 @@ -6,13 +6,9 @@
8.4 sys.path.append("/home/paulb/Software/Python/WebStack")
8.5 sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common")
8.6
8.7 -from WebStack.Adapters import WSGI
8.8 +from WebStack.Adapters.WSGI import deploy
8.9 from Unicode import UnicodeResource
8.10 -from wsgi_cgi import run_with_cgi
8.11
8.12 -# Special magic incantation.
8.13 -
8.14 -handler = WSGI.WSGIAdapter(UnicodeResource())
8.15 -run_with_cgi(handler)
8.16 +deploy(UnicodeResource())
8.17
8.18 # vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/examples/WSGI/wsgi_cgi.py Thu Mar 24 17:41:03 2005 +0000
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,69 +0,0 @@
9.4 -#!/usr/local/bin/python
9.5 -
9.6 -"""
9.7 -WSGI CGI handler code originating from PEP 333, transcribed by Titus Brown.
9.8 -Previously a standalone CGI program, this is now a module imported by the actual
9.9 -CGI programs.
9.10 -"""
9.11 -
9.12 -import os, sys
9.13 -
9.14 -def run_with_cgi(application):
9.15 -
9.16 - environ = dict(os.environ.items())
9.17 - environ['wsgi.input'] = sys.stdin
9.18 - environ['wsgi.errors'] = sys.stderr
9.19 - environ['wsgi.version'] = (1,0)
9.20 - environ['wsgi.multithread'] = False
9.21 - environ['wsgi.multiprocess'] = True
9.22 - environ['wsgi.run_once'] = True
9.23 -
9.24 - if environ.get('HTTPS','off') in ('on','1'):
9.25 - environ['wsgi.url_scheme'] = 'https'
9.26 - else:
9.27 - environ['wsgi.url_scheme'] = 'http'
9.28 -
9.29 - headers_set = []
9.30 - headers_sent = []
9.31 -
9.32 - def write(data):
9.33 - if not headers_set:
9.34 - raise AssertionError("write() before start_response()")
9.35 -
9.36 - elif not headers_sent:
9.37 - # Before the first output, send the stored headers
9.38 - status, response_headers = headers_sent[:] = headers_set
9.39 - sys.stdout.write('Status: %s\r\n' % status)
9.40 - for header in response_headers:
9.41 - sys.stdout.write('%s: %s\r\n' % header)
9.42 - sys.stdout.write('\r\n')
9.43 -
9.44 - sys.stdout.write(data)
9.45 - sys.stdout.flush()
9.46 -
9.47 - def start_response(status,response_headers,exc_info=None):
9.48 - if exc_info:
9.49 - try:
9.50 - if headers_sent:
9.51 - # Re-raise original exception if headers sent
9.52 - raise exc_info[0], exc_info[1], exc_info[2]
9.53 - finally:
9.54 - exc_info = None # avoid dangling circular ref
9.55 - elif headers_set:
9.56 - raise AssertionError("Headers already set!")
9.57 -
9.58 - headers_set[:] = [status,response_headers]
9.59 - return write
9.60 -
9.61 - result = application(environ, start_response)
9.62 - try:
9.63 - for data in result:
9.64 - if data: # don't send headers until body appears
9.65 - write(data)
9.66 - if not headers_sent:
9.67 - write('') # send headers now if body was empty
9.68 - finally:
9.69 - if hasattr(result,'close'):
9.70 - result.close()
9.71 -
9.72 -# vim: tabstop=4 expandtab shiftwidth=4