summaryrefslogtreecommitdiff
path: root/Lib/imp.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-04-29 12:50:03 -0400
committerBrett Cannon <brett@python.org>2012-04-29 12:50:03 -0400
commitacf85cd1314e498b1736677a1e08cfddc956c4ac (patch)
treedfd63a6562c931a4d02770927a589f4b41c35ebb /Lib/imp.py
parente383e82e0484aed79f2c78516e3f223345408d4b (diff)
downloadcpython-git-acf85cd1314e498b1736677a1e08cfddc956c4ac.tar.gz
Issue #13959: Re-implement imp.NullImporter in Lib/imp.py.
Diffstat (limited to 'Lib/imp.py')
-rw-r--r--Lib/imp.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/Lib/imp.py b/Lib/imp.py
index 0388d0881a..2abd7af0db 100644
--- a/Lib/imp.py
+++ b/Lib/imp.py
@@ -14,8 +14,6 @@ from _imp import (lock_held, acquire_lock, release_lock, reload,
from _imp import get_magic, get_tag
# Can (probably) move to importlib
from _imp import get_suffixes
-# Should be re-implemented here (and mostly deprecated)
-from _imp import NullImporter
from importlib._bootstrap import _new_module as new_module
from importlib._bootstrap import _cache_from_source as cache_from_source
@@ -60,6 +58,21 @@ def source_from_cache(path):
return os.path.join(head, base_filename + _bootstrap.SOURCE_SUFFIXES[0])
+class NullImporter:
+
+ """Null import object."""
+
+ def __init__(self, path):
+ if path == '':
+ raise ImportError('empty pathname', path='')
+ elif os.path.isdir(path):
+ raise ImportError('existing directory', path=path)
+
+ def find_module(self, fullname):
+ """Always returns None."""
+ return None
+
+
class _HackedGetData:
"""Compatibiilty support for 'file' arguments of various load_*()