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