summaryrefslogtreecommitdiff
path: root/searx/engines/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/engines/__init__.py')
-rw-r--r--searx/engines/__init__.py43
1 files changed, 36 insertions, 7 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index a3dd7a95a..b762c0dd9 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -13,6 +13,7 @@ usage::
import sys
import copy
+from typing import Dict, List, Optional
from os.path import realpath, dirname
from babel.localedata import locale_identifiers
@@ -43,11 +44,34 @@ ENGINE_DEFAULT_ARGS = {
"enable_http": False,
"display_error_messages": True,
"tokens": [],
+ "about": {},
}
-"""Defaults for the namespace of an engine module, see :py:func:`load_engine`"""
+# set automatically when an engine does not have any tab category
+OTHER_CATEGORY = 'other'
+
+
+class Engine: # pylint: disable=too-few-public-methods
+ """This class is currently never initialized and only used for type hinting."""
+
+ name: str
+ engine: str
+ shortcut: str
+ categories: List[str]
+ supported_languages: List[str]
+ about: dict
+ inactive: bool
+ disabled: bool
+ language_support: bool
+ paging: bool
+ safesearch: bool
+ time_range_support: bool
+ timeout: float
+
+
+# Defaults for the namespace of an engine module, see :py:func:`load_engine`
categories = {'general': []}
-engines = {}
+engines: Dict[str, Engine] = {}
engine_shortcuts = {}
"""Simple map of registered *shortcuts* to name of the engine (or ``None``).
@@ -58,7 +82,7 @@ engine_shortcuts = {}
"""
-def load_engine(engine_data):
+def load_engine(engine_data: dict) -> Optional[Engine]:
"""Load engine from ``engine_data``.
:param dict engine_data: Attributes from YAML ``settings:engines/<engine>``
@@ -113,6 +137,9 @@ def load_engine(engine_data):
set_loggers(engine, engine_name)
+ if not any(cat in settings['categories_as_tabs'] for cat in engine.categories):
+ engine.categories.append(OTHER_CATEGORY)
+
return engine
@@ -131,13 +158,15 @@ def set_loggers(engine, engine_name):
module.logger = logger.getChild(module_engine_name)
-def update_engine_attributes(engine, engine_data):
+def update_engine_attributes(engine: Engine, engine_data):
# set engine attributes from engine_data
for param_name, param_value in engine_data.items():
if param_name == 'categories':
if isinstance(param_value, str):
param_value = list(map(str.strip, param_value.split(',')))
engine.categories = param_value
+ elif hasattr(engine, 'about') and param_name == 'about':
+ engine.about = {**engine.about, **engine_data['about']}
else:
setattr(engine, param_name, param_value)
@@ -147,7 +176,7 @@ def update_engine_attributes(engine, engine_data):
setattr(engine, arg_name, copy.deepcopy(arg_value))
-def set_language_attributes(engine):
+def set_language_attributes(engine: Engine):
# assign supported languages from json file
if engine.name in ENGINES_LANGUAGES:
engine.supported_languages = ENGINES_LANGUAGES[engine.name]
@@ -220,7 +249,7 @@ def is_missing_required_attributes(engine):
return missing
-def is_engine_active(engine):
+def is_engine_active(engine: Engine):
# check if engine is inactive
if engine.inactive is True:
return False
@@ -232,7 +261,7 @@ def is_engine_active(engine):
return True
-def register_engine(engine):
+def register_engine(engine: Engine):
if engine.name in engines:
logger.error('Engine config error: ambigious name: {0}'.format(engine.name))
sys.exit(1)