1 #!/usr/bin/env python 2 3 """ 4 mod_python adapter. 5 """ 6 7 import WebStack.ModPython 8 from mod_python import apache 9 10 def respond(request, resource, debug=0): 11 12 """ 13 Dispatch the given 'request' to the root application-specific 'resource'. 14 The optional 'debug' flag, if set to 1, causes tracebacks to be displayed in 15 the browser. 16 """ 17 18 trans = WebStack.ModPython.Transaction(request) 19 20 # NOTE: Resource pooling may be appropriate. 21 22 try: 23 resource.respond(trans) 24 trans.commit() 25 return trans.get_response_code() 26 except: 27 28 # NOTE: Error conditions should be investigated further, along with 29 # NOTE: other response states. 30 31 if not debug: 32 return apache.HTTP_INTERNAL_SERVER_ERROR 33 else: 34 raise 35 36 def authenticate(request, authenticator, debug=0): 37 38 """ 39 Dispatch the given 'request' to the application-specific 'authenticator'. 40 The optional 'debug' flag, if set to 1, causes tracebacks to be displayed in 41 the browser. 42 """ 43 44 trans = WebStack.ModPython.Transaction(request) 45 46 # NOTE: Resource pooling may be appropriate. 47 # NOTE: Forbidden access is not yet considered here. 48 49 try: 50 if authenticator.authenticate(trans): 51 return apache.OK 52 else: 53 return apache.HTTP_UNAUTHORIZED 54 except: 55 56 # NOTE: Error conditions should be investigated further, along with 57 # NOTE: other response states. 58 59 if not debug: 60 return apache.HTTP_INTERNAL_SERVER_ERROR 61 else: 62 raise 63 64 # vim: tabstop=4 expandtab shiftwidth=4