(self, pathname, fullpath, fullname, data)
| 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. |
| 693 | def _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 |
no test coverage detected
searching dependent graphs…