summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2021-05-26 10:16:34 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2021-05-26 21:17:19 +0200
commitae2536220546852598cfa4d6ee1e03dee4fef5bd (patch)
tree2b973ded99ff0fc9df8cb516f4df7c8212b74c5c /searx/webapp.py
parent85364edaf077de42b24cc5e16507181208780c5e (diff)
[pylint] webapp.py - fix all wrong-import-order messages from pylint
pylint message: wrong-import-order Respect PEP8 import order (standard imports first, then third-party libraries, then local imports). pylint message: wrong-import-position Do not mix code & imports BTW: - only one import per line - replace licence text by SPDX tag Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-xsearx/webapp.py163
1 files changed, 101 insertions, 62 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index ae98d1964..be4975a04 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -1,99 +1,138 @@
#!/usr/bin/env python
-
-'''
-searx is free software: you can redistribute it and/or modify
-it under the terms of the GNU Affero General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-searx is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU Affero General Public License for more details.
-
-You should have received a copy of the GNU Affero General Public License
-along with searx. If not, see < http://www.gnu.org/licenses/ >.
-
-(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
-'''
-
-import sys
-if sys.version_info[0] < 3:
- print('\033[1;31m Python2 is no longer supported\033[0m')
- exit(1)
-
-# set Unix thread name
-try:
- import setproctitle
-except ImportError:
- pass
-else:
- import threading
- old_thread_init = threading.Thread.__init__
-
- def new_thread_init(self, *args, **kwargs):
- old_thread_init(self, *args, **kwargs)
- setproctitle.setthreadtitle(self._name)
- threading.Thread.__init__ = new_thread_init
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+# pylint: disable=missing-function-docstring
import hashlib
import hmac
import json
import os
-
-import httpx
-
-from searx import logger
-logger = logger.getChild('webapp')
+import sys
from datetime import datetime, timedelta
from timeit import default_timer
from html import escape
from io import StringIO
+
import urllib
-from urllib.parse import urlencode, urlparse
+from urllib.parse import (
+ urlencode,
+ urlparse,
+)
+
+import httpx
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter # pylint: disable=no-name-in-module
from werkzeug.middleware.proxy_fix import ProxyFix
+from werkzeug.serving import WSGIRequestHandler
+
from flask import (
- Flask, request, render_template, url_for, Response, make_response,
- redirect, send_from_directory
+ Flask,
+ request,
+ render_template,
+ url_for,
+ Response,
+ make_response,
+ redirect,
+ send_from_directory,
)
-from babel.support import Translations
-import flask_babel
-from flask_babel import Babel, gettext, format_date, format_decimal
from flask.ctx import has_request_context
from flask.json import jsonify
+
+from babel.support import Translations
+import flask_babel
+from flask_babel import (
+ Babel,
+ gettext,
+ format_date,
+ format_decimal,
+)
+
+from searx import logger
from searx import brand, static_path
-from searx import settings, searx_dir, searx_debug
+from searx import (
+ settings,
+ searx_dir,
+ searx_debug,
+)
from searx.exceptions import SearxParameterException
-from searx.engines import categories, engines, engine_shortcuts
+from searx.engines import (
+ categories,
+ engines,
+ engine_shortcuts,
+)
from searx.webutils import (
- UnicodeWriter, highlight_content, get_resources_directory,
- get_static_files, get_result_templates, get_themes,
- prettify_url, new_hmac, is_flask_run_cmdline
+ UnicodeWriter,
+ highlight_content,
+ get_resources_directory,
+ get_static_files,
+ get_result_templates,
+ get_themes,
+ prettify_url,
+ new_hmac,
+ is_flask_run_cmdline,
+)
+from searx.webadapter import (
+ get_search_query_from_webapp,
+ get_selected_categories,
+)
+from searx.utils import (
+ html_to_text,
+ gen_useragent,
+ dict_subset,
+ match_language,
)
-from searx.webadapter import get_search_query_from_webapp, get_selected_categories
-from searx.utils import html_to_text, gen_useragent, dict_subset, match_language
from searx.version import VERSION_STRING
-from searx.languages import language_codes as languages
-from searx.search import SearchWithPlugins, initialize as search_initialize
-from searx.search.checker import get_result as checker_get_result
from searx.query import RawTextQuery
-from searx.autocomplete import search_autocomplete, backends as autocomplete_backends
from searx.plugins import plugins
from searx.plugins.oa_doi_rewrite import get_doi_resolver
-from searx.preferences import Preferences, ValidationException, LANGUAGE_CODES
+from searx.preferences import (
+ Preferences,
+ ValidationException,
+ LANGUAGE_CODES,
+)
from searx.answerers import answerers
-from searx.network import stream as http_stream
from searx.answerers import ask
-from searx.metrics import get_engines_stats, get_engine_errors, get_reliabilities, histogram, counter
+from searx.metrics import (
+ get_engines_stats,
+ get_engine_errors,
+ get_reliabilities,
+ histogram,
+ counter,
+)
+
+# renaming names from searx imports ...
+
+from searx.autocomplete import search_autocomplete, backends as autocomplete_backends
+from searx.languages import language_codes as languages
+from searx.search import SearchWithPlugins, initialize as search_initialize
+from searx.network import stream as http_stream
+from searx.search.checker import get_result as checker_get_result
+
+# set Unix thread name
+try:
+ import setproctitle
+except ImportError:
+ pass
+else:
+ import threading
+ old_thread_init = threading.Thread.__init__
+
+ def new_thread_init(self, *args, **kwargs):
+ old_thread_init(self, *args, **kwargs)
+ setproctitle.setthreadtitle(self._name)
+ threading.Thread.__init__ = new_thread_init
+
+if sys.version_info[0] < 3:
+ print('\033[1;31m Python2 is no longer supported\033[0m')
+ exit(1)
+
+logger = logger.getChild('webapp')
# serve pages with HTTP/1.1
-from werkzeug.serving import WSGIRequestHandler
WSGIRequestHandler.protocol_version = "HTTP/{}".format(settings['server'].get('http_protocol_version', '1.0'))
# check secret_key