3"""Implement request processors used by engine-types.
11 'OnlineDictionaryProcessor',
12 'OnlineCurrencyProcessor',
13 'OnlineUrlSearchProcessor',
18from typing
import Dict
20from searx
import logger
21from searx
import engines
23from .online
import OnlineProcessor
24from .offline
import OfflineProcessor
25from .online_dictionary
import OnlineDictionaryProcessor
26from .online_currency
import OnlineCurrencyProcessor
27from .online_url_search
import OnlineUrlSearchProcessor
28from .abstract
import EngineProcessor
30logger = logger.getChild(
'search.processors')
31PROCESSORS: Dict[str, EngineProcessor] = {}
32"""Cache request processors, stored by *engine-name* (:py:func:`initialize`)
39 """Return processor class according to the ``engine_type``"""
43 OnlineDictionaryProcessor,
44 OnlineCurrencyProcessor,
45 OnlineUrlSearchProcessor,
47 if c.engine_type == engine_type:
53 """Return processor instance that fits to ``engine.engine.type``)"""
54 engine_type = getattr(engine,
'engine_type',
'online')
57 return processor_class(engine, engine_name)
62 """Initialize one processor
64 Call the init function of the engine
66 if processor.has_initialize_function:
67 t = threading.Thread(target=processor.initialize, daemon=
True)
72 """Initialize all engines and store a processor for each engine in :py:obj:`PROCESSORS`."""
73 for engine_data
in engine_list:
74 engine_name = engine_data[
'name']
75 engine = engines.engines.get(engine_name)
80 engine.logger.error(
'Error get processor for engine %s', engine_name)
82 PROCESSORS[engine_name] = processor
get_processor(engine, engine_name)
get_processor_class(engine_type)
initialize_processor(processor)