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 # Provide the adapter so that "path info" can be determined correctly. 48 49 if REQUEST is not None: 50 trans = WebStack.Zope.Transaction(REQUEST, self) 51 else: 52 raise "Internal Error" 53 54 if self.webstack_authenticator is None or self.webstack_authenticator.authenticate(trans): 55 try: 56 self.webstack_resource.respond(trans) 57 except EndOfResponse: 58 pass 59 else: 60 #trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % ( 61 # self.webstack_authenticator.get_auth_type(), self.webstack_authenticator.get_realm())) 62 raise "Unauthorized" 63 64 trans.commit() 65 #raise status_reasons[trans.get_response_code()] 66 67 # vim: tabstop=4 expandtab shiftwidth=4