2"""Implement request processors used by engine-types."""
8 'OnlineDictionaryProcessor',
9 'OnlineCurrencyProcessor',
10 'OnlineUrlSearchProcessor',
18from searx
import logger
19from searx
import engines
21from .online
import OnlineProcessor
22from .offline
import OfflineProcessor
23from .online_dictionary
import OnlineDictionaryProcessor
24from .online_currency
import OnlineCurrencyProcessor
25from .online_url_search
import OnlineUrlSearchProcessor
26from .abstract
import EngineProcessor
31logger = logger.getChild(
'search.processors')
32PROCESSORS: dict[str, EngineProcessor] = {}
33"""Cache request processors, stored by *engine-name* (:py:func:`initialize`)
40 """Return processor class according to the ``engine_type``"""
44 OnlineDictionaryProcessor,
45 OnlineCurrencyProcessor,
46 OnlineUrlSearchProcessor,
48 if c.engine_type == engine_type:
53def get_processor(engine:
"Engine | ModuleType", engine_name: str) -> EngineProcessor |
None:
54 """Return processor instance that fits to ``engine.engine.type``"""
55 engine_type = getattr(engine,
'engine_type',
'online')
57 if processor_class
is not None:
58 return processor_class(engine, engine_name)
63 """Initialize one processor
65 Call the init function of the engine
67 if processor.has_initialize_function:
68 _t = threading.Thread(target=processor.initialize, daemon=
True)
73 """Initialize all engines and store a processor for each engine in
74 :py:obj:`PROCESSORS`."""
75 for engine_data
in engine_list:
76 engine_name: str = engine_data[
'name']
77 engine = engines.engines.get(engine_name)
81 engine.logger.error(
'Error get processor for engine %s', engine_name)
84 PROCESSORS[engine_name] = processor
EngineProcessor|None get_processor("Engine | ModuleType" engine, str engine_name)
type[EngineProcessor]|None get_processor_class(str engine_type)
initialize(list[dict[str, t.Any]] engine_list)
initialize_processor(EngineProcessor processor)