1 #!/usr/bin/env python 2 3 """ 4 Webware adapter. 5 """ 6 7 import WebStack.Webware 8 9 # NOTE: Webware Experimental seems to employ special URLParsers in contexts 10 # NOTE: which are much more compatible with the WebStack approach. 11 12 from WebKit.ServletFactory import ServletFactory 13 from WebKit.Servlet import Servlet 14 15 class WebStackServletFactory(ServletFactory): 16 17 """ 18 A servlet factory object producing servlets which provide access to 19 application-specific resources. 20 """ 21 22 def __init__(self, application, resource, file_extensions): 23 24 """ 25 Initialise the servlet factory with the Webware 'application' and the 26 WebStack root application-specific 'resource'. The 'file_extensions' 27 specified indicate for which files this factory is invoked. 28 """ 29 30 ServletFactory.__init__(self, application) 31 self.webstack_resource = resource 32 self.file_extensions = file_extensions 33 34 def uniqueness(self): 35 36 """ 37 Return "file" uniqueness - probably the most appropriate response. 38 """ 39 40 return "file" 41 42 def extensions(self): 43 44 """ 45 Return the file extensions supported by this factory. 46 """ 47 48 return self.file_extensions 49 50 def servletForTransaction(self, trans): 51 52 """ 53 Return a servlet which will provide access to the application-specific 54 resources. The 'trans' object - a Webware transaction - is not given to 55 the servlet since such information is available when the 'respond' 56 method is invoked on the servlet. 57 """ 58 59 return WebStackServlet(self.webstack_resource) 60 61 class WebStackServlet(Servlet): 62 63 "A servlet which dispatches transactions to application-specific resources." 64 65 def __init__(self, resource): 66 67 "Initialise the servlet with an application-specific 'resource'." 68 69 self.webstack_resource = resource 70 71 def respond(self, trans): 72 73 """ 74 Respond to the incoming transaction, 'trans', by dispatching to the 75 application-specific resource. 76 """ 77 78 new_trans = WebStack.Webware.Transaction(trans) 79 self.webstack_resource.respond(new_trans) 80 81 # vim: tabstop=4 expandtab shiftwidth=4