mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
replace deprecated use of SourceFileLoader.load_module
This commit is contained in:
parent
779677bcc6
commit
94d28831e1
@ -24,12 +24,14 @@ def load_script(actx, path):
|
|||||||
# the fullname is not unique among scripts, so if there already is an existing script with said
|
# the fullname is not unique among scripts, so if there already is an existing script with said
|
||||||
# fullname, remove it.
|
# fullname, remove it.
|
||||||
sys.modules.pop(fullname, None)
|
sys.modules.pop(fullname, None)
|
||||||
loader = importlib.machinery.SourceFileLoader(fullname, path)
|
|
||||||
try:
|
try:
|
||||||
oldpath = sys.path
|
oldpath = sys.path
|
||||||
sys.path.insert(0, os.path.dirname(path))
|
sys.path.insert(0, os.path.dirname(path))
|
||||||
with addonmanager.safecall():
|
with addonmanager.safecall():
|
||||||
m = loader.load_module()
|
loader = importlib.machinery.SourceFileLoader(fullname, path)
|
||||||
|
spec = importlib.util.spec_from_loader(fullname, loader=loader)
|
||||||
|
m = importlib.util.module_from_spec(spec)
|
||||||
|
loader.exec_module(m)
|
||||||
if not getattr(m, "name", None):
|
if not getattr(m, "name", None):
|
||||||
m.name = path
|
m.name = path
|
||||||
return m
|
return m
|
||||||
|
Loading…
Reference in New Issue
Block a user