def get_api(self, settings_dict, api_name, mock_cls=None, use_bind=False): api_settings = settings_dict.get(api_name.upper()) if not api_settings: raise ValueError("unknown or undefined API: %r" % (api_name,)) allow_mock = settings_dict.get("ALLOW_MOCK_API") if allow_mock: allow_mock = not ("NO_MOCK_" + api_name.upper()) in os.environ remote_url = getattr(api_settings, "remote_url", None) if remote_url is None and use_bind: remote_url = api_settings.bind_url if not remote_url: raise Exception("No 'remote_url' specified for %r" % (api_name,)) ClientCls = rpc.get_client_cls(remote_url) client = ClientCls(remote_url) should_check_mock = allow_mock and api_name not in self._get_api_force_no_mock if should_check_mock and not client.server_is_alive(): mock_cls = mock_cls or getattr(api_settings, "mock_cls", None) if mock_cls: mock_cls = instance_or_import(mock_cls) log.warning("%s is not up; using mock API %r for %r", remote_url, mock_cls, api_name) return mock_cls() ProxyClass = getattr(api_settings, "rpc_proxy", RPCClientProxy) return ProxyClass(client)
def get_api(self, settings_dict, api_name, mock_cls=None, use_bind=False): api_settings = settings_dict.get(api_name.upper()) if not api_settings: raise ValueError("unknown or undefined API: %r" %(api_name, )) allow_mock = settings_dict.get("ALLOW_MOCK_API") if allow_mock: allow_mock = not ("NO_MOCK_" + api_name.upper()) in os.environ remote_url = getattr(api_settings, "remote_url", None) if remote_url is None and use_bind: remote_url = api_settings.bind_url if not remote_url: raise Exception("No 'remote_url' specified for %r" %(api_name, )) ClientCls = rpc.get_client_cls(remote_url) client = ClientCls(remote_url) should_check_mock = ( allow_mock and api_name not in self._get_api_force_no_mock ) if should_check_mock and not client.server_is_alive(): mock_cls = mock_cls or getattr(api_settings, "mock_cls", None) if mock_cls: mock_cls = instance_or_import(mock_cls) log.warning("%s is not up; using mock API %r for %r", remote_url, mock_cls, api_name) return mock_cls() ProxyClass = getattr(api_settings, "rpc_proxy", RPCClientProxy) return ProxyClass(client)
def __init__(self, filename, handler_cls, *handler_args, **handler_kwargs): handler_level = handler_kwargs.get("level", logging.NOTSET) logging.Handler.__init__(self, level=handler_level) self.filename = filename self.handlers = {} self.handlers_lock = RLock() self.handler_cls = instance_or_import(handler_cls) self.handler_args = handler_args self.handler_kwargs = handler_kwargs
def _run(self, app_name, app_settings, app_argv): setproctitle(app_name) self.setup_blocking_detector(app_settings) app_class = instance_or_import(app_settings.app_class) app = app_class(app_name, app_settings, app_argv) return app.run()