# HG changeset patch # User paulb # Date 1111686077 0 # Node ID 823610696b11ae8307418b368f4ef10638ac06b2 # Parent 2fd0fc812a293db939fd691cd39ee427a495a097 [project @ 2005-03-24 17:41:17 by paulb] Introduced a standardised 'deploy' function for all suitable frameworks. Moved wsgi_cgi into WebStack.Adapters.Helpers. diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/CalendarHandler.py --- a/examples/WSGI/CalendarHandler.py Thu Mar 24 17:41:03 2005 +0000 +++ b/examples/WSGI/CalendarHandler.py Thu Mar 24 17:41:17 2005 +0000 @@ -6,13 +6,9 @@ sys.path.append("/home/paulb/Software/Python/WebStack") sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") -from WebStack.Adapters import WSGI +from WebStack.Adapters.WSGI import deploy from Calendar import DirectoryResource -from wsgi_cgi import run_with_cgi -# Special magic incantation. - -handler = WSGI.WSGIAdapter(DirectoryResource()) -run_with_cgi(handler) +deploy(DirectoryResource()) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/CookiesHandler.py --- a/examples/WSGI/CookiesHandler.py Thu Mar 24 17:41:03 2005 +0000 +++ b/examples/WSGI/CookiesHandler.py Thu Mar 24 17:41:17 2005 +0000 @@ -6,13 +6,9 @@ sys.path.append("/home/paulb/Software/Python/WebStack") sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") -from WebStack.Adapters import WSGI +from WebStack.Adapters.WSGI import deploy from Cookies import CookiesResource -from wsgi_cgi import run_with_cgi -# Special magic incantation. - -handler = WSGI.WSGIAdapter(CookiesResource()) -run_with_cgi(handler) +deploy(CookiesResource()) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/FormHandler.py --- a/examples/WSGI/FormHandler.py Thu Mar 24 17:41:03 2005 +0000 +++ b/examples/WSGI/FormHandler.py Thu Mar 24 17:41:17 2005 +0000 @@ -6,13 +6,9 @@ sys.path.append("/home/paulb/Software/Python/WebStack") sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") -from WebStack.Adapters import WSGI +from WebStack.Adapters.WSGI import deploy from Form import FormResource -from wsgi_cgi import run_with_cgi -# Special magic incantation. - -handler = WSGI.WSGIAdapter(FormResource()) -run_with_cgi(handler) +deploy(FormResource()) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/LoginHandler.py --- a/examples/WSGI/LoginHandler.py Thu Mar 24 17:41:03 2005 +0000 +++ b/examples/WSGI/LoginHandler.py Thu Mar 24 17:41:17 2005 +0000 @@ -6,23 +6,19 @@ sys.path.append("/home/paulb/Software/Python/WebStack") sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") -from WebStack.Adapters import WSGI +from WebStack.Adapters.WSGI import deploy from WebStack.Resources.Login import LoginResource, LoginAuthenticator -from wsgi_cgi import run_with_cgi -resource = LoginResource( - LoginAuthenticator( - secret_key="horses", - credentials=( - ("badger", "abc"), - ("vole", "xyz"), +deploy( + LoginResource( + LoginAuthenticator( + secret_key="horses", + credentials=( + ("badger", "abc"), + ("vole", "xyz"), + ) ) ) ) -# Special magic incantation. - -handler = WSGI.WSGIAdapter(resource) -run_with_cgi(handler) - # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/SessionsHandler.py --- a/examples/WSGI/SessionsHandler.py Thu Mar 24 17:41:03 2005 +0000 +++ b/examples/WSGI/SessionsHandler.py Thu Mar 24 17:41:17 2005 +0000 @@ -6,13 +6,9 @@ sys.path.append("/home/paulb/Software/Python/WebStack") sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") -from WebStack.Adapters import WSGI +from WebStack.Adapters.WSGI import deploy from Sessions import SessionsResource -from wsgi_cgi import run_with_cgi -# Special magic incantation. - -handler = WSGI.WSGIAdapter(SessionsResource()) -run_with_cgi(handler) +deploy(SessionsResource()) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/SimpleHandler.py --- a/examples/WSGI/SimpleHandler.py Thu Mar 24 17:41:03 2005 +0000 +++ b/examples/WSGI/SimpleHandler.py Thu Mar 24 17:41:17 2005 +0000 @@ -6,13 +6,9 @@ sys.path.append("/home/paulb/Software/Python/WebStack") sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") -from WebStack.Adapters import WSGI +from WebStack.Adapters.WSGI import deploy from Simple import SimpleResource -from wsgi_cgi import run_with_cgi -# Special magic incantation. - -handler = WSGI.WSGIAdapter(SimpleResource()) -run_with_cgi(handler) +deploy(SimpleResource()) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/SimpleWithLoginHandler.py --- a/examples/WSGI/SimpleWithLoginHandler.py Thu Mar 24 17:41:03 2005 +0000 +++ b/examples/WSGI/SimpleWithLoginHandler.py Thu Mar 24 17:41:17 2005 +0000 @@ -6,23 +6,19 @@ sys.path.append("/home/paulb/Software/Python/WebStack") sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") -from WebStack.Adapters import WSGI +from WebStack.Adapters.WSGI import deploy from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator from Simple import SimpleResource -from wsgi_cgi import run_with_cgi -resource = LoginRedirectResource( - login_url="http://localhost/wsgi/login", - app_url="http://localhost", - resource=SimpleResource(), - authenticator=LoginRedirectAuthenticator(secret_key="horses"), - anonymous_parameter_name="anonymous", - logout_parameter_name="logout" +deploy( + LoginRedirectResource( + login_url="http://localhost/wsgi/login", + app_url="http://localhost", + resource=SimpleResource(), + authenticator=LoginRedirectAuthenticator(secret_key="horses"), + anonymous_parameter_name="anonymous", + logout_parameter_name="logout" + ) ) -# Special magic incantation. - -handler = WSGI.WSGIAdapter(resource) -run_with_cgi(handler) - # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/UnicodeHandler.py --- a/examples/WSGI/UnicodeHandler.py Thu Mar 24 17:41:03 2005 +0000 +++ b/examples/WSGI/UnicodeHandler.py Thu Mar 24 17:41:17 2005 +0000 @@ -6,13 +6,9 @@ sys.path.append("/home/paulb/Software/Python/WebStack") sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") -from WebStack.Adapters import WSGI +from WebStack.Adapters.WSGI import deploy from Unicode import UnicodeResource -from wsgi_cgi import run_with_cgi -# Special magic incantation. - -handler = WSGI.WSGIAdapter(UnicodeResource()) -run_with_cgi(handler) +deploy(UnicodeResource()) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 2fd0fc812a29 -r 823610696b11 examples/WSGI/wsgi_cgi.py --- a/examples/WSGI/wsgi_cgi.py Thu Mar 24 17:41:03 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -#!/usr/local/bin/python - -""" -WSGI CGI handler code originating from PEP 333, transcribed by Titus Brown. -Previously a standalone CGI program, this is now a module imported by the actual -CGI programs. -""" - -import os, sys - -def run_with_cgi(application): - - environ = dict(os.environ.items()) - environ['wsgi.input'] = sys.stdin - environ['wsgi.errors'] = sys.stderr - environ['wsgi.version'] = (1,0) - environ['wsgi.multithread'] = False - environ['wsgi.multiprocess'] = True - environ['wsgi.run_once'] = True - - if environ.get('HTTPS','off') in ('on','1'): - environ['wsgi.url_scheme'] = 'https' - else: - environ['wsgi.url_scheme'] = 'http' - - headers_set = [] - headers_sent = [] - - def write(data): - if not headers_set: - raise AssertionError("write() before start_response()") - - elif not headers_sent: - # Before the first output, send the stored headers - status, response_headers = headers_sent[:] = headers_set - sys.stdout.write('Status: %s\r\n' % status) - for header in response_headers: - sys.stdout.write('%s: %s\r\n' % header) - sys.stdout.write('\r\n') - - sys.stdout.write(data) - sys.stdout.flush() - - def start_response(status,response_headers,exc_info=None): - if exc_info: - try: - if headers_sent: - # Re-raise original exception if headers sent - raise exc_info[0], exc_info[1], exc_info[2] - finally: - exc_info = None # avoid dangling circular ref - elif headers_set: - raise AssertionError("Headers already set!") - - headers_set[:] = [status,response_headers] - return write - - result = application(environ, start_response) - try: - for data in result: - if data: # don't send headers until body appears - write(data) - if not headers_sent: - write('') # send headers now if body was empty - finally: - if hasattr(result,'close'): - result.close() - -# vim: tabstop=4 expandtab shiftwidth=4