1.1 --- a/WebStack/Adapters/Twisted.py Fri Jun 20 22:27:50 2008 +0200
1.2 +++ b/WebStack/Adapters/Twisted.py Sat Jan 29 23:34:57 2005 +0000
1.3 @@ -14,16 +14,18 @@
1.4
1.5 isLeaf = 1
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 root application-specific 'resource' and optional
1.12 - 'authenticator'.
1.13 + 'authenticator'. The optional 'handle_errors' parameter (if true) causes
1.14 + handlers to deal with uncaught exceptions cleanly.
1.15 """
1.16
1.17 twisted.web.resource.Resource.__init__(self)
1.18 self.webstack_resource = resource
1.19 self.webstack_authenticator = authenticator
1.20 + self.handle_errors = handle_errors
1.21
1.22 def getChild(self, path, request):
1.23 raise NotImplementedError, "getChild"
1.24 @@ -38,6 +40,11 @@
1.25 self.webstack_resource.respond(trans)
1.26 except EndOfResponse:
1.27 pass
1.28 + except:
1.29 + if self.handle_errors:
1.30 + trans.set_response_code(500) # Internal error
1.31 + else:
1.32 + raise
1.33 else:
1.34 trans.set_response_code(401) # Unauthorized
1.35 trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % (