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 #from ZPublisher.HTTPResponse import status_reasons 13 14 class WebStackAdapterProduct(Persistent, Item): 15 16 "A WebStack adapter product superclass." 17 18 def __init__(self, id, resource, authenticator=None, permission=None): 19 20 """ 21 Initialise with an 'id', a WebStack 'resource', and an optional 22 'authenticator'. The optional 'permission' is a Zope-related security 23 identifier. 24 """ 25 26 self.id = id 27 self.webstack_resource = resource 28 self.webstack_authenticator = authenticator 29 self.security = ClassSecurityInfo() 30 31 if authenticator is None: 32 self.security.declarePublic("index_html") 33 else: 34 permission = permission or "View" 35 self.security.declareProtected(permission, "index_html") 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 if REQUEST is not None: 50 trans = WebStack.Zope.Transaction(REQUEST) 51 else: 52 raise "Internal Error" 53 54 if self.webstack_authenticator is None or self.webstack_authenticator.authenticate(trans): 55 self.webstack_resource.respond(trans) 56 else: 57 #trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % ( 58 # self.webstack_authenticator.get_auth_type(), self.webstack_authenticator.get_realm())) 59 raise "Unauthorized" 60 61 trans.commit() 62 #raise status_reasons[trans.get_response_code()] 63 64 # vim: tabstop=4 expandtab shiftwidth=4