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

Function _classify_pyc

Lib/importlib/_bootstrap_external.py:424–454  ·  view source on GitHub ↗

Perform basic validity checking of a pyc header and return the flags field, which determines how the pyc should be further validated against the source. *data* is the contents of the pyc file. (Only the first 16 bytes are required, though.) *name* is the name of the module being im

(data, name, exc_details)

Source from the content-addressed store, hash-verified

422
423
424def _classify_pyc(data, name, exc_details):
425 """Perform basic validity checking of a pyc header and return the flags field,
426 which determines how the pyc should be further validated against the source.
427
428 *data* is the contents of the pyc file. (Only the first 16 bytes are
429 required, though.)
430
431 *name* is the name of the module being imported. It is used for logging.
432
433 *exc_details* is a dictionary passed to ImportError if it raised for
434 improved debugging.
435
436 ImportError is raised when the magic number is incorrect or when the flags
437 field is invalid. EOFError is raised when the data is found to be truncated.
438
439 """
440 magic = data[:4]
441 if magic != MAGIC_NUMBER:
442 message = f'bad magic number in {name!r}: {magic!r}'
443 _bootstrap._verbose_message('{}', message)
444 raise ImportError(message, **exc_details)
445 if len(data) < 16:
446 message = f'reached EOF while reading pyc header of {name!r}'
447 _bootstrap._verbose_message('{}', message)
448 raise EOFError(message)
449 flags = _unpack_uint32(data[4:8])
450 # Only the first two flags are defined.
451 if flags & ~0b11:
452 message = f'invalid flags {flags!r} in {name!r}'
453 raise ImportError(message, **exc_details)
454 return flags
455
456
457def _validate_timestamp_pyc(data, source_mtime, source_size, name,

Callers 2

get_codeMethod · 0.70
get_codeMethod · 0.70

Calls 2

lenFunction · 0.85
_unpack_uint32Function · 0.70

Tested by

no test coverage detected