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

Function _validate_hash_pyc

Lib/importlib/_bootstrap_external.py:485–506  ·  view source on GitHub ↗

Validate a hash-based pyc by checking the real source hash against the one in the pyc header. *data* is the contents of the pyc file. (Only the first 16 bytes are required.) *source_hash* is the importlib.util.source_hash() of the source file. *name* is the name of the module

(data, source_hash, name, exc_details)

Source from the content-addressed store, hash-verified

483
484
485def _validate_hash_pyc(data, source_hash, name, exc_details):
486 """Validate a hash-based pyc by checking the real source hash against the one in
487 the pyc header.
488
489 *data* is the contents of the pyc file. (Only the first 16 bytes are
490 required.)
491
492 *source_hash* is the importlib.util.source_hash() of the source file.
493
494 *name* is the name of the module being imported. It is used for logging.
495
496 *exc_details* is a dictionary passed to ImportError if it raised for
497 improved debugging.
498
499 An ImportError is raised if the bytecode is stale.
500
501 """
502 if data[8:16] != source_hash:
503 raise ImportError(
504 f'hash in bytecode doesn\'t match hash of source {name!r}',
505 **exc_details,
506 )
507
508
509def _compile_bytecode(data, name=None, bytecode_path=None, source_path=None):

Callers 1

get_codeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected