(self, pathname, fullpath, fullname, data)
| 639 | # and return the code object. Raises ImportError it the magic word doesn't |
| 640 | # match, or if the recorded .py[co] metadata does not match the source. |
| 641 | def _unmarshal_code(self, pathname, fullpath, fullname, data): |
| 642 | exc_details = { |
| 643 | 'name': fullname, |
| 644 | 'path': fullpath, |
| 645 | } |
| 646 | |
| 647 | flags = _bootstrap_external._classify_pyc(data, fullname, exc_details) |
| 648 | |
| 649 | hash_based = flags & 0b1 != 0 |
| 650 | if hash_based: |
| 651 | check_source = flags & 0b10 != 0 |
| 652 | if (_imp.check_hash_based_pycs != 'never' and |
| 653 | (check_source or _imp.check_hash_based_pycs == 'always')): |
| 654 | source_bytes = _get_pyc_source(self, fullpath) |
| 655 | if source_bytes is not None: |
| 656 | source_hash = _imp.source_hash( |
| 657 | _bootstrap_external._RAW_MAGIC_NUMBER, |
| 658 | source_bytes, |
| 659 | ) |
| 660 | |
| 661 | _bootstrap_external._validate_hash_pyc( |
| 662 | data, source_hash, fullname, exc_details) |
| 663 | else: |
| 664 | source_mtime, source_size = \ |
| 665 | _get_mtime_and_size_of_source(self, fullpath) |
| 666 | |
| 667 | if source_mtime: |
| 668 | # We don't use _bootstrap_external._validate_timestamp_pyc |
| 669 | # to allow for a more lenient timestamp check. |
| 670 | if (not _eq_mtime(_unpack_uint32(data[8:12]), source_mtime) or |
| 671 | _unpack_uint32(data[12:16]) != source_size): |
| 672 | _bootstrap._verbose_message( |
| 673 | f'bytecode is stale for {fullname!r}') |
| 674 | return None |
| 675 | |
| 676 | code = marshal.loads(data[16:]) |
| 677 | if not isinstance(code, _code_type): |
| 678 | raise TypeError(f'compiled module {pathname!r} is not a code object') |
| 679 | return code |
| 680 | |
| 681 | _code_type = type(_unmarshal_code.__code__) |
| 682 |
no test coverage detected