(
fp: IO[bytes], source_stat: os.stat_result, co: types.CodeType
)
| 286 | |
| 287 | |
| 288 | def _write_pyc_fp( |
| 289 | fp: IO[bytes], source_stat: os.stat_result, co: types.CodeType |
| 290 | ) -> None: |
| 291 | # Technically, we don't have to have the same pyc format as |
| 292 | # (C)Python, since these "pycs" should never be seen by builtin |
| 293 | # import. However, there's little reason to deviate. |
| 294 | fp.write(importlib.util.MAGIC_NUMBER) |
| 295 | # https://www.python.org/dev/peps/pep-0552/ |
| 296 | if sys.version_info >= (3, 7): |
| 297 | flags = b"\x00\x00\x00\x00" |
| 298 | fp.write(flags) |
| 299 | # as of now, bytecode header expects 32-bit numbers for size and mtime (#4903) |
| 300 | mtime = int(source_stat.st_mtime) & 0xFFFFFFFF |
| 301 | size = source_stat.st_size & 0xFFFFFFFF |
| 302 | # "<LL" stands for 2 unsigned longs, little-endian. |
| 303 | fp.write(struct.pack("<LL", mtime, size)) |
| 304 | fp.write(marshal.dumps(co)) |
| 305 | |
| 306 | |
| 307 | if sys.platform == "win32": |
no test coverage detected