PATCH: add support for Python 3 bytecode files

David Malcolm dmalcolm at redhat.com
Mon Oct 26 22:26:31 EET 2009


Attached is a patch to file-5.0.3 to add support for python 3 bytecode
files.

With this patch, "file" can detect a python 3 bytecode file:
$ file /usr/lib/python3.1/re.pyo
/usr/lib/python3.1/re.pyo: python 3.1 byte-compiled

I also slightly fixed-up an out-of-date comment

Caveats: 
(i) patch is actually against Fedora's somewhat patched downstream
file-5.0.3; is there a SCM I should be generating a patch against?)
(ii) only tested with 3.1; I calculated up the value for 3.0 from the source
in python's py3k branch's Python/import.c:
[snip]
       Python 3.0a5: 3130 (lexical exception stacking, including POP_EXCEPT)
[snip]
       Python 3.1a0: 3150 (optimize conditional branches:
      introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE)
[snip]

Note that the value has 1 added to it in py3k's _PyImport_Init,
giving:
  python 3.0: magic=3131 = 0x0c3b (hex) =  0x3b 0x0c 0xc0 0x0a (header)
and 
  python 3.1: magic=3151 = 0x0c4f (hex) =  0x4f 0x0c 0x0d 0x0a (header)  

FWIW I'm tracking this downstream here:
https://bugzilla.redhat.com/show_bug.cgi?id=531082

Hope this is helpful
Dave
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file-5.03-add-python-3.patch
Type: text/x-patch
Size: 1062 bytes
Desc: not available
URL: <http://mx.gw.com/pipermail/file/attachments/20091026/e2700f2e/attachment.bin>


More information about the File mailing list