1 #!/usr/bin/env python 2 3 """ 4 Zope adapter. 5 """ 6 7 import WebStack.Zope 8 from WebStack.Generic import EndOfResponse 9 10 from Globals import Persistent 11 from OFS.SimpleItem import Item 12 from AccessControl import ClassSecurityInfo 13 import Acquisition 14 #from ZPublisher.HTTPResponse import status_reasons 15 16 class WebStackAdapterProduct(Persistent, Acquisition.Implicit, Item): 17 18 "A WebStack adapter product superclass." 19 20 security = ClassSecurityInfo() 21 security.declareObjectProtected("View") 22 security.declareProtected("View", "index_html") 23 24 def __init__(self, id, resource, authenticator=None, handle_errors=1): 25 26 """ 27 Initialise with an 'id', a WebStack 'resource', and an optional 28 'authenticator'. The optional 'handle_errors' parameter (if true) causes 29 handlers to deal with uncaught exceptions cleanly. 30 """ 31 32 self.id = id 33 self.webstack_resource = resource 34 self.webstack_authenticator = authenticator 35 self.handle_errors = handle_errors 36 37 def __bobo_traverse__(self, request, entry_name): 38 if entry_name == "index_html": 39 return getattr(self, "index_html") 40 return self 41 42 def index_html(self, REQUEST=None): 43 44 """ 45 Dispatch the given 'REQUEST' to the root application-specific WebStack 46 resource. 47 """ 48 49 # Provide the adapter so that "path info" can be determined correctly. 50 51 if REQUEST is not None: 52 trans = WebStack.Zope.Transaction(REQUEST, self) 53 else: 54 raise "Internal Error" 55 56 if self.webstack_authenticator is None or self.webstack_authenticator.authenticate(trans): 57 try: 58 self.webstack_resource.respond(trans) 59 except EndOfResponse: 60 pass 61 except: 62 if self.handle_errors: 63 trans.set_response_code(500) # Internal error 64 else: 65 raise 66 else: 67 #trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % ( 68 # self.webstack_authenticator.get_auth_type(), self.webstack_authenticator.get_realm())) 69 raise "Unauthorized" 70 71 trans.commit() 72 #raise status_reasons[trans.get_response_code()] 73 74 # vim: tabstop=4 expandtab shiftwidth=4