def init(): """Initialize the filters.""" from cherrypy.lib import cptools instances = {} inputs, outputs = [], [] conf = cherrypy.config.get for filtercls in input_filters + conf('server.input_filters', []): if isinstance(filtercls, basestring): filtercls = cptools.attributes(filtercls) f = instances.get(filtercls) if f is None: f = instances[filtercls] = filtercls() inputs.append(f) for filtercls in conf('server.output_filters', []) + output_filters: if isinstance(filtercls, basestring): filtercls = cptools.attributes(filtercls) f = instances.get(filtercls) if f is None: f = instances[filtercls] = filtercls() outputs.append(f) # Transform the instance lists into a dict of methods # in 2.2 we check the old camelCase filter names first # to provide backward compatibility with 2.1 _filterhooks.clear() for old_name, new_name in zip(_old_input_methods, _input_methods): _filterhooks[new_name] = [] for f in inputs: method = getattr(f, old_name, None) if method: _filterhooks[new_name].append(method) else: method = getattr(f, new_name, None) if method: _filterhooks[new_name].append(method) for old_name, new_name in zip(_old_output_methods, _output_methods): _filterhooks[new_name] = [] for f in outputs: method = getattr(f, old_name, None) if method: _filterhooks[new_name].append(method) else: method = getattr(f, new_name, None) if method: _filterhooks[new_name].append(method)
def start(self, init_only=False, server_class=_missing, server=None, **kwargs): """Main function. MUST be called from the main thread. Set initOnly to True to keep this function from blocking. Set serverClass and server to None to skip starting any HTTP server. """ # Read old variable names for backward compatibility if 'initOnly' in kwargs: init_only = kwargs['initOnly'] if 'serverClass' in kwargs: server_class = kwargs['serverClass'] conf = cherrypy.config.get if not init_only: init_only = conf('server.init_only', False) if server is None: server = conf('server.instance', None) if server is None: if server_class is _missing: server_class = conf("server.class", _missing) if server_class is _missing: import _cpwsgi server_class = _cpwsgi.WSGIServer elif server_class and isinstance(server_class, basestring): # Dynamically load the class from the given string server_class = cptools.attributes(server_class) self.httpserverclass = server_class if server_class is not None: self.httpserver = server_class() else: if isinstance(server, basestring): server = cptools.attributes(server) self.httpserverclass = server.__class__ self.httpserver = server self.blocking = not init_only Engine.start(self)