From c19bffde4df5c879d11ec7ea97b4fa30a07db992 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 28 May 2024 17:56:54 +0200 Subject: [PATCH] [fix] issues reported by pylint-3.2.2 Signed-off-by: Markus Heiser --- searx/engines/base.py | 4 +++- searx/infopage/__init__.py | 12 ++++++++++++ searx/webapp.py | 9 ++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/searx/engines/base.py b/searx/engines/base.py index 5cfcc9250..f81906482 100755 --- a/searx/engines/base.py +++ b/searx/engines/base.py @@ -80,8 +80,10 @@ def response(resp): for entry in search_results.xpath('./result/doc'): content = "No description available" - + url = "" + title = "" date = datetime.now() # needed in case no dcdate is available for an item + for item in entry: if item.attrib["name"] == "dcdate": date = item.text diff --git a/searx/infopage/__init__.py b/searx/infopage/__init__.py index 3f9426beb..1d556d6d2 100644 --- a/searx/infopage/__init__.py +++ b/searx/infopage/__init__.py @@ -17,6 +17,8 @@ Usage in a Flask app route: """ +from __future__ import annotations + __all__ = ['InfoPage', 'InfoPageSet'] import os @@ -37,6 +39,16 @@ from ..locales import LOCALE_NAMES logger = logging.getLogger('searx.infopage') _INFO_FOLDER = os.path.abspath(os.path.dirname(__file__)) +INFO_PAGES: 'InfoPageSet' + + +def __getattr__(name): + if name == 'INFO_PAGES': + global INFO_PAGES # pylint: disable=global-statement + INFO_PAGES = InfoPageSet() + return INFO_PAGES + + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") class InfoPage: diff --git a/searx/webapp.py b/searx/webapp.py index 0901af8ea..b2b6a0bb5 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -276,8 +276,8 @@ def custom_url_for(endpoint: str, **values): suffix = "?" + file_hash if endpoint == 'info' and 'locale' not in values: locale = request.preferences.get_value('locale') - if _INFO_PAGES.get_page(values['pagename'], locale) is None: - locale = _INFO_PAGES.locale_default + if infopage.INFO_PAGES.get_page(values['pagename'], locale) is None: + locale = infopage.INFO_PAGES.locale_default values['locale'] = locale return url_for(endpoint, **values) + suffix @@ -804,14 +804,14 @@ def about(): @app.route('/info//', methods=['GET']) def info(pagename, locale): """Render page of online user documentation""" - page = _INFO_PAGES.get_page(pagename, locale) + page = infopage.INFO_PAGES.get_page(pagename, locale) if page is None: flask.abort(404) user_locale = request.preferences.get_value('locale') return render( 'info.html', - all_pages=_INFO_PAGES.iter_pages(user_locale, fallback_to_default=True), + all_pages=infopage.INFO_PAGES.iter_pages(user_locale, fallback_to_default=True), active_page=page, active_pagename=pagename, ) @@ -1333,7 +1333,6 @@ werkzeug_reloader = flask_run_development or (searx_debug and __name__ == "__mai # initialize the engines except on the first run of the werkzeug server. if not werkzeug_reloader or (werkzeug_reloader and os.environ.get("WERKZEUG_RUN_MAIN") == "true"): locales_initialize() - _INFO_PAGES = infopage.InfoPageSet() redis_initialize() plugin_initialize(app) search_initialize(enable_checker=True, check_network=True, enable_metrics=settings['general']['enable_metrics'])