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)
| 411 | |
| 412 | |
| 413 | def _classify_pyc(data, name, exc_details): |
| 414 | """Perform basic validity checking of a pyc header and return the flags field, |
| 415 | which determines how the pyc should be further validated against the source. |
| 416 | |
| 417 | *data* is the contents of the pyc file. (Only the first 16 bytes are |
| 418 | required, though.) |
| 419 | |
| 420 | *name* is the name of the module being imported. It is used for logging. |
| 421 | |
| 422 | *exc_details* is a dictionary passed to ImportError if it raised for |
| 423 | improved debugging. |
| 424 | |
| 425 | ImportError is raised when the magic number is incorrect or when the flags |
| 426 | field is invalid. EOFError is raised when the data is found to be truncated. |
| 427 | |
| 428 | """ |
| 429 | magic = data[:4] |
| 430 | if magic != MAGIC_NUMBER: |
| 431 | message = f'bad magic number in {name!r}: {magic!r}' |
| 432 | _bootstrap._verbose_message('{}', message) |
| 433 | raise ImportError(message, **exc_details) |
| 434 | if len(data) < 16: |
| 435 | message = f'reached EOF while reading pyc header of {name!r}' |
| 436 | _bootstrap._verbose_message('{}', message) |
| 437 | raise EOFError(message) |
| 438 | flags = _unpack_uint32(data[4:8]) |
| 439 | # Only the first two flags are defined. |
| 440 | if flags & ~0b11: |
| 441 | message = f'invalid flags {flags!r} in {name!r}' |
| 442 | raise ImportError(message, **exc_details) |
| 443 | return flags |
| 444 | |
| 445 | |
| 446 | def _validate_timestamp_pyc(data, source_mtime, source_size, name, |
no test coverage detected
searching dependent graphs…