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/google.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'searx/engines/google.py') diff --git a/searx/engines/google.py b/searx/engines/google.py index 708068f3a..6aaac2f22 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -23,7 +23,7 @@ import babel.languages from searx.utils import extract_text, eval_xpath, eval_xpath_list, eval_xpath_getindex from searx.locales import language_tag, region_tag, get_offical_locales -from searx import network +from searx.network import get # see https://github.com/searxng/searxng/issues/762 from searx.exceptions import SearxEngineCaptchaException from searx.enginelib.traits import EngineTraits @@ -419,11 +419,11 @@ def fetch_traits(engine_traits: EngineTraits, add_domains: bool = True): engine_traits.custom['supported_domains'] = {} - resp = network.get('https://www.google.com/preferences') - if not resp.ok: + resp = get('https://www.google.com/preferences') + if not resp.ok: # type: ignore raise RuntimeError("Response from Google's preferences is not OK.") - dom = html.fromstring(resp.text) + dom = html.fromstring(resp.text) # type: ignore # supported language codes @@ -474,18 +474,18 @@ def fetch_traits(engine_traits: EngineTraits, add_domains: bool = True): # supported domains if add_domains: - resp = network.get('https://www.google.com/supported_domains') - if not resp.ok: + resp = get('https://www.google.com/supported_domains') + if not resp.ok: # type: ignore raise RuntimeError("Response from https://www.google.com/supported_domains is not OK.") - for domain in resp.text.split(): + for domain in resp.text.split(): # type: ignore domain = domain.strip() if not domain or domain in [ '.google.com', ]: continue region = domain.split('.')[-1].upper() - engine_traits.custom['supported_domains'][region] = 'www' + domain + engine_traits.custom['supported_domains'][region] = 'www' + domain # type: ignore if region == 'HK': # There is no google.cn, we use .com.hk for zh-CN - engine_traits.custom['supported_domains']['CN'] = 'www' + domain + engine_traits.custom['supported_domains']['CN'] = 'www' + domain # type: ignore -- cgit v1.2.3