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

Function _unmarshal_code

Lib/zipimport.py:693–731  ·  view source on GitHub ↗
(self, pathname, fullpath, fullname, data)

Source from the content-addressed store, hash-verified

691# and return the code object. Raises ImportError it the magic word doesn't
692# match, or if the recorded .py[co] metadata does not match the source.
693def _unmarshal_code(self, pathname, fullpath, fullname, data):
694 exc_details = {
695 'name': fullname,
696 'path': fullpath,
697 }
698
699 flags = _bootstrap_external._classify_pyc(data, fullname, exc_details)
700
701 hash_based = flags & 0b1 != 0
702 if hash_based:
703 check_source = flags & 0b10 != 0
704 if (_imp.check_hash_based_pycs != 'never' and
705 (check_source or _imp.check_hash_based_pycs == 'always')):
706 source_bytes = _get_pyc_source(self, fullpath)
707 if source_bytes is not None:
708 source_hash = _imp.source_hash(
709 _imp.pyc_magic_number_token,
710 source_bytes,
711 )
712
713 _bootstrap_external._validate_hash_pyc(
714 data, source_hash, fullname, exc_details)
715 else:
716 source_mtime, source_size = \
717 _get_mtime_and_size_of_source(self, fullpath)
718
719 if source_mtime:
720 # We don't use _bootstrap_external._validate_timestamp_pyc
721 # to allow for a more lenient timestamp check.
722 if (not _eq_mtime(_unpack_uint32(data[8:12]), source_mtime) or
723 _unpack_uint32(data[12:16]) != source_size):
724 _bootstrap._verbose_message(
725 f'bytecode is stale for {fullname!r}')
726 return None
727
728 code = marshal.loads(data[16:])
729 if not isinstance(code, _code_type):
730 raise TypeError(f'compiled module {pathname!r} is not a code object')
731 return code
732
733_code_type = type(_unmarshal_code.__code__)
734

Callers 1

_get_module_codeFunction · 0.85

Calls 5

_get_pyc_sourceFunction · 0.85
_eq_mtimeFunction · 0.85
_unpack_uint32Function · 0.85
loadsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…