Skip to content

Commit 86f377c

Browse files
committed
the imp module has been removed in python3.12
1 parent 8b3ebbf commit 86f377c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

webapp/graphite/util.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
See the License for the specific language governing permissions and
1313
limitations under the License."""
1414

15-
import imp
15+
import importlib
1616
import io
1717
import json as _json
1818
import socket
@@ -145,12 +145,11 @@ def is_unsafe_str(s):
145145

146146
def load_module(module_path, member=None):
147147
module_name = splitext(basename(module_path))[0]
148-
try: # 'U' is default from Python 3.0 and deprecated since 3.9
149-
module_file = open(module_path, 'U')
150-
except ValueError:
151-
module_file = open(module_path, 'rt')
152-
description = ('.py', 'U', imp.PY_SOURCE)
153-
module = imp.load_module(module_name, module_file, module_path, description)
148+
spec = importlib.util.spec_from_file_location(module_name, module_path)
149+
if spec is None:
150+
raise IOError(f'file {module_path} not found')
151+
module = importlib.util.module_from_spec(spec)
152+
spec.loader.exec_module(module)
154153
if member:
155154
return getattr(module, member)
156155
else:

0 commit comments

Comments
 (0)