<div dir="ltr"><div>I'm fine with adding an API, though I don't think that an API that knows about all current (historic) and future formats belongs in importlib.util -- that module only concerns itself with the *current* format.<br><br></div>In terms of the API design I'd make take an IO[bytes] and just read and parse the header, so after that you can use marshal.load() straight from the file object. File size, mtime and bitfield should be represented as ints (the parser should take care of endianness).The hash should be a bytes.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 3, 2017 at 8:24 AM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, 3 Oct 2017 08:15:04 -0700<br>
Guido van Rossum <<a href="mailto:gvanrossum@gmail.com">gvanrossum@gmail.com</a>> wrote:<br>
> It's really not that hard. You just check the magic number and if it's the<br>
> new one, skip 4 words. No need to understand the internals of the header.<br>
<br>
</span>Still, I agree with Barry that an API would be nice.<br>
<br>
Regards<br>
<span class="HOEnZb"><font color="#888888"><br>
Antoine.<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> On Oct 3, 2017 08:06, "Barry Warsaw" <<a href="mailto:barry@python.org">barry@python.org</a>> wrote:<br>
><br>
> > 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<br>
> > 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/" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/</a><br>
> > guido%<a href="http://40python.org" rel="noreferrer" target="_blank">40python.org</a><br>
> ><br>
><br>
<br>
<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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>