diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2025-08-22 17:17:51 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-09-03 13:37:36 +0200 |
| commit | 57b9673efb1b4fd18a3ac15e26da642201e2cd33 (patch) | |
| tree | 79d3ecd365a1669a1109aa7e5dd3636bc1041d96 /searx/network/raise_for_httperror.py | |
| parent | 09500459feffa414dc7a0601bdb164464a8b0454 (diff) | |
[mod] addition of various type hints / tbc
- pyright configuration [1]_
- stub files: types-lxml [2]_
- addition of various type hints
- enable use of new type system features on older Python versions [3]_
- ``.tool-versions`` - set python to lowest version we support (3.10.18) [4]_:
Older versions typically lack some typing features found in newer Python
versions. Therefore, for local type checking (before commit), it is necessary
to use the older Python interpreter.
.. [1] https://docs.basedpyright.com/v1.20.0/configuration/config-files/
.. [2] https://pypi.org/project/types-lxml/
.. [3] https://typing-extensions.readthedocs.io/en/latest/#
.. [4] https://mise.jdx.dev/configuration.html#tool-versions
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Format: reST
Diffstat (limited to 'searx/network/raise_for_httperror.py')
| -rw-r--r-- | searx/network/raise_for_httperror.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/searx/network/raise_for_httperror.py b/searx/network/raise_for_httperror.py index abee2c78b..1a9e3d0d2 100644 --- a/searx/network/raise_for_httperror.py +++ b/searx/network/raise_for_httperror.py @@ -3,6 +3,7 @@ """ +import typing as t from searx.exceptions import ( SearxEngineCaptchaException, SearxEngineTooManyRequestsException, @@ -10,8 +11,11 @@ from searx.exceptions import ( ) from searx import get_setting +if t.TYPE_CHECKING: + from searx.extended_types import SXNG_Response -def is_cloudflare_challenge(resp): + +def is_cloudflare_challenge(resp: "SXNG_Response"): if resp.status_code in [429, 503]: if ('__cf_chl_jschl_tk__=' in resp.text) or ( '/cdn-cgi/challenge-platform/' in resp.text @@ -24,11 +28,11 @@ def is_cloudflare_challenge(resp): return False -def is_cloudflare_firewall(resp): +def is_cloudflare_firewall(resp: "SXNG_Response"): return resp.status_code == 403 and '<span class="cf-error-code">1020</span>' in resp.text -def raise_for_cloudflare_captcha(resp): +def raise_for_cloudflare_captcha(resp: "SXNG_Response"): if resp.headers.get('Server', '').startswith('cloudflare'): if is_cloudflare_challenge(resp): # https://support.cloudflare.com/hc/en-us/articles/200170136-Understanding-Cloudflare-Challenge-Passage-Captcha- @@ -44,19 +48,19 @@ def raise_for_cloudflare_captcha(resp): ) -def raise_for_recaptcha(resp): +def raise_for_recaptcha(resp: "SXNG_Response"): if resp.status_code == 503 and '"https://www.google.com/recaptcha/' in resp.text: raise SearxEngineCaptchaException( message='ReCAPTCHA', suspended_time=get_setting('search.suspended_times.recaptcha_SearxEngineCaptcha') ) -def raise_for_captcha(resp): +def raise_for_captcha(resp: "SXNG_Response"): raise_for_cloudflare_captcha(resp) raise_for_recaptcha(resp) -def raise_for_httperror(resp): +def raise_for_httperror(resp: "SXNG_Response") -> None: """Raise exception for an HTTP response is an error. Args: |