Unix file(1) command identifing .pyc

Sean 'Shaleh' Perry shalehperry at attbi.com
Tue May 28 17:58:52 EDT 2002


On 28-May-2002 drt wrote:
> The  Unix file  command  identifies  the  type  of  a file using,
> among other tests, a test for whether the file begins with  a  certain
> magic  number. The actual version (3.38) can't identify compiled
> python code. I have added the macic numbers for python and
> successfully tested on 2.2.1 and 2.1.3 on i386 and PowerPC machines.
> Perhaps somebody has acient Python versions or unusual machines to
> further test this.
> 
> The magic file can be found at
> http://c0re.jp/c0de/misc/file-3.38-magic-python
> 
> Usage example:
> $ curl -O http://c0re.jp/c0de/misc/file-3.38-magic-python
> $ file -m file-3.38-magic-python /usr/local/lib/python*/cgi.pyc 
> file: Using regular magic file `file-3.38-magic-python'
> /usr/local/lib/python2.1/cgi.pyc: python 2.1.x compiled bytecode
> /usr/local/lib/python2.2/cgi.pyc: python 2.2.x compiled bytecode
> $ 
> 

$ file popen2.pyc
popen2.pyc: python (2.1) compiled

is what i get on my Debian box.

# often the module starts with a multiline string
0       string          """     a python script text executable
# MAGIC as specified in Python/import.c
# ( YEAR - 1995 ) + MONTH  + DAY (little endian followed by "\r\n"
# 20121 = 21/01/1997 
0       belong          0x994e0d0a      python (1.5.2/1.6) compiled
# 50823 = 23/08/2000
0       belong          0x87c60d0a      python (2.0) compiled
# 60202 = 02/02/2001
0       belong          0x2aeb0d0a      python (2.1) compiled
# 60717 = 17/01/2001
0       belong          0x2ded0d0a      python (2.2) compiled

is the contents of our magic file.





More information about the Python-list mailing list