MCPcopy Index your code
hub / github.com/python/cpython / get_code

Method get_code

Lib/importlib/_bootstrap_external.py:810–893  ·  view source on GitHub ↗

Concrete implementation of InspectLoader.get_code. Reading of bytecode requires path_stats to be implemented. To write bytecode, set_data must also be implemented.

(self, fullname)

Source from the content-addressed store, hash-verified

808 module=fullname)
809
810 def get_code(self, fullname):
811 """Concrete implementation of InspectLoader.get_code.
812
813 Reading of bytecode requires path_stats to be implemented. To write
814 bytecode, set_data must also be implemented.
815
816 """
817 source_path = self.get_filename(fullname)
818 source_mtime = None
819 source_bytes = None
820 source_hash = None
821 hash_based = False
822 check_source = True
823 try:
824 bytecode_path = cache_from_source(source_path)
825 except NotImplementedError:
826 bytecode_path = None
827 else:
828 try:
829 st = self.path_stats(source_path)
830 except OSError:
831 pass
832 else:
833 source_mtime = int(st['mtime'])
834 try:
835 data = self.get_data(bytecode_path)
836 except OSError:
837 pass
838 else:
839 exc_details = {
840 'name': fullname,
841 'path': bytecode_path,
842 }
843 try:
844 flags = _classify_pyc(data, fullname, exc_details)
845 bytes_data = memoryview(data)[16:]
846 hash_based = flags & 0b1 != 0
847 if hash_based:
848 check_source = flags & 0b10 != 0
849 if (_imp.check_hash_based_pycs != 'never' and
850 (check_source or
851 _imp.check_hash_based_pycs == 'always')):
852 source_bytes = self.get_data(source_path)
853 source_hash = _imp.source_hash(
854 _imp.pyc_magic_number_token,
855 source_bytes,
856 )
857 _validate_hash_pyc(data, source_hash, fullname,
858 exc_details)
859 else:
860 _validate_timestamp_pyc(
861 data,
862 source_mtime,
863 st['size'],
864 fullname,
865 exc_details,
866 )
867 except (ImportError, EOFError):

Callers 1

exec_moduleMethod · 0.45

Calls 12

path_statsMethod · 0.95
get_dataMethod · 0.95
source_to_codeMethod · 0.95
_cache_bytecodeMethod · 0.95
cache_from_sourceFunction · 0.85
_classify_pycFunction · 0.85
_validate_hash_pycFunction · 0.85
_validate_timestamp_pycFunction · 0.85
_compile_bytecodeFunction · 0.85
_code_to_hash_pycFunction · 0.85
_code_to_timestamp_pycFunction · 0.85
get_filenameMethod · 0.45

Tested by

no test coverage detected