diff options
author | Martin Fischer <martin@push-f.com> | 2022-01-24 11:44:18 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-01-27 22:17:16 +0100 |
commit | b767752d0cdefb6c5f41350c15fcdb50f34d2bfa (patch) | |
tree | 3017327b81b019aeda7d750dccf552ed1505373a /searx/webapp.py | |
parent | 640c404844e3b06482402c53fdce8a2295772d42 (diff) | |
download | searxng-b767752d0cdefb6c5f41350c15fcdb50f34d2bfa.tar.gz searxng-b767752d0cdefb6c5f41350c15fcdb50f34d2bfa.zip |
[pyright:basic] searx.webapp
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-x | searx/webapp.py | 29 |
1 files changed, 21 insertions, 8 deletions
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 |