summaryrefslogtreecommitdiff
path: root/searx/engines/google.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2023-06-25 12:37:31 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2023-06-25 13:58:26 +0200
commite8706fb738da9feb21e596f403dddb40e69c8a7b (patch)
tree1ddf3dbd2860d65de879d9feecf7df01a7727680 /searx/engines/google.py
parent2e4a435134e0f677fbe24853dd81453a54770674 (diff)
[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 <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/engines/google.py')
-rw-r--r--searx/engines/google.py18
1 files changed, 9 insertions, 9 deletions
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