diff --git a/webapp/graphite/util.py b/webapp/graphite/util.py index 1b5889026..bb46fa16c 100644 --- a/webapp/graphite/util.py +++ b/webapp/graphite/util.py @@ -12,7 +12,7 @@ See the License for the specific language governing permissions and limitations under the License.""" -import imp +import importlib import io import json as _json import socket @@ -145,12 +145,11 @@ def is_unsafe_str(s): def load_module(module_path, member=None): module_name = splitext(basename(module_path))[0] - try: # 'U' is default from Python 3.0 and deprecated since 3.9 - module_file = open(module_path, 'U') - except ValueError: - module_file = open(module_path, 'rt') - description = ('.py', 'U', imp.PY_SOURCE) - module = imp.load_module(module_name, module_file, module_path, description) + spec = importlib.util.spec_from_file_location(module_name, module_path) + if spec is None: + raise IOError(f'file {module_path} not found') + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) if member: return getattr(module, member) else: