2626
2727# Bootstrap-related code ######################################################
2828
29- CASE_INSENSITIVE_PLATFORMS = 'win' , 'cygwin' , 'darwin'
29+ _CASE_INSENSITIVE_PLATFORMS = 'win' , 'cygwin' , 'darwin'
3030
3131
3232def _make_relax_case ():
33- if sys .platform .startswith (CASE_INSENSITIVE_PLATFORMS ):
33+ if sys .platform .startswith (_CASE_INSENSITIVE_PLATFORMS ):
3434 def _relax_case ():
3535 """True if filenames must be checked case-insensitively."""
3636 return b'PYTHONCASEOK' in _os .environ
@@ -179,10 +179,10 @@ def _wrap(new, old):
179179 new .__dict__ .update (old .__dict__ )
180180
181181
182- code_type = type (_wrap .__code__ )
182+ _code_type = type (_wrap .__code__ )
183183
184184
185- def _new_module (name ):
185+ def new_module (name ):
186186 """Create a new module.
187187
188188 The module is not entered into sys.modules.
@@ -193,15 +193,15 @@ def _new_module(name):
193193
194194# Finder/loader utility code ##################################################
195195
196- PYCACHE = '__pycache__'
196+ _PYCACHE = '__pycache__'
197197
198- SOURCE_SUFFIXES = ['.py' ] # _setup() adds .pyw as needed.
198+ _SOURCE_SUFFIXES = ['.py' ] # _setup() adds .pyw as needed.
199199
200- DEBUG_BYTECODE_SUFFIX = '.pyc'
201- OPT_BYTECODE_SUFFIX = '.pyo'
202- BYTECODE_SUFFIX = DEBUG_BYTECODE_SUFFIX if __debug__ else OPT_BYTECODE_SUFFIX
200+ _DEBUG_BYTECODE_SUFFIX = '.pyc'
201+ _OPT_BYTECODE_SUFFIX = '.pyo'
202+ _BYTECODE_SUFFIX = _DEBUG_BYTECODE_SUFFIX if __debug__ else _OPT_BYTECODE_SUFFIX
203203
204- def _cache_from_source (path , debug_override = None ):
204+ def cache_from_source (path , debug_override = None ):
205205 """Given the path to a .py file, return the path to its .pyc/.pyo file.
206206
207207 The .py file does not need to exist; this simply returns the path to the
@@ -213,14 +213,14 @@ def _cache_from_source(path, debug_override=None):
213213
214214 """
215215 debug = __debug__ if debug_override is None else debug_override
216- suffix = DEBUG_BYTECODE_SUFFIX if debug else OPT_BYTECODE_SUFFIX
216+ suffix = _DEBUG_BYTECODE_SUFFIX if debug else _OPT_BYTECODE_SUFFIX
217217 head , tail = _path_split (path )
218218 base_filename , sep , _ = tail .partition ('.' )
219219 filename = '' .join ([base_filename , sep , _TAG , suffix ])
220- return _path_join (head , PYCACHE , filename )
220+ return _path_join (head , _PYCACHE , filename )
221221
222222
223- def verbose_message (message , * args ):
223+ def _verbose_message (message , * args ):
224224 """Print the message to stderr if -v/PYTHONVERBOSE is turned on."""
225225 if sys .flags .verbose :
226226 if not message .startswith (('#' , 'import ' )):
@@ -277,7 +277,7 @@ def module_for_loader_wrapper(self, fullname, *args, **kwargs):
277277 # This must be done before open() is called as the 'io' module
278278 # implicitly imports 'locale' and would otherwise trigger an
279279 # infinite loop.
280- module = _new_module (fullname )
280+ module = new_module (fullname )
281281 sys .modules [fullname ] = module
282282 module .__loader__ = self
283283 try :
@@ -472,11 +472,11 @@ def _bytes_from_bytecode(self, fullname, data, bytecode_path, source_stats):
472472 raise ImportError (msg , name = fullname , path = bytecode_path )
473473 elif len (raw_timestamp ) != 4 :
474474 message = 'bad timestamp in {}' .format (fullname )
475- verbose_message (message )
475+ _verbose_message (message )
476476 raise EOFError (message )
477477 elif len (raw_size ) != 4 :
478478 message = 'bad size in {}' .format (fullname )
479- verbose_message (message )
479+ _verbose_message (message )
480480 raise EOFError (message )
481481 if source_stats is not None :
482482 try :
@@ -486,7 +486,7 @@ def _bytes_from_bytecode(self, fullname, data, bytecode_path, source_stats):
486486 else :
487487 if _r_long (raw_timestamp ) != source_mtime :
488488 message = 'bytecode is stale for {}' .format (fullname )
489- verbose_message (message )
489+ _verbose_message (message )
490490 raise ImportError (message , name = fullname ,
491491 path = bytecode_path )
492492 try :
@@ -510,7 +510,7 @@ def _load_module(self, module, *, sourceless=False):
510510 code_object = self .get_code (name )
511511 module .__file__ = self .get_filename (name )
512512 if not sourceless :
513- module .__cached__ = _cache_from_source (module .__file__ )
513+ module .__cached__ = cache_from_source (module .__file__ )
514514 else :
515515 module .__cached__ = module .__file__
516516 module .__package__ = name
@@ -573,7 +573,7 @@ def get_code(self, fullname):
573573
574574 """
575575 source_path = self .get_filename (fullname )
576- bytecode_path = _cache_from_source (source_path )
576+ bytecode_path = cache_from_source (source_path )
577577 source_mtime = None
578578 if bytecode_path is not None :
579579 try :
@@ -594,12 +594,12 @@ def get_code(self, fullname):
594594 except (ImportError , EOFError ):
595595 pass
596596 else :
597- verbose_message ('{} matches {}' , bytecode_path ,
597+ _verbose_message ('{} matches {}' , bytecode_path ,
598598 source_path )
599599 found = marshal .loads (bytes_data )
600- if isinstance (found , code_type ):
600+ if isinstance (found , _code_type ):
601601 _imp ._fix_co_filename (found , source_path )
602- verbose_message ('code object from {}' ,
602+ _verbose_message ('code object from {}' ,
603603 bytecode_path )
604604 return found
605605 else :
@@ -609,7 +609,7 @@ def get_code(self, fullname):
609609 source_bytes = self .get_data (source_path )
610610 code_object = compile (source_bytes , source_path , 'exec' ,
611611 dont_inherit = True )
612- verbose_message ('code object from {}' , source_path )
612+ _verbose_message ('code object from {}' , source_path )
613613 if (not sys .dont_write_bytecode and bytecode_path is not None and
614614 source_mtime is not None ):
615615 data = bytearray (_MAGIC_NUMBER )
@@ -618,7 +618,7 @@ def get_code(self, fullname):
618618 data .extend (marshal .dumps (code_object ))
619619 try :
620620 self .set_data (bytecode_path , data )
621- verbose_message ('wrote {!r}' , bytecode_path )
621+ _verbose_message ('wrote {!r}' , bytecode_path )
622622 except NotImplementedError :
623623 pass
624624 return code_object
@@ -687,7 +687,7 @@ def set_data(self, path, data):
687687 return
688688 try :
689689 _write_atomic (path , data )
690- verbose_message ('created {!r}' , path )
690+ _verbose_message ('created {!r}' , path )
691691 except (PermissionError , FileExistsError ):
692692 # Don't worry if you can't write bytecode or someone is writing
693693 # it at the same time.
@@ -706,8 +706,8 @@ def get_code(self, fullname):
706706 data = self .get_data (path )
707707 bytes_data = self ._bytes_from_bytecode (fullname , data , path , None )
708708 found = marshal .loads (bytes_data )
709- if isinstance (found , code_type ):
710- verbose_message ('code object from {!r}' , path )
709+ if isinstance (found , _code_type ):
710+ _verbose_message ('code object from {!r}' , path )
711711 return found
712712 else :
713713 raise ImportError ("Non-code object in {}" .format (path ),
@@ -738,7 +738,7 @@ def load_module(self, fullname):
738738 is_reload = fullname in sys .modules
739739 try :
740740 module = _imp .load_dynamic (fullname , self .path )
741- verbose_message ('extension module loaded from {!r}' , self .path )
741+ _verbose_message ('extension module loaded from {!r}' , self .path )
742742 return module
743743 except :
744744 if not is_reload and fullname in sys .modules :
@@ -908,7 +908,7 @@ def _fill_cache(self):
908908 new_name = name
909909 lower_suffix_contents .add (new_name )
910910 self ._path_cache = lower_suffix_contents
911- if sys .platform .startswith (CASE_INSENSITIVE_PLATFORMS ):
911+ if sys .platform .startswith (_CASE_INSENSITIVE_PLATFORMS ):
912912 self ._relaxed_path_cache = set (fn .lower () for fn in contents )
913913
914914 @classmethod
@@ -1013,7 +1013,7 @@ def _find_and_load(name, import_):
10131013 elif name not in sys .modules :
10141014 # The parent import may have already imported this module.
10151015 loader .load_module (name )
1016- verbose_message ('import {!r} # {!r}' , name , loader )
1016+ _verbose_message ('import {!r} # {!r}' , name , loader )
10171017 # Backwards-compatibility; be nicer to skip the dict lookup.
10181018 module = sys .modules [name ]
10191019 if parent :
@@ -1185,7 +1185,7 @@ def _setup(sys_module, _imp_module):
11851185 setattr (self_module , '_MAGIC_NUMBER' , _imp_module .get_magic ())
11861186 setattr (self_module , '_TAG' , _imp .get_tag ())
11871187 if builtin_os == 'nt' :
1188- SOURCE_SUFFIXES .append ('.pyw' )
1188+ _SOURCE_SUFFIXES .append ('.pyw' )
11891189
11901190
11911191def _install (sys_module , _imp_module ):
0 commit comments