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