mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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.
This commit is contained in:
parent
17098a5447
commit
2657df4744
19 changed files with 2971 additions and 3171 deletions
16
Lib/imp.py
16
Lib/imp.py
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue