From e8706fb738da9feb21e596f403dddb40e69c8a7b Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 25 Jun 2023 12:37:31 +0200 Subject: [fix] engine & network issues / documentation and type annotations This patch fixes some quirks and issues related to the engines and the network. Each engine has its own network and this network was broken for the following engines[1]: - archlinux - bing - dailymotion - duckduckgo - google - peertube - startpage - wikipedia Since the files have been touched anyway, the type annotaions of the engine modules has also been completed so that error messages from the type checker are no longer reported. Related and (partial) fixed issue: - [1] https://github.com/searxng/searxng/issues/762#issuecomment-1605323861 - [2] https://github.com/searxng/searxng/issues/2513 - [3] https://github.com/searxng/searxng/issues/2515 Signed-off-by: Markus Heiser --- searx/engines/bing.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'searx/engines/bing.py') diff --git a/searx/engines/bing.py b/searx/engines/bing.py index 81a0cf6a5..3cd707870 100644 --- a/searx/engines/bing.py +++ b/searx/engines/bing.py @@ -38,7 +38,6 @@ import babel import babel.languages from searx.utils import eval_xpath, extract_text, eval_xpath_list, eval_xpath_getindex -from searx import network from searx.locales import language_tag, region_tag from searx.enginelib.traits import EngineTraits @@ -180,6 +179,10 @@ def request(query, params): def response(resp): + # pylint: disable=too-many-locals,import-outside-toplevel + + from searx.network import Request, multi_requests # see https://github.com/searxng/searxng/issues/762 + results = [] result_len = 0 @@ -231,9 +234,9 @@ def response(resp): # resolve all Bing redirections in parallel request_list = [ - network.Request.get(u, allow_redirects=False, headers=resp.search_params['headers']) for u in url_to_resolve + Request.get(u, allow_redirects=False, headers=resp.search_params['headers']) for u in url_to_resolve ] - response_list = network.multi_requests(request_list) + response_list = multi_requests(request_list) for i, redirect_response in enumerate(response_list): if not isinstance(redirect_response, Exception): results[url_to_resolve_index[i]]['url'] = redirect_response.headers['location'] @@ -272,16 +275,19 @@ def fetch_traits(engine_traits: EngineTraits): def _fetch_traits(engine_traits: EngineTraits, url: str, xpath_language_codes: str, xpath_market_codes: str): + # pylint: disable=too-many-locals,import-outside-toplevel + + from searx.network import get # see https://github.com/searxng/searxng/issues/762 # insert alias to map from a language (zh) to a language + script (zh_Hans) engine_traits.languages['zh'] = 'zh-hans' - resp = network.get(url) + resp = get(url) - if not resp.ok: + if not resp.ok: # type: ignore print("ERROR: response from peertube is not OK.") - dom = html.fromstring(resp.text) + dom = html.fromstring(resp.text) # type: ignore map_lang = {'jp': 'ja'} for td in eval_xpath(dom, xpath_language_codes): -- cgit v1.2.3