diff options
author | Brett Cannon <brett@python.org> | 2012-05-04 19:20:40 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-05-04 19:20:40 (GMT) |
commit | 2657df47449dd5d324985a5eb43b937217e0d7e0 (patch) | |
tree | 9010c343fd2387a7961009b5b2ed93c7176fc6b1 /Lib/imp.py | |
parent | 17098a5447f8bc742023b39eb7d8ef141beed119 (diff) | |
download | cpython-2657df47449dd5d324985a5eb43b937217e0d7e0.zip cpython-2657df47449dd5d324985a5eb43b937217e0d7e0.tar.gz cpython-2657df47449dd5d324985a5eb43b937217e0d7e0.tar.bz2 |
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
This introduces a new function, imp.extension_suffixes(), which is
currently undocumented. That is forthcoming once issue #14657 is
resolved and how to expose file suffixes is decided.
Diffstat (limited to 'Lib/imp.py')
-rw-r--r-- | Lib/imp.py | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -9,11 +9,9 @@ functionality over this module. from _imp import (lock_held, acquire_lock, release_lock, load_dynamic, get_frozen_object, is_frozen_package, init_builtin, init_frozen, is_builtin, is_frozen, - _fix_co_filename) + _fix_co_filename, extension_suffixes) # Could move out of _imp, but not worth the code from _imp import get_magic, get_tag -# Can (probably) move to importlib -from _imp import get_suffixes from importlib._bootstrap import new_module from importlib._bootstrap import cache_from_source @@ -38,6 +36,14 @@ PY_CODERESOURCE = 8 IMP_HOOK = 9 +def get_suffixes(): + extensions = [(s, 'rb', C_EXTENSION) for s in extension_suffixes()] + source = [(s, 'U', PY_SOURCE) for s in _bootstrap._SOURCE_SUFFIXES] + bytecode = [(_bootstrap._BYTECODE_SUFFIX, 'rb', PY_COMPILED)] + + return extensions + source + bytecode + + def source_from_cache(path): """Given the path to a .pyc./.pyo file, return the path to its .py file. @@ -120,8 +126,8 @@ def load_compiled(name, pathname, file=None): # XXX deprecate def load_package(name, path): if os.path.isdir(path): - extensions = _bootstrap._suffix_list(PY_SOURCE) - extensions += _bootstrap._suffix_list(PY_COMPILED) + extensions = _bootstrap._SOURCE_SUFFIXES + extensions += [_bootstrap._BYTECODE_SUFFIX] for extension in extensions: path = os.path.join(path, '__init__'+extension) if os.path.exists(path): |