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

Function _validate_hash_pyc

Lib/importlib/_bootstrap_external.py:474–495  ·  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

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

Callers 1

get_codeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…