# HG changeset patch # User paulb # Date 1082838818 0 # Node ID 2e48b46491c72550c20ef2996722cec5dc2159af # Parent 8f35654956bbe54d030e94c2400ae4945841f27f [project @ 2004-04-24 20:33:38 by paulb] Added CGI support. diff -r 8f35654956bb -r 2e48b46491c7 WebStack/Adapters/CGI.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WebStack/Adapters/CGI.py Sat Apr 24 20:33:38 2004 +0000 @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +""" +CGI adapter. +""" + +import WebStack.CGI +import sys, os + +def respond(resource, authenticator=None): + + """ + Dispatch to the root application-specific 'resource'. Employ the optional + 'authenticator' to control access to the resource. + """ + + trans = WebStack.CGI.Transaction(sys.stdin, sys.stdout, os.environ) + + try: + if authenticator is None or authenticator.authenticate(trans): + resource.respond(trans) + else: + trans.set_response_code(401) # Unauthorized + trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % ( + authenticator.get_auth_type(), authenticator.get_realm())) + finally: + trans.commit() + +# vim: tabstop=4 expandtab shiftwidth=4