summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-01-24 11:44:18 +0100
committerMartin Fischer <martin@push-f.com>2022-01-27 22:17:16 +0100
commitb767752d0cdefb6c5f41350c15fcdb50f34d2bfa (patch)
tree3017327b81b019aeda7d750dccf552ed1505373a
parent640c404844e3b06482402c53fdce8a2295772d42 (diff)
downloadsearxng-b767752d0cdefb6c5f41350c15fcdb50f34d2bfa.tar.gz
searxng-b767752d0cdefb6c5f41350c15fcdb50f34d2bfa.zip
[pyright:basic] searx.webapp
-rw-r--r--searx/network/__init__.py3
-rwxr-xr-xsearx/webapp.py29
2 files changed, 23 insertions, 9 deletions
diff --git a/searx/network/__init__.py b/searx/network/__init__.py
index 7d02a0014..ced76243d 100644
--- a/searx/network/__init__.py
+++ b/searx/network/__init__.py
@@ -7,6 +7,7 @@ import threading
import concurrent.futures
from types import MethodType
from timeit import default_timer
+from typing import Iterable, Tuple
import httpx
import anyio
@@ -210,7 +211,7 @@ def _close_response_method(self):
continue
-def stream(method, url, **kwargs):
+def stream(method, url, **kwargs) -> Tuple[httpx.Response, Iterable[bytes]]:
"""Replace httpx.stream.
Usage:
diff --git a/searx/webapp.py b/searx/webapp.py
index 7e351bfaa..6bb358d3c 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
+# pyright: basic
"""WebbApp
"""
@@ -33,11 +34,11 @@ from flask import (
Flask,
render_template,
url_for,
- Response,
make_response,
redirect,
send_from_directory,
)
+from flask.wrappers import Response
from flask.ctx import has_request_context
from flask.json import jsonify
@@ -255,7 +256,13 @@ flask_babel.get_translations = _get_translations
@babel.localeselector
def get_locale():
- locale = request.preferences.get_value('locale') if has_request_context() else 'en'
+ locale = 'en'
+
+ if has_request_context():
+ value = request.preferences.get_value('locale')
+ if value:
+ locale = value
+
if locale == 'oc':
request.form['use-translation'] = 'oc'
locale = 'fr_FR'
@@ -310,6 +317,7 @@ def code_highlighter(codelines, language=None):
html_code = ''
tmp_code = ''
last_line = None
+ line_code_start = None
# parse lines
for line, code in codelines:
@@ -351,9 +359,11 @@ def get_current_theme_name(override: str = None) -> str:
if override and (override in themes or override == '__common__'):
return override
theme_name = request.args.get('theme', request.preferences.get_value('theme'))
- if theme_name not in themes:
- theme_name = default_theme
- return theme_name
+
+ if theme_name and theme_name in themes:
+ return theme_name
+
+ return default_theme
def get_result_template(theme_name: str, template_name: str):
@@ -380,7 +390,7 @@ def proxify(url: str):
if not settings.get('result_proxy'):
return url
- url_params = dict(mortyurl=url.encode())
+ url_params = dict(mortyurl=url)
if settings['result_proxy'].get('key'):
url_params['mortyhash'] = hmac.new(settings['result_proxy']['key'], url.encode(), hashlib.sha256).hexdigest()
@@ -1137,10 +1147,13 @@ def image_proxy():
except httpx.HTTPError:
logger.exception('HTTP error on closing')
+ assert resp is not None
+
def close_stream():
nonlocal resp, stream
try:
- resp.close()
+ if resp:
+ resp.close()
del resp
del stream
except httpx.HTTPError as e:
@@ -1207,7 +1220,7 @@ def stats():
reverse, key_name, default_value = STATS_SORT_PARAMETERS[sort_order]
def get_key(engine_stat):
- reliability = engine_reliabilities.get(engine_stat['name']).get('reliablity', 0)
+ reliability = engine_reliabilities.get(engine_stat['name'], {}).get('reliablity', 0)
reliability_order = 0 if reliability else 1
if key_name == 'reliability':
key = reliability