1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/WebStack/Adapters/CGI.py Sat Apr 24 20:33:38 2004 +0000
1.3 @@ -0,0 +1,29 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +CGI adapter.
1.8 +"""
1.9 +
1.10 +import WebStack.CGI
1.11 +import sys, os
1.12 +
1.13 +def respond(resource, authenticator=None):
1.14 +
1.15 + """
1.16 + Dispatch to the root application-specific 'resource'. Employ the optional
1.17 + 'authenticator' to control access to the resource.
1.18 + """
1.19 +
1.20 + trans = WebStack.CGI.Transaction(sys.stdin, sys.stdout, os.environ)
1.21 +
1.22 + try:
1.23 + if authenticator is None or authenticator.authenticate(trans):
1.24 + resource.respond(trans)
1.25 + else:
1.26 + trans.set_response_code(401) # Unauthorized
1.27 + trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % (
1.28 + authenticator.get_auth_type(), authenticator.get_realm()))
1.29 + finally:
1.30 + trans.commit()
1.31 +
1.32 +# vim: tabstop=4 expandtab shiftwidth=4