diff options
author | Alexandre Flament <alex@al-f.net> | 2021-09-13 19:37:51 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2021-10-06 19:18:19 +0200 |
commit | 2b4fef71186be1e4a9ce160ddfa6707e2f138a3e (patch) | |
tree | f1e3037e04a533849bcd1834e35b2b4af93f87da /searx/plugins/ahmia_filter.py | |
parent | adeb084cf4ffc59f1e49b47d049e7541be6dd5dd (diff) | |
download | searxng-2b4fef71186be1e4a9ce160ddfa6707e2f138a3e.tar.gz searxng-2b4fef71186be1e4a9ce160ddfa6707e2f138a3e.zip |
plugins: refactor initialization
add a new function "init" call when the app starts.
The function can:
* return False to disable the plugin.
* modify the Flask app.
Diffstat (limited to 'searx/plugins/ahmia_filter.py')
-rw-r--r-- | searx/plugins/ahmia_filter.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/searx/plugins/ahmia_filter.py b/searx/plugins/ahmia_filter.py index 70f216ee1..326da9ca1 100644 --- a/searx/plugins/ahmia_filter.py +++ b/searx/plugins/ahmia_filter.py @@ -13,15 +13,17 @@ preference_section = 'onions' ahmia_blacklist = None -def get_ahmia_blacklist(): - global ahmia_blacklist - if not ahmia_blacklist: - ahmia_blacklist = ahmia_blacklist_loader() - return ahmia_blacklist - - def on_result(request, search, result): if not result.get('is_onion') or not result.get('parsed_url'): return True result_hash = md5(result['parsed_url'].hostname.encode()).hexdigest() - return result_hash not in get_ahmia_blacklist() + return result_hash not in ahmia_blacklist + + +def init(app, settings): + global ahmia_blacklist # pylint: disable=global-statement + if not settings['outgoing']['using_tor_proxy']: + # disable the plugin + return False + ahmia_blacklist = ahmia_blacklist_loader() + return True |