[enh] rename Engine class to ConfiguredEngine

This commit is contained in:
Martin Fischer 2022-01-28 09:24:56 +01:00
parent 24b784a360
commit 685d876d2e
3 changed files with 16 additions and 14 deletions

View file

@ -51,7 +51,7 @@ ENGINE_DEFAULT_ARGS = {
OTHER_CATEGORY = 'other'
class Engine: # pylint: disable=too-few-public-methods
class ConfiguredEngine: # pylint: disable=too-few-public-methods
"""This class is currently never initialized and only used for type hinting."""
name: str
@ -72,7 +72,7 @@ class Engine: # pylint: disable=too-few-public-methods
# Defaults for the namespace of an engine module, see :py:func:`load_engine`
categories = {'general': []}
engines: Dict[str, Engine] = {}
engines: Dict[str, ConfiguredEngine] = {}
engine_shortcuts = {}
"""Simple map of registered *shortcuts* to name of the engine (or ``None``).
@ -83,7 +83,7 @@ engine_shortcuts = {}
"""
def load_engine(engine_data: dict) -> Optional[Engine]:
def load_engine(engine_data: dict) -> Optional[ConfiguredEngine]:
"""Load engine from ``engine_data``.
:param dict engine_data: Attributes from YAML ``settings:engines/<engine>``
@ -159,7 +159,7 @@ def set_loggers(engine, engine_name):
module.logger = logger.getChild(module_engine_name)
def update_engine_attributes(engine: Engine, engine_data):
def update_engine_attributes(engine: ConfiguredEngine, engine_data):
# set engine attributes from engine_data
for param_name, param_value in engine_data.items():
if param_name == 'categories':
@ -177,7 +177,7 @@ def update_engine_attributes(engine: Engine, engine_data):
setattr(engine, arg_name, copy.deepcopy(arg_value))
def set_language_attributes(engine: Engine):
def set_language_attributes(engine: ConfiguredEngine):
# assign supported languages from json file
if engine.name in ENGINES_LANGUAGES:
engine.supported_languages = ENGINES_LANGUAGES[engine.name]
@ -231,7 +231,7 @@ def set_language_attributes(engine: Engine):
)
def update_attributes_for_tor(engine: Engine) -> bool:
def update_attributes_for_tor(engine: ConfiguredEngine) -> bool:
if using_tor_proxy(engine) and hasattr(engine, 'onion_url'):
engine.search_url = engine.onion_url + getattr(engine, 'search_path', '')
engine.timeout += settings['outgoing'].get('extra_proxy_timeout', 0)
@ -250,12 +250,12 @@ def is_missing_required_attributes(engine):
return missing
def using_tor_proxy(engine: Engine):
def using_tor_proxy(engine: ConfiguredEngine):
"""Return True if the engine configuration declares to use Tor."""
return settings['outgoing'].get('using_tor_proxy') or getattr(engine, 'using_tor_proxy', False)
def is_engine_active(engine: Engine):
def is_engine_active(engine: ConfiguredEngine):
# check if engine is inactive
if engine.inactive is True:
return False
@ -267,7 +267,7 @@ def is_engine_active(engine: Engine):
return True
def register_engine(engine: Engine):
def register_engine(engine: ConfiguredEngine):
if engine.name in engines:
logger.error('Engine config error: ambigious name: {0}'.format(engine.name))
sys.exit(1)

View file

@ -13,7 +13,7 @@ from typing import Iterable, Dict, List
import flask
from searx import settings, autocomplete
from searx.engines import Engine
from searx.engines import ConfiguredEngine
from searx.plugins import Plugin
from searx.locales import LOCALE_NAMES
from searx.webutils import VALID_LANGUAGE_CODE
@ -257,7 +257,7 @@ class BooleanChoices:
class EnginesSetting(BooleanChoices):
"""Engine settings"""
def __init__(self, default_value, engines: Iterable[Engine]):
def __init__(self, default_value, engines: Iterable[ConfiguredEngine]):
choices = {}
for engine in engines:
for category in engine.categories:
@ -292,7 +292,9 @@ class PluginsSetting(BooleanChoices):
class Preferences:
"""Validates and saves preferences to cookies"""
def __init__(self, themes: List[str], categories: List[str], engines: Dict[str, Engine], plugins: Iterable[Plugin]):
def __init__(
self, themes: List[str], categories: List[str], engines: Dict[str, ConfiguredEngine], plugins: Iterable[Plugin]
):
super().__init__()
self.key_value_settings: Dict[str, Setting] = {

View file

@ -12,7 +12,7 @@ from io import StringIO
from codecs import getincrementalencoder
from searx import logger, settings
from searx.engines import Engine, OTHER_CATEGORY
from searx.engines import ConfiguredEngine, OTHER_CATEGORY
VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(-[a-zA-Z]{2})?$')
@ -142,7 +142,7 @@ def is_flask_run_cmdline():
DEFAULT_GROUP_NAME = 'others'
def group_engines_in_tab(engines: Iterable[Engine]) -> List[Tuple[str, Iterable[Engine]]]:
def group_engines_in_tab(engines: Iterable[ConfiguredEngine]) -> List[Tuple[str, Iterable[ConfiguredEngine]]]:
"""Groups an Iterable of engines by their first non tab category"""
def get_group(eng):