1.1 --- a/WebStack/Adapters/WSGI.py Fri Jun 20 22:27:50 2008 +0200
1.2 +++ b/WebStack/Adapters/WSGI.py Sat Jan 29 23:34:57 2005 +0000
1.3 @@ -11,15 +11,17 @@
1.4
1.5 "A WSGI adapter class."
1.6
1.7 - def __init__(self, resource, authenticator=None):
1.8 + def __init__(self, resource, authenticator=None, handle_errors=1):
1.9
1.10 """
1.11 Initialise the adapter with the given WebStack 'resource' and the
1.12 - optional 'authenticator'.
1.13 + optional 'authenticator'. The optional 'handle_errors' parameter (if
1.14 + true) causes handlers to deal with uncaught exceptions cleanly.
1.15 """
1.16
1.17 self.resource = resource
1.18 self.authenticator = authenticator
1.19 + self.handle_errors = handle_errors
1.20
1.21 def __call__(self, environ, start_response):
1.22
1.23 @@ -43,6 +45,11 @@
1.24 self.resource.respond(trans)
1.25 except EndOfResponse:
1.26 pass
1.27 + except:
1.28 + if self.handle_errors:
1.29 + trans.set_response_code(500) # Internal error
1.30 + else:
1.31 + raise
1.32 else:
1.33 trans.set_response_code(401) # Unauthorized
1.34 trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % (