summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-03-15 01:41:33 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-03-15 01:41:33 (GMT)
commita113ac58be3ee73d1382af3bfbf47b7ed5e5f5a9 (patch)
tree78b2a6b9730046c61c3d76c7cb7b7f195c695136 /Lib/importlib/_bootstrap.py
parent7aa21f75c1d9ac36f1ab7e00aa9d0048ef61476d (diff)
downloadcpython-a113ac58be3ee73d1382af3bfbf47b7ed5e5f5a9.zip
cpython-a113ac58be3ee73d1382af3bfbf47b7ed5e5f5a9.tar.gz
cpython-a113ac58be3ee73d1382af3bfbf47b7ed5e5f5a9.tar.bz2
Implement InspectLoader for BuiltinImporter.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index e94c1d2..736e1b6 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -173,6 +173,16 @@ def _check_name(method):
return inner
+def _requires_builtin(fxn):
+ """Decorator to verify the named module is built-in."""
+ def wrapper(self, fullname):
+ if fullname not in sys.builtin_module_names:
+ raise ImportError("{0} is not a built-in module".format(fullname))
+ return fxn(self, fullname)
+ _wrap(wrapper, fxn)
+ return wrapper
+
+
def _suffix_list(suffix_type):
"""Return a list of file suffixes based on the imp file type."""
return [suffix[0] for suffix in imp.get_suffixes()
@@ -204,10 +214,9 @@ class BuiltinImporter:
@classmethod
@set_package
@set_loader
+ @_requires_builtin
def load_module(cls, fullname):
"""Load a built-in module."""
- if fullname not in sys.builtin_module_names:
- raise ImportError("{0} is not a built-in module".format(fullname))
is_reload = fullname in sys.modules
try:
return imp.init_builtin(fullname)
@@ -216,6 +225,24 @@ class BuiltinImporter:
del sys.modules[fullname]
raise
+ @classmethod
+ @_requires_builtin
+ def get_code(cls, fullname):
+ """Return None as built-in modules do not have code objects."""
+ return None
+
+ @classmethod
+ @_requires_builtin
+ def get_source(cls, fullname):
+ """Return None as built-in modules do not have source code."""
+ return None
+
+ @classmethod
+ @_requires_builtin
+ def is_package(cls, fullname):
+ """Return None as built-in module are never packages."""
+ return False
+
class FrozenImporter: