1717from importlib ._bootstrap import cache_from_source
1818
1919from importlib import _bootstrap
20+ from importlib import machinery
2021import os
2122import sys
2223import tokenize
24+ import warnings
2325
2426
2527# XXX "deprecate" once find_module(), load_module(), and get_suffixes() are
3739
3840
3941def get_suffixes ():
42+ warnings .warn ('imp.get_suffixes() is deprecated; use the constants '
43+ 'defined on importlib.machinery instead' ,
44+ DeprecationWarning , 2 )
4045 extensions = [(s , 'rb' , C_EXTENSION ) for s in extension_suffixes ()]
41- source = [(s , 'U' , PY_SOURCE ) for s in _bootstrap . _SOURCE_SUFFIXES ]
42- bytecode = [(_bootstrap . _BYTECODE_SUFFIX , 'rb' , PY_COMPILED )]
46+ source = [(s , 'U' , PY_SOURCE ) for s in machinery . SOURCE_SUFFIXES ]
47+ bytecode = [(s , 'rb' , PY_COMPILED ) for s in machinery . BYTECODE_SUFFIXES ]
4348
4449 return extensions + source + bytecode
4550
@@ -61,7 +66,7 @@ def source_from_cache(path):
6166 raise ValueError ('expected only 2 dots in '
6267 '{!r}' .format (pycache_filename ))
6368 base_filename = pycache_filename .partition ('.' )[0 ]
64- return os .path .join (head , base_filename + _bootstrap . _SOURCE_SUFFIXES [0 ])
69+ return os .path .join (head , base_filename + machinery . SOURCE_SUFFIXES [0 ])
6570
6671
6772class NullImporter :
@@ -126,7 +131,7 @@ def load_compiled(name, pathname, file=None):
126131# XXX deprecate
127132def load_package (name , path ):
128133 if os .path .isdir (path ):
129- extensions = _bootstrap . _SOURCE_SUFFIXES + [_bootstrap . _BYTECODE_SUFFIX ]
134+ extensions = machinery . SOURCE_SUFFIXES [:] + [machinery . BYTECODE_SUFFIXES ]
130135 for extension in extensions :
131136 path = os .path .join (path , '__init__' + extension )
132137 if os .path .exists (path ):
@@ -190,19 +195,21 @@ def find_module(name, path=None):
190195
191196 for entry in path :
192197 package_directory = os .path .join (entry , name )
193- for suffix in ['.py' , _bootstrap . _BYTECODE_SUFFIX ]:
198+ for suffix in ['.py' , machinery . BYTECODE_SUFFIXES [ 0 ] ]:
194199 package_file_name = '__init__' + suffix
195200 file_path = os .path .join (package_directory , package_file_name )
196201 if os .path .isfile (file_path ):
197202 return None , package_directory , ('' , '' , PKG_DIRECTORY )
198- for suffix , mode , type_ in get_suffixes ():
199- file_name = name + suffix
200- file_path = os .path .join (entry , file_name )
201- if os .path .isfile (file_path ):
202- break
203- else :
204- continue
205- break # Break out of outer loop when breaking out of inner loop.
203+ with warnings .catch_warnings ():
204+ warnings .simplefilter ('ignore' )
205+ for suffix , mode , type_ in get_suffixes ():
206+ file_name = name + suffix
207+ file_path = os .path .join (entry , file_name )
208+ if os .path .isfile (file_path ):
209+ break
210+ else :
211+ continue
212+ break # Break out of outer loop when breaking out of inner loop.
206213 else :
207214 raise ImportError ('No module name {!r}' .format (name ), name = name )
208215
0 commit comments