Skip to content

Commit

Permalink
Replace imp with importlib
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
  • Loading branch information
c00kiemon5ter committed Nov 7, 2023
1 parent 076563b commit 116d843
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions src/saml2/tools/parse_xsd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import errno
import getopt
import imp
import importlib
import re
import sys
import time
Expand Down Expand Up @@ -2015,38 +2015,10 @@ def usage():
print("Usage: parse_xsd [-i <module:as>] xsd.file > module.py")


def recursive_find_module(name, path=None):
parts = name.split(".")

mod_a = None
for part in parts:
# print("$$", part, path)
try:
(fil, pathname, desc) = imp.find_module(part, path)
except ImportError:
raise

mod_a = imp.load_module(name, fil, pathname, desc)
sys.modules[name] = mod_a
path = mod_a.__path__

return mod_a


def get_mod(name, path=None):
try:
mod_a = sys.modules[name]
if not isinstance(mod_a, types.ModuleType):
raise KeyError
except KeyError:
try:
(fil, pathname, desc) = imp.find_module(name, path)
mod_a = imp.load_module(name, fil, pathname, desc)
except ImportError:
if "." in name:
mod_a = recursive_find_module(name, path)
else:
raise
mod_a = sys.modules.get(name)
if not mod_a or not isinstance(mod_a, types.ModuleType):
mod_a = importlib.import_module(name, path)
sys.modules[name] = mod_a
return mod_a

Expand Down

0 comments on commit 116d843

Please sign in to comment.