diff --git a/Lib/imp.py b/Lib/imp.py new file mode 100644 --- /dev/null +++ b/Lib/imp.py @@ -0,0 +1,243 @@ +"""This module provides the components needed to build your own __import__ +function. Undocumented functions are obsolete. + +As of Python 3.3, the API of the imp module is provided here as a pure +Python module. The original imp module, Python/import.c, is now exposed +as _imp. However, both imp and _imp are essentially wrappers around +importlib. As such, importlib should be used directly. + +""" + +# the backwards-compatible interface +__all__ = ( + # implemented in importlib._bootstrap + "lock_held", "acquire_lock", "release_lock", + "cache_from_source", "source_from_cache", + "NullImporter", + # implemented here + "PY_SOURCE", "PY_COMPILED", "C_EXTENSION", "PKG_DIRECTORY", + "C_BUILTIN", "PY_FROZEN", "SEARCH_ERROR", "PY_RESOURCE", + "PY_CODERESOURCE", "IMP_HOOK", + "get_suffixes", "find_module", "load_module", "reload", + "new_module", "get_magic", "get_tag", + ) + +# "private" but still here: +# load_package (seemingly never documented) +# load_dynamic (documented through 3.1) +# load_compiled (documented through 3.1) +# load_source (documented through 3.1) +# init_builtin (documented through 3.1) +# init_frozen (documented through 3.1) +# is_builtin (documented through 3.1) +# is_frozen (documented through 3.1) +# _fix_co_filename +# get_frozen_object +# is_frozen_package + +# not here, but runpy looks for it here: +# get_loader + +import sys +import os.path + +import importlib._bootstrap as importlib + +from importlib._bootstrap import ( + # exposed here + NullImporter, # XXX going away in importlib + lock_held, + acquire_lock, + release_lock, + cache_from_source, + source_from_cache, + # _not_ in public interface + load_dynamic, + _fix_co_filename, + get_frozen_object, + is_frozen_package, + init_builtin, + init_frozen, + is_builtin, + is_frozen, + ) + +# XXX Can die a horrible death: +from _imp import load_compiled, load_source, load_package + + +( +SEARCH_ERROR, # = 0 +PY_SOURCE, +PY_COMPILED, +C_EXTENSION, +PY_RESOURCE, # Mac only +PKG_DIRECTORY, +C_BUILTIN, +PY_FROZEN, +PY_CODERESOURCE, # Mac only +IMP_HOOK, +) = range(10) + +_MODULE_TYPES = { + importlib.BuiltinImporter: C_BUILTIN, + importlib.FrozenImporter: PY_FROZEN, + importlib._ExtensionFileLoader: C_EXTENSION, + importlib._SourcelessFileLoader: PY_COMPILED, + importlib._SourceFileLoader: PY_SOURCE, + } + +_ERR_MSG = 'No module named {!r}' + +def get_magic(): + """Return the magic number for .pyc or .pyo files.""" + return importlib.MAGIC_BYTES + + +def get_tag(): + """Return the magic tag for .pyc or .pyo files.""" + return importlib.TAG + + +def new_module(name): + """Create a new module. + + Do not enter it in sys.modules. The module name must include the full + package name, if any. + + """ + return importlib.Module(name) + + +def get_suffixes(): + """Return a list of (suffix, mode, type) tuples describing the files + that find_module() looks for.""" + results = [] + for Loader, filetype in _MODULE_TYPES.items(): + suffixes = getattr(Loader, "SUFFIXES", None) + if not suffixes: + continue + for suffix in suffixes: + results.append((suffix, Loader.MODE, filetype)) + return results + + +def _extrapolate_loader(module): + """Return the loader that would load the module.""" + # XXX ultimately superfluous + # under importlib, all modules have __loader__ defined... + try: + return module.__loader__ + except AttributeError: + pass + + if importlib.is_builtin(module.__name__): + return importlib.BuiltinImporter + elif importlib.is_frozen(module.__name__): + return importlib.FrozenImporter + + # must be one of the path-based loaders + filename = getattr(module, "__file__", None) + for Loader, filetype in _MODULE_TYPES.items(): + if filetype in (C_BUILTIN, PY_FROZEN): + continue + for suffix in Loader.SUFFIXES: + if filename.endswith(suffix): + break + else: + continue + break + else: + msg = "Could not identify loader for {}" + raise ImportError(msg.format(filename)) + + if filetype is PY_COMPILED: + return Loader(module.__name__) + #return Loader(module.__name__, os.path.dirname(module.__file__)) + return Loader(module.__name__, filename) + + +def reload(module): + """Reload the module and return it. + + The module must have been successfully imported before. + + """ + # XXX get rid of interp->modules_reloading + #return module.__loader__.load_module(module.__name__) + loader = _extrapolate_loader(module) + return loader.load_module(module.__name__) + + +def find_module(name, path=None): + """Search for a module and return the tuple representing it. + + If path is omitted or None, search for a built-in, frozen or special + module and continue search in sys.path. The module name cannot + contain '.'; to search for a submodule of a package, pass the + submodule name and the package's __path__. + + usage: + find_module(name, [path]) -> (file, filename, (suffix, mode, type)) + + """ + + loader = importlib.get_loader(name, path) + if loader is None: + raise ImportError(_ERR_MSG.format(name)) + + # defaults + file = None + filename = None + suffix = "" + mode = "" + try: + filetype = _MODULE_TYPES[loader] + except KeyError: + raise ImportError(_ERR_MSG.format(name)) + + # XXX handle MS_COREDLL case? + + if loader.is_package(name): + filename = os.path.dirname(loader.get_filename(name)) + elif filetype not in (C_BUILTIN, PY_FROZEN): + filename = loader.get_filename(name) + for suffix in loader.SUFFIXES: + if filename.endswith(suffix): + file = open(filename, loader.MODE) + break + else: + suffix = "" + mode = "" + + return (file, filename, (suffix, mode, filetype)) + + +def load_module(name, file, filename, description): + """Load a module, given information returned by find_module(). + + The module name must include the full package name, if any. + + usage: + load_module(name, file, filename, (suffix, mode, type)) -> module + + """ + suffix, mode, filetype = description + if filetype is PKG_DIRECTORY: + args = find_module(os.path.join(name, "__init__"), filename) + return load_module(*args) + elif filetype in (PY_SOURCE, PY_COMPILED, C_EXTENSION): + return importlib.load_module_from_file(filename, module, name, + file=file, + filetype=filetype) + elif filetype is C_BUILTIN: + return BuiltinImporter.load_module(name) + elif filetype is PY_FROZEN: + return FrozenImporter.load_module(name) + else: + msg = "Don't know how to import {} (type code {})" + raise ImportError(msg.format(name, filetype)) + +# XXX remove once the above implementations are working +#from _imp import load_module +from _imp import find_module, load_module diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -10,10 +10,10 @@ # Bootstrap help ##################################################### -import imp +import _imp import sys -_bootstrap._setup(sys, imp) +_bootstrap._setup(sys, _imp) # Public API ######################################################### diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -7,7 +7,7 @@ """ -# Injected modules are '_warnings', 'imp', 'sys', 'marshal', '_io', +# Injected modules are '_warnings', '_imp', 'sys', 'marshal', '_io', # and '_os' (a.k.a. 'posix', 'nt' or 'os2'). # Injected attribute is path_sep. # Most injection is handled by _setup(). @@ -16,6 +16,11 @@ # reference any injected objects! This includes not only global code but also # anything specified at the class level. +# XXX dependencies on import.c: +# is_frozen, init_frozen, get_frozen_object, is_frozen_package, is_builtin, +# init_builtin, _fix_co_filename, load_dynamic +# acquire_lock, release_lock, lock_held, cache_from_source, source_from_cache + # Bootstrap-related code ###################################################### @@ -105,15 +110,17 @@ return _path_is_mode_type(path, 0o040000) +# XXX unused function? def _path_without_ext(path, ext_type): """Replacement for os.path.splitext()[0].""" - for suffix in _suffix_list(ext_type): + for suffix in imp.get_suffixes()[ext_type]: if path.endswith(suffix): return path[:-len(suffix)] else: raise ValueError("path is not of the specified type") +# XXX unused function? def _path_absolute(path): """Replacement for os.path.abspath.""" if not path: @@ -158,9 +165,228 @@ code_type = type(_wrap.__code__) + +# legacy imp interface support ################################################ + +# Magic word to reject .pyc files generated by other Python versions. +# It should change for each incompatible change to the bytecode. +# +# The value of CR and LF is incorporated so if you ever read or write +# a .pyc file in text mode the magic number will be wrong; also, the +# Apple MPW compiler swaps their values, botching string constants. +# +# The magic numbers must be spaced apart at least 2 values, as the +# -U interpeter flag will cause MAGIC+1 being used. They have been +# odd numbers for some time now. +# +# There were a variety of old schemes for setting the magic number. +# The current working scheme is to increment the previous value by +# 10. +# +# Starting with the adoption of PEP 3147 in Python 3.2, every bump in magic +# number also includes a new "magic tag", i.e. a human readable string used +# to represent the magic number in __pycache__ directories. When you change +# the magic number, you must also set a new unique magic tag. Generally this +# can be named after the Python major version of the magic number bump, but +# it can really be anything, as long as it's different than anything else +# that's come before. The tags are included in the following table, starting +# with Python 3.2a0. +# +# Known values: +# Python 1.5: 20121 +# Python 1.5.1: 20121 +# Python 1.5.2: 20121 +# Python 1.6: 50428 +# Python 2.0: 50823 +# Python 2.0.1: 50823 +# Python 2.1: 60202 +# Python 2.1.1: 60202 +# Python 2.1.2: 60202 +# Python 2.2: 60717 +# Python 2.3a0: 62011 +# Python 2.3a0: 62021 +# Python 2.3a0: 62011 (!) +# Python 2.4a0: 62041 +# Python 2.4a3: 62051 +# Python 2.4b1: 62061 +# Python 2.5a0: 62071 +# Python 2.5a0: 62081 (ast-branch) +# Python 2.5a0: 62091 (with) +# Python 2.5a0: 62092 (changed WITH_CLEANUP opcode) +# Python 2.5b3: 62101 (fix wrong code: for x, in ...) +# Python 2.5b3: 62111 (fix wrong code: x += yield) +# Python 2.5c1: 62121 (fix wrong lnotab with for loops and +# storing constants that should have been removed) +# Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp) +# Python 2.6a0: 62151 (peephole optimizations and STORE_MAP opcode) +# Python 2.6a1: 62161 (WITH_CLEANUP optimization) +# Python 3000: 3000 +# 3010 (removed UNARY_CONVERT) +# 3020 (added BUILD_SET) +# 3030 (added keyword-only parameters) +# 3040 (added signature annotations) +# 3050 (print becomes a function) +# 3060 (PEP 3115 metaclass syntax) +# 3061 (string literals become unicode) +# 3071 (PEP 3109 raise changes) +# 3081 (PEP 3137 make __file__ and __name__ unicode) +# 3091 (kill str8 interning) +# 3101 (merge from 2.6a0, see 62151) +# 3103 (__file__ points to source file) +# Python 3.0a4: 3111 (WITH_CLEANUP optimization). +# Python 3.0a5: 3131 (lexical exception stacking, including POP_EXCEPT) +# Python 3.1a0: 3141 (optimize list, set and dict comprehensions: +# change LIST_APPEND and SET_ADD, add MAP_ADD) +# Python 3.1a0: 3151 (optimize conditional branches: +# introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE) +# Python 3.2a0: 3160 (add SETUP_WITH) +# tag: cpython-32 +# Python 3.2a1: 3170 (add DUP_TOP_TWO, remove DUP_TOPX and ROT_FOUR) +# tag: cpython-32 +# Python 3.2a2 3180 (add DELETE_DEREF) +# Python 3.3a0 3190 __class__ super closure changed +# Python 3.3a0 3200 (__qualname__ added) +# 3210 (added size modulo 2**32 to the pyc header) +# Python 3.3a1 3220 (changed PEP 380 implementation) + +# MAGIC must change whenever the bytecode emitted by the compiler may no +# longer be understood by older implementations of the eval loop (usually +# due to the addition of new opcodes). +MAGIC = 3220 + + +# TAG must change for each major Python release. The magic number will take +# care of any bytecode changes that occur during development. +#TAG = ... (set in _setup() due to reliance on sys) + + +# XXX the platform names need to be matched up +_PLATFORM_EXTENSIONS = { # pulled from Python.dynload_*.c + #"aix": (".so",), + "cygwin": (".dll",), + "dl": (".o",), + "hpux": (".sl",), + #"next": (".so",), + "win32": (".pyd", + "_d.pyd"), + # default defined in _setup() due to reliance on sys + } + + +def _get_pyc_magic_int(magic_bytes, *, withlinesep=False): + """Return the magic number encoded in the bytes.""" + rawmagic = magic_bytes[0] + (magic_bytes[1] << 8) + if withlinesep: + rawmagic += magic_bytes[2] << 16 + rawmagic += magic_bytes[3] << 24 + return rawmagic + +def get_pyc_magic_bytes(rawmagic=MAGIC, *, withlinesep=True): + """Return the magic number for .pyc or .pyo files.""" + if withlinesep: + rawmagic |= (ord("\r") << 16) | (ord("\n") << 24) + return bytes(( + (rawmagic >> 0) & 0xff, + (rawmagic >> 8) & 0xff, + (rawmagic >> 16) & 0xff, + (rawmagic >> 24) & 0xff)) + +MAGIC_BYTES = get_pyc_magic_bytes() + + +# these 3 rely on C implementation so they're overridden in _setup() +def lock_held(): + raise NotImplementedError +def acquire_lock(): + raise NotImplementedError +def release_lock(): + raise NotImplementedError + + +# "Module" class defined in _setup() (due to reliance on _imp) +#Module = type(imp) + + +# XXX needs implementation (currently overridden in _setup()) +def cache_from_source(path, debug_override=None): + """Given the path to a .py file, return the path to its .pyc/.pyo file. + + The .py file does not need to exist; this simply returns the path to the + .pyc/.pyo file calculated as if the .py file were imported. The extension + will be .pyc unless __debug__ is not defined, then it will be .pyo. + + If debug_override is not None, then it must be a boolean and is taken as + the value of __debug__ instead. + + """ + raise NotImplementedError + + +# XXX needs implementation (currently overridden in _setup()) +def source_from_cache(path): + """Given the path to a .pyc./.pyo file, return the path to its .py file. + + The .pyc/.pyo file does not need to exist; this simply returns the + path to the .py file calculated to correspond to the .pyc/.pyo file. + If path does not conform to PEP 3147 format, ValueError will be raised. + + """ + raise NotImplementedError + + +# XXX +def get_loader_from_filename(filename): + raise NotImplementedError + + +def infer_module_name(filename): + """Return the full module name derived from the filename.""" + # XXX figure it out a la runpy.run_module()? + # a stub for use (ultimately) in things like runpy + raise NotImplementedError + + +def load_module_from_file(filename, mode="r", name=None, parent="", + ispackage=False, file=None, loader=None): + """Load and return the module. + + If no name is passed, it is derived from the filename. If parent is + passed, that module is used for __package__. Otherwise it is + derived from the name. + + """ + # XXX incomplete, but you get the idea + if name is None: + name = infer_module_name(filename) + if filetype is None: + filetype = get_filetype(filename) + + if parent is None: + parent = name.rpartition(".")[0] + if parent == "": + parent = None + else: + parent = import_module(parent) # XXX NameError + + if not loader: + loader = None# XXX ??? + + # XXX requires that loaders have load_module_from_file() + if file is None: + file = open(filename, mode) + with file: + return loader.load_module_from_file(name, filename, parent, + file, is_package) + return loader.load_module_from_file(name, filename, parent, + file, is_package) + +# XXX for Loaders: +#def load_module_from_file(self, name, filename, parent, loader, file, +# is_package=False): + + # Finder/loader utility code ################################################## - def set_package(fxn): """Set __package__ on the returned module.""" def set_package_wrapper(*args, **kwargs): @@ -205,7 +431,7 @@ # This must be done before open() is called as the 'io' module # implicitly imports 'locale' and would otherwise trigger an # infinite loop. - module = imp.new_module(fullname) + module = Module(fullname) sys.modules[fullname] = module try: return fxn(self, module, *args, **kwargs) @@ -253,6 +479,7 @@ return _requires_frozen_wrapper +# XXX unused function 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() @@ -382,7 +609,7 @@ magic = data[:4] raw_timestamp = data[4:8] raw_size = data[8:12] - if len(magic) != 4 or magic != imp.get_magic(): + if len(magic) != 4 or magic != MAGIC_BYTES: raise ImportError("bad magic number in {}".format(fullname)) elif len(raw_timestamp) != 4: raise EOFError("bad timestamp in {}".format(fullname)) @@ -417,7 +644,7 @@ code_object = self.get_code(name) module.__file__ = self.get_filename(name) if not sourceless: - module.__cached__ = imp.cache_from_source(module.__file__) + module.__cached__ = cache_from_source(module.__file__) else: module.__cached__ = module.__file__ module.__package__ = name @@ -479,7 +706,7 @@ """ source_path = self.get_filename(fullname) - bytecode_path = imp.cache_from_source(source_path) + bytecode_path = cache_from_source(source_path) source_mtime = None if bytecode_path is not None: try: @@ -511,10 +738,10 @@ dont_inherit=True) if (not sys.dont_write_bytecode and bytecode_path is not None and source_mtime is not None): - # If e.g. Jython ever implements imp.cache_from_source to have + # If e.g. Jython ever implements cache_from_source to have # their own cached file format, this block of code will most likely # throw an exception. - data = bytearray(imp.get_magic()) + data = bytearray(MAGIC_BYTES) data.extend(_w_long(source_mtime)) data.extend(_w_long(len(source_bytes))) data.extend(marshal.dumps(code_object)) @@ -561,6 +788,9 @@ """Concrete implementation of SourceLoader using the file system.""" + SUFFIXES = [".py"] # .pyw added in _setup(), if appropriate + MODE = "U" + def path_stats(self, path): """Return the metadat for the path.""" st = _os.stat(path) @@ -598,6 +828,9 @@ """Loader which handles sourceless file imports.""" + SUFFIXES = [".pyc" if __debug__ else ".pyo"] + MODE = "rb" + def load_module(self, fullname): return self._load_module(fullname, sourceless=True) @@ -624,6 +857,10 @@ """ + # filled out in _setup() + SUFFIXES = [] + MODE = "rb" # XXX will this ever _not_ be the case? + def __init__(self, name, path): self._name = name self._path = path @@ -807,7 +1044,7 @@ supports_packages = True def __init__(self): - self.suffixes = _suffix_list(imp.PY_SOURCE) + self.suffixes = self.loader.SUFFIXES class _SourcelessFinderDetails: @@ -815,7 +1052,7 @@ supports_packages = True def __init__(self): - self.suffixes = _suffix_list(imp.PY_COMPILED) + self.suffixes = self.loader.SUFFIXES class _ExtensionFinderDetails: @@ -824,7 +1061,23 @@ supports_packages = False def __init__(self): - self.suffixes = _suffix_list(imp.C_EXTENSION) + self.suffixes = self.loader.SUFFIXES + + +# XXX going away at some point +class NullImporter: + + """Null importer object""" + + def __init__(self, name): + if len(name) == 0: + raise ImportError('empty pathname') + elif _path_isdir(name): + raise ImportError('existing directory') + + def find_module(self, fullname, path=None): + """Always return None""" + return None # Import itself ############################################################### @@ -852,7 +1105,7 @@ try: return super()._path_hooks(path) except ImportError: - implicit_hooks = [_DEFAULT_PATH_HOOK, imp.NullImporter] + implicit_hooks = [_DEFAULT_PATH_HOOK, NullImporter] return super()._path_hooks(path, implicit_hooks) @classmethod @@ -868,11 +1121,11 @@ def __enter__(self): """Acquire the import lock.""" - imp.acquire_lock() + acquire_lock() def __exit__(self, exc_type, exc_value, exc_traceback): """Release the import lock regardless of any raised exceptions.""" - imp.release_lock() + release_lock() def _resolve_name(name, package, level): @@ -899,6 +1152,13 @@ return None +def get_loader(name, path=None): + loader = _find_module(name, path) + if loader is None: + raise ImportError(_ERR_MSG.format(name)) + return loader + + def _sanity_check(name, package, level): """Verify arguments are "sane".""" if not isinstance(name, str): @@ -1094,7 +1354,76 @@ # Constants setattr(self_module, '_relax_case', _make_relax_case()) + # find the Python implementation + # XXX is there a better way? + if sys.version.startswith("IronPython"): + impl = "ironpython" + elif sys.version.startswith("java"): + impl = "jython" + elif "PyPy" in sys.version: + impl = "pypy" + else: + impl = "cpython" + # set TAG from current version + global TAG + TAG = "{}-{}{}".format(impl, *sys.version_info) + + # suffixes + if sys.platform == "win32": + _SourceFileLoader.SUFFIXES.append(".pyw") + # XXX from Include/modsupport.h + PYTHON_ABI_STRING = sys.version_info[0] + # XXX from Lib/_sysconfigdata.py + SOABI = "{}dm".format(TAG) + default = ( + ".so", + ".abi{}.so".format(PYTHON_ABI_STRING), + ".{}.so".format(SOABI) + ) + for suffix in _PLATFORM_EXTENSIONS.get(sys.platform, default): + _ExtensionFileLoader.SUFFIXES.append(suffix) + _ExtensionFileLoader.SUFFIXES.append("module{}".format(suffix)) + + # expose the builtin module type + global Module + Module = type(imp) + + # XXX these must be implemented in C (i.e. in _imp)? + global lock_held + lock_held = imp.lock_held + global acquire_lock + acquire_lock = imp.acquire_lock + global release_lock + release_lock = imp.release_lock + + # Needs to stay in _imp + global load_dynamic + load_dynamic = imp.load_dynamic + + # Need to stay in _imp (but used only here) + global _fix_co_filename + _fix_co_filename = imp._fix_co_filename + global get_frozen_object + get_frozen_object = imp.get_frozen_object + global is_frozen_package + is_frozen_package = imp.is_frozen_package + global init_builtin + init_builtin = imp.init_builtin + global is_builtin + is_builtin = imp.is_builtin + global init_frozen + init_frozen = imp.init_frozen + global is_frozen + is_frozen = imp.is_frozen + + # XXX not implemented here yet + global cache_from_source + cache_from_source = imp.cache_from_source + global source_from_cache + source_from_cache = imp.source_from_cache + + def _install(sys_module, imp_module): """Install importlib as the implementation of import. diff --git a/Modules/config.c.in b/Modules/config.c.in --- a/Modules/config.c.in +++ b/Modules/config.c.in @@ -39,7 +39,7 @@ {"marshal", PyMarshal_Init}, /* This lives in import.c */ - {"imp", PyInit_imp}, + {"_imp", PyInit_imp}, /* This lives in Python/Python-ast.c */ {"_ast", PyInit__ast}, diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -4259,7 +4259,7 @@ static struct PyModuleDef impmodule = { PyModuleDef_HEAD_INIT, - "imp", + "_imp", doc_imp, 0, imp_methods, diff --git a/use_of_imp.txt b/use_of_imp.txt new file mode 100644 --- /dev/null +++ b/use_of_imp.txt @@ -0,0 +1,369 @@ + +# grep -r 'from imp import ' * +# grep -r ' imp\.' * +# XXX generate this document programmatically? +# +# +# Markers: +# + part of import system +# - tests +# o tools + + +usage of the imp module in CPython (.py files): +------------------------------------------------ + +imp.get_importer() + Lib/runpy.py + +imp.load_package() + - Lib/test/test_imp.py + +imp.load_source() + - Lib/test/test_imp.py + +imp.load_compiled() + - Lib/test/test_imp.py + +imp.lock_held() + - Lib/test/test_socketserver.py + - Lib/test/test_imp.py + - Lib/test/test_threaded_import.py + +imp.release_lock() + + Lib/importlib/_bootstrap.py + - Lib/test/test_fork1.py + - Lib/test/test_imp.py + +imp.acquire_lock() + + Lib/importlib/_bootstrap.py + - Lib/test/test_imp.py + - Lib/test/test_fork1.py + +imp.load_dynamic() + + Lib/importlib/_bootstrap.py + o Mac/Tools/bundlebuilder.py + o setup.py + +imp._fix_co_filename() + + Lib/importlib/_bootstrap.py + +imp.get_frozen_object() + + Lib/importlib/_bootstrap.py + +imp.init_frozen() + + Lib/importlib/_bootstrap.py + +imp.init_builtin() + + Lib/importlib/_bootstrap.py + +imp.is_builtin() + + Lib/importlib/_bootstrap.py + +imp.is_frozen() + + Lib/importlib/_bootstrap.py + +imp.NullImporter + + Lib/importlib/_bootstrap.py + - Lib/importlib/test/import_/test_path.py + - Lib/importlib/test/test_api.py + - Lib/test/test_sys.py + - Lib/test/test_imp.py + Lib/runpy.py + +imp.new_module() + + Lib/importlib/_bootstrap.py + - Lib/importlib/test/source/test_abc_loader.py + - Lib/importlib/test/source/test_file_loader.py + - Lib/importlib/test/frozen/test_loader.py + - Lib/importlib/test/util.py + - Lib/importlib/test/test_util.py + - Lib/importlib/test/benchmark.py + - Lib/test/test_pkgutil.py + - Lib/test/test_pdb.py + Lib/runpy.py + +imp.C_BUILTIN + Lib/modulefinder.py + +imp.C_EXTENSION + Lib/pkgutil.py + +imp.PY_COMPILED + Lib/pkgutil.py + +imp.PKG_DIRECTORY + o Mac/Tools/bundlebuilder.py + o Tools/i18n/pygettext.py + Lib/modulefinder.py + Lib/pyclbr.py + Lib/pkgutil.py + +imp.C_EXTENSION + - Lib/importlib/test/extension/util.py + o Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand + Lib/pkgutil.py + +imp.PY_SOURCE + - Lib/test/test_imp.py + o Tools/i18n/pygettext.py + o Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand + Lib/packaging/create.py + Lib/pkgutil.py + Lib/pydoc.py + Lib/idlelib/EditorWindow.py + Lib/modulefinder.py + Lib/pyclbr.py + +imp.PY_COMPILED + Lib/pydoc.py + Lib/modulefinder.py + Lib/pkgutil.py + +imp.get_magic() + + Lib/importlib/_bootstrap.py + - Lib/importlib/test/source/test_abc_loader.py + - Lib/importlib/test/source/test_file_loader.py + - Lib/test/test_zipimport.py + - Lib/test/test_compileall.py + o Mac/Tools/bundlebuilder.py + o Tools/scripts/checkpyc.py + Lib/pydoc.py + Lib/compileall.py + Lib/modulefinder.py + Lib/importlib/abc.py + Lib/pkgutil.py + Lib/py_compile.py + +imp.get_suffixes() + + Lib/importlib/_bootstrap.py + - Lib/importlib/test/extension/util.py + o Mac/Tools/bundlebuilder.py + o Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand + o Tools/i18n/pygettext.py + Lib/ctypes/util.py + Lib/inspect.py + Lib/idlelib/PathBrowser.py + Lib/modulefinder.py + +imp.cache_from_source() + + Lib/importlib/_bootstrap.py + - Lib/distutils/tests/test_install_lib.py + - Lib/importlib/test/source/test_abc_loader.py + - Lib/importlib/test/source/test_file_loader.py + - Lib/importlib/test/benchmark.py + - Lib/packaging/tests/test_command_install_lib.py + - Lib/test/test_zipimport.py + - Lib/test/test_py_compile.py + - Lib/test/test_imp.py + - Lib/test/test_compileall.py + - Lib/test/test_import.py + - Lib/test/support.py + Lib/compileall.py + Lib/py_compile.py + Lib/zipfile.py + Lib/distutils/util.py + Lib/packaging/util.py + +imp.source_from_cache() + - Lib/test/test_zipfile.py + - Lib/test/test_imp.py + +imp.get_tag() + - Lib/distutils/tests/test_build_py.py + - Lib/distutils/tests/test_bdist_dumb.py + - Lib/distutils/tests/test_install.py + - Lib/packaging/tests/test_command_install_dist.py + - Lib/packaging/tests/test_command_build_py.py + - Lib/packaging/tests/test_command_bdist_dumb.py + - Lib/test/test_imp.py + - Lib/test/test_import.py + +imp.load_module() + - Lib/test/test_imp.py + - Lib/test/test_importhooks.py + - Lib/test/test_import.py + Lib/pydoc.py + Lib/idlelib/EditorWindow.py: + Lib/pkgutil.py + Lib/packaging/create.py + Lib/multiprocessing/forking.py + Python/makeopcodetargets.py + +imp.find_module() + - Lib/test/test_imp.py + - Lib/test/test_unicode.py + - Lib/test/test_importhooks.py + - Lib/test/test_import.py + o Mac/Tools/bundlebuilder.py + o Python/makeopcodetargets.py + o Tools/i18n/pygettext.py + Lib/idlelib/EditorWindow.py + Lib/modulefinder.py + Lib/pkgutil.py + Lib/pyclbr.py + Lib/multiprocessing/forking.py + +imp.reload() + - Lib/test/test_imp.py + - Lib/test/test_imp.py + - Lib/test/test_imp.py + - Lib/test/test_import.py + o Doc/tutorial/modules.rst + o Doc/faq/programming.rst + o Doc/faq/programming.rst + + +imp.get_loader() + Lib/runpy.py + +PyImport_GetImporter() + Lib/runpy.py + + +usage of __import__ in CPython (.py files): +-------------------------------------------- + +builtins.__import__() + + Lib/importlib/_bootstrap.py + - Lib/ctypes/test/__init__.py + - Lib/unittest/mock.py + - Lib/unittest/main.py + - Lib/unittest/test/testmock/__init__.py + - Lib/unittest/test/__init__.py + - Lib/unittest/loader.py + - Lib/distutils/tests/__init__.py + - Lib/importlib/test/regrtest.py + - Lib/importlib/test/import_/test_caching.py + - Lib/importlib/test/import_/util.py + - Lib/importlib/test/import_/test_api.py + - Lib/importlib/test/import_/test_relative_imports.py + - Lib/importlib/test/__main__.py + - Lib/importlib/test/benchmark.py + - Lib/lib2to3/tests/__init__.py + - Lib/packaging/tests/test_dist.py + - Lib/packaging/tests/__init__.py + - Lib/test/test_zipimport.py + - Lib/test/test_runpy.py + - Lib/test/test_support.py + - Lib/test/test_strlit.py + - Lib/test/test_dbm.py + - Lib/test/test_modulefinder.py + - Lib/test/test_pyclbr.py + - Lib/test/regrtest.py + - Lib/test/test_imp.py + - Lib/test/test_exceptions.py + - Lib/test/test_multiprocessing.py + - Lib/test/test_pkgimport.py + - Lib/test/test_coding.py + - Lib/test/test_email/test_email.py + - Lib/test/test_fork1.py + - Lib/test/test_importhooks.py + - Lib/test/test_import.py + - Lib/test/xmltests.py + - Lib/test/test_builtin.py + - Lib/test/support.py + - Lib/test/test_uuid.py + - Lib/test/test_pkg.py + - Lib/test/json_tests/__init__.py + - Lib/doctest.py + o Tools/pynche/PyncheWidget.py + o Tools/iobench/iobench.py + o Tools/ccbench/ccbench.py + o Misc/Vim/vim_syntax.py + Lib/turtle.py + Lib/ctypes/__init__.py + Lib/warnings.py + Lib/pydoc.py + Lib/dbm/__init__.py + Lib/pickle.py + Lib/xml/sax/__init__.py + Lib/xml/dom/domreg.py + Lib/idlelib/EditorWindow.py + Lib/idlelib/PyShell.py + Lib/distutils/ccompiler.py + Lib/distutils/dist.py + Lib/turtledemo/__main__.py + Lib/importlib/__init__.py + Lib/encodings/__init__.py + Lib/smtpd.py + Lib/lib2to3/refactor.py + Lib/logging/config.py + Lib/pkgutil.py + Lib/optparse.py + Lib/packaging/util.py + + +usage of pkgutil module in CPython (.py files): +------------------------------------------------ + +pkgutil.iter_modules() + - Lib/test/test_pkgutil.py + Lib/pydoc.py + +pkgutil.walk_packages() + - Lib/test/test_pkgutil.py + Lib/pydoc.py + +pkgutil.extend_path() + Lib/pkgutil.py + +pkgutil.get_data() + - Lib/test/test_pkgutil.py + +pkgutil.get_loader() + - Lib/test/test_doctest.py + Lib/runpy.py + +pkgutil.read_code() + Lib/runpy.py + + +usage of compileall module in CPython: +--------------------------------------- + +compile_dir() + - Lib/test/test_compileall.py + + +usage of pycompile module in CPython: +-------------------------------------- + +compile() + + Lib/compileall.py + - Lib/importlib/test/source/test_file_loader.py + - Lib/importlib/test/source/test_finder.py + - Lib/importlib/test/benchmark.py + - Lib/test/test_runpy.py + - Lib/test/test_py_compile.py + - Lib/test/test_compileall.py + - Lib/test/test_import.py + - Lib/test/test_cmd_line_script.py + o PC/bdist_wininst/install.c + Lib/distutils/util.py + Lib/packaging/util.py + Lib/zipfile.py + + +PyCompileError + Lib/compileall.py + Lib/zipfile.py + + +usage of the import state in CPython: +-------------------------------------- + +sys.modules + +sys.builtin_module_names + +sys.dont_write_bytecode + +sys.path + +sys.meta_path + +sys.path_importer_cache + +sys.path_hooks +