From b664cf11a71955009b8d28501b4277ef041aba88 Mon Sep 17 00:00:00 2001 From: Alexandre Rossi Date: Thu, 1 Feb 2024 16:54:40 +0100 Subject: [PATCH] the imp module has been removed in python3.12 --- webapp/graphite/util.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/webapp/graphite/util.py b/webapp/graphite/util.py index 1b5889026..08154fbb7 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,9 @@ 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) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) if member: return getattr(module, member) else: