Skip to content

Commit

Permalink
the imp module has been removed in python3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
niol committed Feb 1, 2024
1 parent 8b3ebbf commit daa2811
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions webapp/graphite/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, file_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
if member:
return getattr(module, member)
else:
Expand Down

0 comments on commit daa2811

Please sign in to comment.