mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Issue #13959: Re-implement imp.NullImporter in Lib/imp.py.
This commit is contained in:
parent
e383e82e04
commit
acf85cd131
3 changed files with 17 additions and 144 deletions
17
Lib/imp.py
17
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_*()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue