def __init__(self, js_path=None, compression_enabled=None): super(WindmillApplication, self).__init__() if js_path is None: js_path = windmill.settings['JS_PATH'] if compression_enabled is None: compression_enabled = not windmill.settings['DISABLE_JS_COMPRESS'] self.proxy_application = ProxyApplication() self.test_resolution_suite = TestResolutionSuite() self.command_resolution_suite = CommandResolutionSuite() self.queue = ControllerQueue(self.command_resolution_suite, self.test_resolution_suite) self.xmlrpc_methods_instance = XMLRPCMethods(self.queue, self.test_resolution_suite, self.command_resolution_suite, proxy=self.proxy_application) self.jsonrpc_methods_instance = JSONRPCMethods(self.queue, self.test_resolution_suite, self.command_resolution_suite, proxy=self.proxy_application) self.add_resource('windmill-jsonrpc', JSONRPCApplication(instance=self.jsonrpc_methods_instance)) self.add_resource('windmill-serv', FileServerApplication(js_path)) self.add_resource('windmill-xmlrpc', XMLRPCApplication(instance=self.xmlrpc_methods_instance)) self.add_resource('windmill-compressor', CompressorApplication(os.path.join(js_path, 'js'), compression_enabled))
class WindmillApplication(RestApplication): def __init__(self, js_path=None, compression_enabled=None): super(WindmillApplication, self).__init__() if js_path is None: js_path = windmill.settings['JS_PATH'] if compression_enabled is None: compression_enabled = not windmill.settings['DISABLE_JS_COMPRESS'] self.proxy_application = ProxyApplication() self.test_resolution_suite = TestResolutionSuite() self.command_resolution_suite = CommandResolutionSuite() self.queue = ControllerQueue(self.command_resolution_suite, self.test_resolution_suite) self.xmlrpc_methods_instance = XMLRPCMethods(self.queue, self.test_resolution_suite, self.command_resolution_suite, proxy=self.proxy_application) self.jsonrpc_methods_instance = JSONRPCMethods(self.queue, self.test_resolution_suite, self.command_resolution_suite, proxy=self.proxy_application) self.add_resource('windmill-jsonrpc', JSONRPCApplication(instance=self.jsonrpc_methods_instance)) self.add_resource('windmill-serv', FileServerApplication(js_path)) self.add_resource('windmill-xmlrpc', XMLRPCApplication(instance=self.xmlrpc_methods_instance)) self.add_resource('windmill-compressor', CompressorApplication(os.path.join(js_path, 'js'), compression_enabled)) def __call__(self, environ, start_response): """Special subclass __call__ method that finds windmill-serv anywhere in path""" request = self.request_class(environ, start_response) path = environ['SCRIPT_NAME'] + environ['PATH_INFO'] if len(path) is 0: path = '/' if path.startswith('/'): path = [p for p in path.split('/') if len(p) is not 0] elif environ['PATH_INFO'].startswith('http'): path = [p for p in urlparse(path).path.split('/') if len(p) is not 0] else: raise Exception('Cannot read PATH_INFO '+request.full_uri+str(request.environ)) if len(path) is 0: response = self.handler(request) if response is None: response = Response500(str(type(self))+".handler() did not return a response object") response.request = request response.start_response() return response elif 'windmill-serv' in path: path = path[path.index('windmill-serv'):] response = self.rest_handler(request, *path) if response is None: response = Response500(str(type(self))+".rest_handler() did not return a response object") response.request = request response.start_response() return response else: response = self.rest_handler(request, *path) if response is None: response = Response500(str(type(self))+".rest_handler() did not return a response object") response.request = request response.start_response() return response def handler(self, request, *path): return self.proxy_application.handler(request)