PATCH: add support for Python 3 bytecode files

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

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

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

(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:
       Python 3.0a5: 3130 (lexical exception stacking, including POP_EXCEPT)
       Python 3.1a0: 3150 (optimize conditional branches:
      introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE)

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

FWIW I'm tracking this downstream here:

Hope this is helpful
-------------- 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: <>

More information about the File mailing list