Skip to content

Commit

Permalink
chore: improved imp support in legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Oct 15, 2023
1 parent d6b1796 commit ee464ff
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/netius/base/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@ def ctx_absolute():
try: import http.client
except ImportError: pass

with ctx_absolute():
try: import importlib.util
except ImportError: pass

try: import HTMLParser
except ImportError: import html.parser; HTMLParser = html.parser

try: import cPickle
except ImportError: import pickle; cPickle = pickle

try: import imp
except ImportError: import importlib; imp = importlib

try: import importlib
except ImportError: import imp; importlib = imp

Expand Down Expand Up @@ -329,6 +336,17 @@ def getargspec(func):
if has_full: return ArgSpec(*inspect.getfullargspec(func)[:4])
else: return inspect.getargspec(func)

def has_module(name):
if PYTHON_3:
try: spec = importlib.util.find_spec(name)
except ImportError: return False
if spec == None: return False
return True
try: file, _path, _description = imp.find_module(name)
except ImportError: return False
if file: file.close()
return True

def reduce(*args, **kwargs):
if PYTHON_3: return functools.reduce(*args, **kwargs)
return _reduce(*args, **kwargs)
Expand Down

0 comments on commit ee464ff

Please sign in to comment.