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