<div dir="auto">It's really not that hard. You just check the magic number and if it's the new one, skip 4 words. No need to understand the internals of the header.</div><div class="gmail_extra"><br><div class="gmail_quote">On Oct 3, 2017 08:06, "Barry Warsaw" <<a href="mailto:barry@python.org">barry@python.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Guido van Rossum wrote:<br>
> There have been no further comments. PEP 552 is now accepted.<br>
><br>
> Congrats, Benjamin! Go ahead and send your implementation for review.Oops.<br>
> Let me try that again.<br>
<br>
While I'm very glad PEP 552 has been accepted, it occurs to me that it<br>
will now be more difficult to parse the various pyc file formats from<br>
Python.  E.g. I used to be able to just open the pyc in binary mode,<br>
read all the bytes, and then lop off the first 8 bytes to get to the<br>
code object.  With the addition of the source file size, I now have to<br>
(maybe, if I have to also read old-style pyc files) lop off the front 12<br>
bytes, but okay.<br>
<br>
With PEP 552, I have to do a lot more work to just get at the code<br>
object.  How many bytes at the front of the file do I need to skip past?<br>
 What about all the metadata at the front of the pyc, how do I interpret<br>
that if I want to get at it from Python code?<br>
<br>
Should the PEP 552 implementation add an API, probably to<br>
importlib.util, that would understand all current and future formats?<br>
Something like this perhaps?<br>
<br>
class PycFileSpec:<br>
    magic_number: bytes<br>
    timestamp: Optional[bytes] # maybe an int? datetime?<br>
    source_size: Optional[bytes]<br>
    bit_field: Optional[bytes]<br>
    code_object: bytes<br>
<br>
def parse_pyc(path: str) -> PycFileSpec:<br>
<br>
Cheers,<br>
-Barry<br>
<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>guido%40python.org</a><br>
</blockquote></div></div>