mirror of
https://github.com/searxng/searxng.git
synced 2026-10-19 09:54:24 +00:00
[fix] issues reported by pylint v4.1.2 (#6827)
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
619696aa6c
commit
bba4f64e8a
11 changed files with 32 additions and 29 deletions
|
|
@ -93,7 +93,7 @@ class TrackerPatternsDB:
|
|||
continue
|
||||
|
||||
if resp.status_code != 200:
|
||||
log.warning(f"TRACKER_PATTERNS: ClearURL ignore HTTP {resp.status_code} {url}")
|
||||
log.warning("TRACKER_PATTERNS: ClearURL ignore HTTP %s %s", resp.status_code, url)
|
||||
continue
|
||||
|
||||
break
|
||||
|
|
|
|||
|
|
@ -115,26 +115,26 @@ def load_engine(engine_data: dict[str, t.Any]) -> "Engine | types.ModuleType | N
|
|||
logger.error('An engine does not have a "name" field')
|
||||
return None
|
||||
if '_' in engine_name:
|
||||
logger.error('Engine name contains underscore: "{}"'.format(engine_name))
|
||||
logger.error('Engine name contains underscore: "%s"', engine_name)
|
||||
return None
|
||||
|
||||
if engine_name.lower() != engine_name:
|
||||
logger.warning('Engine name is not lowercase: "{}", converting to lowercase'.format(engine_name))
|
||||
logger.warning('Engine name is not lowercase: "%s", converting to lowercase', engine_name)
|
||||
engine_name = engine_name.lower()
|
||||
engine_data['name'] = engine_name
|
||||
|
||||
# load_module
|
||||
module_name = engine_data.get('engine')
|
||||
if module_name is None:
|
||||
logger.error('The "engine" field is missing for the engine named "{}"'.format(engine_name))
|
||||
logger.error('The "engine" field is missing for the engine named "%s"', engine_name)
|
||||
return None
|
||||
try:
|
||||
engine = load_module(module_name + '.py', ENGINE_DIR)
|
||||
except (SyntaxError, KeyboardInterrupt, SystemExit, SystemError, ImportError, RuntimeError):
|
||||
logger.exception('Fatal exception in engine "{}"'.format(module_name))
|
||||
logger.exception('Fatal exception in engine "%s"', module_name)
|
||||
sys.exit(1)
|
||||
except BaseException:
|
||||
logger.exception('Cannot load engine "{}"'.format(module_name))
|
||||
logger.exception('Cannot load engine "%s"', module_name)
|
||||
return None
|
||||
|
||||
check_engine_module(engine)
|
||||
|
|
@ -247,7 +247,7 @@ def is_missing_required_attributes(engine: "Engine | types.ModuleType"):
|
|||
missing = False
|
||||
for engine_attr in dir(engine):
|
||||
if not engine_attr.startswith('_') and getattr(engine, engine_attr) is None:
|
||||
logger.error('Missing engine config attribute: "{0}.{1}"'.format(engine.name, engine_attr))
|
||||
logger.error('Missing engine config attribute: "%s.%s"', engine.name, engine_attr)
|
||||
missing = True
|
||||
return missing
|
||||
|
||||
|
|
@ -277,12 +277,12 @@ def call_engine_setup(engine: "Engine | types.ModuleType", engine_data: dict[str
|
|||
if setup_func is None:
|
||||
setup_ok = True
|
||||
elif not callable(setup_func):
|
||||
logger.error(f"engine's setup method isn't a callable (is of type: {type(setup_func)})")
|
||||
logger.error("engine's setup method isn't a callable (is of type: %s)", type(setup_func))
|
||||
else:
|
||||
try:
|
||||
setup_ok = engine.setup(engine_data)
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
logger.exception(f"(PID {os.getpid()}) {engine.name}: engine SETUP failed, exception: {e}")
|
||||
logger.exception("(PID %s) %s: engine SETUP failed, exception: %s", os.getpid(), engine.name, e)
|
||||
setup_ok = False
|
||||
|
||||
# The evaluation of the return value is analogous to Engine.init
|
||||
|
|
@ -290,18 +290,18 @@ def call_engine_setup(engine: "Engine | types.ModuleType", engine_data: dict[str
|
|||
setup_ok = True
|
||||
|
||||
if not setup_ok:
|
||||
logger.error(f"(PID {os.getpid()}) {engine.name}: engine setup was not successful")
|
||||
logger.error("(PID %s) %s: engine setup was not successful", os.getpid(), engine.name)
|
||||
return setup_ok
|
||||
|
||||
|
||||
def register_engine(engine: "Engine | types.ModuleType"):
|
||||
if engine.name in engines:
|
||||
logger.error('Engine config error: ambiguous name: {0}'.format(engine.name))
|
||||
logger.error('Engine config error: ambiguous name: %s', engine.name)
|
||||
sys.exit(1)
|
||||
engines[engine.name] = engine
|
||||
|
||||
if engine.shortcut in engine_shortcuts:
|
||||
logger.error('Engine config error: ambiguous shortcut: {0}'.format(engine.shortcut))
|
||||
logger.error('Engine config error: ambiguous shortcut: %s', engine.shortcut)
|
||||
sys.exit(1)
|
||||
engine_shortcuts[engine.shortcut] = engine.name
|
||||
|
||||
|
|
@ -327,7 +327,9 @@ def load_engines(engine_list: list[dict[str, t.Any]]):
|
|||
# if an engine can't be loaded (if for example the engine is missing
|
||||
# tor or some other requirements) its set to inactive!
|
||||
logger.error(
|
||||
f"(PID {os.getpid()}) {engine_data.get('name', '???')}: can't register engine (loading engine failed)"
|
||||
"(PID %s) %s: can't register engine (loading engine failed)",
|
||||
os.getpid(),
|
||||
engine_data.get("name", "???"),
|
||||
)
|
||||
engine_data["inactive"] = True
|
||||
return engines
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ def obtain_token():
|
|||
)
|
||||
token['value'] = loads(actual_token.text)['authInfo']['access_token']
|
||||
token['last_updated'] = update_time
|
||||
# pylint: disable=bare-except
|
||||
except:
|
||||
except: # pylint: disable=bare-except
|
||||
pass
|
||||
return token
|
||||
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ def _get_results_from_process(res: EngineResults, cmd, pageno):
|
|||
for raw_result in raw_results:
|
||||
result = __parse_single_result(raw_result)
|
||||
if result is None:
|
||||
_command_logger.debug('skipped result:', raw_result)
|
||||
_command_logger.debug('skipped result: %s', raw_result)
|
||||
continue
|
||||
|
||||
if start <= count and count <= end: # pylint: disable=chained-comparison
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ def init():
|
|||
cfg_file = (settings_loader.get_user_cfg_folder() or pathlib.Path("/etc/searxng")) / "favicons.toml"
|
||||
if not cfg_file.exists():
|
||||
if is_active():
|
||||
logger.error(f"missing favicon config: {cfg_file}")
|
||||
logger.error("missing favicon config: %s", cfg_file)
|
||||
cfg_file = config.DEFAULT_CFG_TOML_PATH
|
||||
|
||||
logger.debug(f"load favicon config: {cfg_file}")
|
||||
logger.debug("load favicon config: %s", cfg_file)
|
||||
cfg = config.FaviconConfig.from_toml_file(cfg_file, use_cache=True)
|
||||
cache.init(cfg.cache)
|
||||
proxy.init(cfg.proxy)
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ CREATE TABLE IF NOT EXISTS blob_map (
|
|||
bytes_c = len(data or b"")
|
||||
if bytes_c > self.cfg.BLOB_MAX_BYTES:
|
||||
logger.info(
|
||||
"favicon of resolver: %s / authority: %s to big to cache (bytes: %s) " % (resolver, authority, bytes_c)
|
||||
"favicon of resolver: %s / authority: %s to big to cache (bytes: %s) ", resolver, authority, bytes_c
|
||||
)
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class Request(t.NamedTuple):
|
|||
|
||||
method: str
|
||||
url: str
|
||||
kwargs: dict[str, str] = {}
|
||||
kwargs: dict[str, str] = {} # pylint: disable=dangerous-default-value
|
||||
|
||||
@staticmethod
|
||||
def get(url: str, **kwargs: t.Any):
|
||||
|
|
|
|||
|
|
@ -126,9 +126,11 @@ class Search:
|
|||
actual_timeout = min(query_timeout, max_request_timeout)
|
||||
|
||||
logger.debug(
|
||||
"actual_timeout={0} (default_timeout={1}, ?timeout_limit={2}, max_request_timeout={3})".format(
|
||||
actual_timeout, default_timeout, query_timeout, max_request_timeout
|
||||
)
|
||||
"actual_timeout=%s (default_timeout=%s, ?timeout_limit=%s, max_request_timeout=%s)",
|
||||
actual_timeout,
|
||||
default_timeout,
|
||||
query_timeout,
|
||||
max_request_timeout,
|
||||
)
|
||||
|
||||
return requests, actual_timeout
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class ProcessorMap(dict[str, EngineProcessor]):
|
|||
eng_type = getattr(eng_obj, "engine_type", "online")
|
||||
proc_cls = self.processor_types.get(eng_type)
|
||||
if proc_cls is None:
|
||||
logger.error("Engine '%s' is of unknown engine_type: %s", eng_type)
|
||||
logger.error("Engine of name '%s' is of unknown engine_type: %s", eng_name, eng_type)
|
||||
continue
|
||||
|
||||
# initialize (and register) the engine
|
||||
|
|
@ -94,7 +94,7 @@ class ProcessorMap(dict[str, EngineProcessor]):
|
|||
# logger.debug("registered engine processor: %s", eng_proc.engine.name)
|
||||
else:
|
||||
logger.error(
|
||||
f"(PID {os.getpid()}) {eng_proc.engine.name}: can't register engines processor (init engine failed)"
|
||||
"(PID %s) %s: can't register engines processor (init engine failed)", os.getpid(), eng_proc.engine.name
|
||||
)
|
||||
|
||||
return eng_proc_ok
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ class EngineProcessor(ABC):
|
|||
try:
|
||||
init_ok = self.engine.init(eng_setting)
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
logger.exception(f"(PID {os.getpid()}) {self.engine.name}: engine INIT failed, exception: {e}")
|
||||
logger.exception("(PID %s) %s: engine INIT failed, exception: %s", os.getpid(), self.engine.name, e)
|
||||
init_ok = False
|
||||
|
||||
# In older engines, None is returned from the init method, which is
|
||||
|
|
@ -172,7 +172,7 @@ class EngineProcessor(ABC):
|
|||
init_ok = True
|
||||
|
||||
if not init_ok:
|
||||
logger.error(f"(PID {os.getpid()}) {self.engine.name}: engine init was not successful")
|
||||
logger.error("(PID %s) %s: engine init was not successful", os.getpid(), self.engine.name)
|
||||
|
||||
return init_ok
|
||||
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ def code_highlighter(codelines, language=None, hl_lines=None, strip_whitespace=T
|
|||
lexer = get_lexer_by_name(language, stripall=strip_whitespace, stripnl=strip_new_lines)
|
||||
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
logger.warning("pygments lexer: %s " % e)
|
||||
logger.warning("pygments lexer: %s ", e)
|
||||
# if lexer is not found, using default one
|
||||
lexer = get_lexer_by_name('text', stripall=strip_whitespace, stripnl=strip_new_lines)
|
||||
|
||||
|
|
@ -1048,7 +1048,7 @@ def image_proxy():
|
|||
del resp
|
||||
del stream
|
||||
except RequestException as e:
|
||||
logger.debug('Exception while closing response', e)
|
||||
logger.debug('Exception while closing response: %s', e)
|
||||
|
||||
try:
|
||||
headers = dict_subset(resp.headers, {'Content-Type', 'Content-Encoding', 'Content-Length', 'Length'})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue