diff options
author | Alexandre Flament <alex@al-f.net> | 2020-10-05 12:50:08 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2020-10-06 09:42:11 +0200 |
commit | 15013e64d8a1cb21a9edab429b153ab83b5f1db5 (patch) | |
tree | 29a6f6916225f230659fb95af350579ec0b2e0c4 /searx | |
parent | 584760cf5419051bd3f37e733147e048356f7ffc (diff) | |
download | searxng-15013e64d8a1cb21a9edab429b153ab83b5f1db5.tar.gz searxng-15013e64d8a1cb21a9edab429b153ab83b5f1db5.zip |
[fix] drop Python 2: use importlib instead of imp.load_source
imp.load_source is not documented in Python 3
see documentation : https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
partial fix of https://github.com/searx/searx/issues/1674
Diffstat (limited to 'searx')
-rw-r--r-- | searx/utils.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/searx/utils.py b/searx/utils.py index 0be3c5b00..db17feba9 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -3,8 +3,8 @@ import os import sys import re import json +import importlib -from imp import load_source from numbers import Number from os.path import splitext, join from io import open @@ -445,8 +445,11 @@ def load_module(filename, module_dir): if modname in sys.modules: del sys.modules[modname] filepath = join(module_dir, filename) - module = load_source(modname, filepath) - module.name = modname + # and https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly + spec = importlib.util.spec_from_file_location(modname, filepath) + module = importlib.util.module_from_spec(spec) + sys.modules[modname] = module + spec.loader.exec_module(module) return module |