MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_code

Method get_code

Lib/importlib/_bootstrap_external.py:826–909  ·  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

824 dont_inherit=True, optimize=_optimize)
825
826 def get_code(self, fullname):
827 """Concrete implementation of InspectLoader.get_code.
828
829 Reading of bytecode requires path_stats to be implemented. To write
830 bytecode, set_data must also be implemented.
831
832 """
833 source_path = self.get_filename(fullname)
834 source_mtime = None
835 source_bytes = None
836 source_hash = None
837 hash_based = False
838 check_source = True
839 try:
840 bytecode_path = cache_from_source(source_path)
841 except NotImplementedError:
842 bytecode_path = None
843 else:
844 try:
845 st = self.path_stats(source_path)
846 except OSError:
847 pass
848 else:
849 source_mtime = int(st['mtime'])
850 try:
851 data = self.get_data(bytecode_path)
852 except OSError:
853 pass
854 else:
855 exc_details = {
856 'name': fullname,
857 'path': bytecode_path,
858 }
859 try:
860 flags = _classify_pyc(data, fullname, exc_details)
861 bytes_data = memoryview(data)[16:]
862 hash_based = flags & 0b1 != 0
863 if hash_based:
864 check_source = flags & 0b10 != 0
865 if (_imp.check_hash_based_pycs != 'never' and
866 (check_source or
867 _imp.check_hash_based_pycs == 'always')):
868 source_bytes = self.get_data(source_path)
869 source_hash = _imp.source_hash(
870 _imp.pyc_magic_number_token,
871 source_bytes,
872 )
873 _validate_hash_pyc(data, source_hash, fullname,
874 exc_details)
875 else:
876 _validate_timestamp_pyc(
877 data,
878 source_mtime,
879 st['size'],
880 fullname,
881 exc_details,
882 )
883 except (ImportError, EOFError):

Callers 1

exec_moduleMethod · 0.45

Calls 13

path_statsMethod · 0.95
get_dataMethod · 0.95
source_to_codeMethod · 0.95
_cache_bytecodeMethod · 0.95
lenFunction · 0.85
cache_from_sourceFunction · 0.70
_classify_pycFunction · 0.70
_validate_hash_pycFunction · 0.70
_validate_timestamp_pycFunction · 0.70
_compile_bytecodeFunction · 0.70
_code_to_hash_pycFunction · 0.70
_code_to_timestamp_pycFunction · 0.70

Tested by

no test coverage detected