1.1 --- a/WebStack/Adapters/Webware.py Fri Jun 20 22:27:50 2008 +0200
1.2 +++ b/WebStack/Adapters/Webware.py Sat Jan 29 23:34:57 2005 +0000
1.3 @@ -29,15 +29,18 @@
1.4 instantiation.
1.5 """
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 parser object with the given root application-specific
1.12 - 'resource' and optional 'authenticator'.
1.13 + 'resource' and optional 'authenticator'. The optional 'handle_errors'
1.14 + parameter (if true) causes handlers to deal with uncaught exceptions
1.15 + cleanly.
1.16 """
1.17
1.18 self.webstack_resource = resource
1.19 self.webstack_authenticator = authenticator
1.20 + self.handle_errors = handle_errors
1.21
1.22 def parse(self, trans, requestPath):
1.23
1.24 @@ -52,7 +55,8 @@
1.25 should be available elsewhere.
1.26 """
1.27
1.28 - return WebStackServlet(self.webstack_resource, self.webstack_authenticator)
1.29 + return WebStackServlet(self.webstack_resource, self.webstack_authenticator,
1.30 + self.handle_errors)
1.31
1.32 # For Webware 0.8.1 and earlier, employ servlet factories and servlets.
1.33
1.34 @@ -66,19 +70,22 @@
1.35 application-specific resources.
1.36 """
1.37
1.38 - def __init__(self, application, resource, file_extensions, authenticator=None):
1.39 + def __init__(self, application, resource, file_extensions, authenticator=None, handle_errors=1):
1.40
1.41 """
1.42 Initialise the servlet factory with the Webware 'application' and the
1.43 WebStack root application-specific 'resource'. The 'file_extensions'
1.44 specified indicate for which files this factory is invoked. An optional
1.45 - 'authenticator' is used to control access to the resource.
1.46 + 'authenticator' is used to control access to the resource. The optional
1.47 + 'handle_errors' parameter (if true) causes handlers to deal with
1.48 + uncaught exceptions cleanly.
1.49 """
1.50
1.51 ServletFactory.__init__(self, application)
1.52 self.webstack_resource = resource
1.53 self.file_extensions = file_extensions
1.54 self.webstack_authenticator = authenticator
1.55 + self.handle_errors = handle_errors
1.56
1.57 def uniqueness(self):
1.58
1.59 @@ -105,7 +112,8 @@
1.60 method is invoked on the servlet.
1.61 """
1.62
1.63 - return WebStackServlet(self.webstack_resource, self.webstack_authenticator)
1.64 + return WebStackServlet(self.webstack_resource, self.webstack_authenticator,
1.65 + self.handle_errors)
1.66
1.67 # Servlets are common to both solutions.
1.68
1.69 @@ -113,16 +121,18 @@
1.70
1.71 "A servlet which dispatches transactions to application-specific resources."
1.72
1.73 - def __init__(self, resource, authenticator):
1.74 + def __init__(self, resource, authenticator, handle_errors):
1.75
1.76 """
1.77 Initialise the servlet with an application-specific 'resource' and
1.78 - 'authenticator'.
1.79 + 'authenticator'. Where 'handle_errors' is true, uncaught exceptions are
1.80 + dealt with by the handler.
1.81 """
1.82
1.83 Servlet.__init__(self)
1.84 self.webstack_resource = resource
1.85 self.webstack_authenticator = authenticator
1.86 + self.handle_errors = handle_errors
1.87
1.88 def respond(self, trans):
1.89
1.90 @@ -137,6 +147,11 @@
1.91 self.webstack_resource.respond(new_trans)
1.92 except EndOfResponse:
1.93 pass
1.94 + except:
1.95 + if self.handle_errors:
1.96 + new_trans.set_response_code(500) # Internal error
1.97 + else:
1.98 + raise
1.99 else:
1.100 new_trans.set_response_code(401) # Unauthorized
1.101 new_trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % (