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): 25 26 """ 27 Initialise with an 'id', a WebStack 'resource', and an optional 28 'authenticator'. 29 """ 30 31 self.id = id 32 self.webstack_resource = resource 33 self.webstack_authenticator = authenticator 34 35 def __bobo_traverse__(self, request, entry_name): 36 if entry_name == "index_html": 37 return getattr(self, "index_html") 38 return self 39 40 def index_html(self, REQUEST=None): 41 42 """ 43 Dispatch the given 'REQUEST' to the root application-specific WebStack 44 resource. 45 """ 46 47 if REQUEST is not None: 48 trans = WebStack.Zope.Transaction(REQUEST) 49 else: 50 raise "Internal Error" 51 52 if self.webstack_authenticator is None or self.webstack_authenticator.authenticate(trans): 53 try: 54 self.webstack_resource.respond(trans) 55 except EndOfResponse: 56 pass 57 else: 58 #trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % ( 59 # self.webstack_authenticator.get_auth_type(), self.webstack_authenticator.get_realm())) 60 raise "Unauthorized" 61 62 trans.commit() 63 #raise status_reasons[trans.get_response_code()] 64 65 # vim: tabstop=4 expandtab shiftwidth=4