Fix modpython to show list of available modules

In 1.8.0 I switched from deprecated imp to importlib for loading module
by name, but forgot about this function

Close #1884
This commit is contained in:
Alexey Sokolov
2023-10-26 00:29:03 +01:00
parent bf5805d9a9
commit aa5016657b
3 changed files with 12 additions and 61 deletions

View File

@@ -940,33 +940,6 @@ def get_mod_info(modname, retmsg, modinfo):
return 2
def get_mod_info_path(path, modname, modinfo):
try:
x = imp.find_module(modname, [path])
except ImportError:
return 0
# x == (<open file './modules/admin.so', mode 'rb' at 0x7fa2dc748d20>,
# './modules/admin.so', ('.so', 'rb', 3))
# x == (<open file './modules/pythontest.py', mode 'U' at 0x7fa2dc748d20>,
# './modules/pythontest.py', ('.py', 'U', 1))
if x[0] is None and x[2][2] != imp.PKG_DIRECTORY:
return 0
try:
pymodule = imp.load_module(modname, *x)
except ImportError:
return 0
finally:
if x[0]:
x[0].close()
if modname not in pymodule.__dict__:
return 0
cl = pymodule.__dict__[modname]
modinfo.SetName(modname)
modinfo.SetPath(pymodule.__file__)
gather_mod_info(cl, modinfo)
return 1
CONTINUE = CModule.CONTINUE
HALT = CModule.HALT
HALTMODS = CModule.HALTMODS