SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[typing] add results.UnresponsiveEngine
Martin Fischer193b0efd12a7
diff --git a/searx/results.py b/searx/results.pyindex 5e1b46ed5..1ac6a5ab5 100644--- a/searx/results.py+++ b/searx/results.py@@ -2,7 +2,7 @@ import refrom collections import defaultdictfrom operator import itemgetterfrom threading import RLock-from typing import List, NamedTuple+from typing import List, NamedTuple, Setfrom urllib.parse import urlparse, unquotefrom searx import logger@@ -145,6 +145,12 @@ class Timing(NamedTuple):load: float+class UnresponsiveEngine(NamedTuple):+ engine: str+ error_type: str+ suspended: bool++class ResultContainer:"""docstring for ResultContainer"""@@ -176,7 +182,7 @@ class ResultContainer:self.engine_data = defaultdict(dict)self._closed = Falseself.paging = False- self.unresponsive_engines = set()+ self.unresponsive_engines: Set[UnresponsiveEngine] = set()self.timings: List[Timing] = []self.redirect_url = Noneself.on_result = lambda _: True@@ -409,9 +415,9 @@ class ResultContainer:return 0return resultnum_sum / len(self._number_of_results)- def add_unresponsive_engine(self, engine_name, error_type, suspended=False):+ def add_unresponsive_engine(self, engine_name: str, error_type: str, suspended: bool = False):if engines[engine_name].display_error_messages:- self.unresponsive_engines.add((engine_name, error_type, suspended))+ self.unresponsive_engines.add(UnresponsiveEngine(engine_name, error_type, suspended))def add_timing(self, engine_name: str, engine_time: float, page_load_time: float):self.timings.append(Timing(engine_name, total=engine_time, load=page_load_time))diff --git a/searx/webapp.py b/searx/webapp.pyindex bb6e74b25..196bfb0d2 100755--- a/searx/webapp.py+++ b/searx/webapp.py@@ -15,7 +15,7 @@ from timeit import default_timerfrom html import escapefrom io import StringIOimport typing-from typing import List, Dict+from typing import List, Dict, Iterableimport urllibfrom urllib.parse import urlencode@@ -56,7 +56,7 @@ from searx import (searx_debug,)from searx.data import ENGINE_DESCRIPTIONS-from searx.results import Timing+from searx.results import Timing, UnresponsiveEnginefrom searx.settings_defaults import OUTPUT_FORMATSfrom searx.settings_loader import get_default_settings_pathfrom searx.exceptions import SearxParameterException@@ -844,21 +844,21 @@ def search():)-def __get_translated_errors(unresponsive_engines):+def __get_translated_errors(unresponsive_engines: Iterable[UnresponsiveEngine]):translated_errors = []# make a copy unresponsive_engines to avoid "RuntimeError: Set changed size# during iteration" it happens when an engine modifies the ResultContainer# after the search_multiple_requests method has stopped waiting- for unresponsive_engine in list(unresponsive_engines):- error_user_text = exception_classname_to_text.get(unresponsive_engine[1])+ for unresponsive_engine in unresponsive_engines:+ error_user_text = exception_classname_to_text.get(unresponsive_engine.error_type)if not error_user_text:error_user_text = exception_classname_to_text[None]error_msg = gettext(error_user_text)- if unresponsive_engine[2]:+ if unresponsive_engine.suspended:error_msg = gettext('Suspended') + ': ' + error_msg- translated_errors.append((unresponsive_engine[0], error_msg))+ translated_errors.append((unresponsive_engine.engine, error_msg))return sorted(translated_errors, key=lambda e: e[0])