xref: /freebsd/contrib/file/magic/Magdir/python (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
1
2#------------------------------------------------------------------------------
3# $File: python,v 1.45 2022/07/24 23:59:37 christos Exp $
4# python:  file(1) magic for python
5#
6# Outlook puts """ too for urgent messages
7# From: David Necas <yeti@physics.muni.cz>
8# often the module starts with a multiline string
90	string/t	"""	Python script text executable
10# MAGIC as specified in Python/import.c (1.0 to 3.7)
11# and in Lib/importlib/_bootstrap_external.py (3.5+)
12# two bytes of magic followed by "\r\n" in little endian order
130	belong		0x02099900	python 1.0 byte-compiled
14!:mime application/x-bytecode.python
150	belong		0x03099900	python 1.1/1.2 byte-compiled
16!:mime application/x-bytecode.python
170	belong		0x892e0d0a	python 1.3 byte-compiled
18!:mime application/x-bytecode.python
190	belong		0x04170d0a	python 1.4 byte-compiled
20!:mime application/x-bytecode.python
210	belong		0x994e0d0a	python 1.5 byte-compiled
22!:mime application/x-bytecode.python
230	belong		0xfcc40d0a	python 1.6 byte-compiled
24!:mime application/x-bytecode.python
250	belong		0xfdc40d0a	python 1.6 byte-compiled
26!:mime application/x-bytecode.python
270	belong		0x87c60d0a	python 2.0 byte-compiled
28!:mime application/x-bytecode.python
290	belong		0x88c60d0a	python 2.0 byte-compiled
30!:mime application/x-bytecode.python
310	belong		0x2aeb0d0a	python 2.1 byte-compiled
32!:mime application/x-bytecode.python
330	belong		0x2beb0d0a	python 2.1 byte-compiled
34!:mime application/x-bytecode.python
350	belong		0x2ded0d0a	python 2.2 byte-compiled
36!:mime application/x-bytecode.python
370	belong		0x2eed0d0a	python 2.2 byte-compiled
38!:mime application/x-bytecode.python
390	belong		0x3bf20d0a	python 2.3 byte-compiled
40!:mime application/x-bytecode.python
410	belong		0x3cf20d0a	python 2.3 byte-compiled
42!:mime application/x-bytecode.python
430	belong		0x45f20d0a	python 2.3 byte-compiled
44!:mime application/x-bytecode.python
450	belong		0x59f20d0a	python 2.4 byte-compiled
46!:mime application/x-bytecode.python
470	belong		0x63f20d0a	python 2.4 byte-compiled
48!:mime application/x-bytecode.python
490	belong		0x6df20d0a	python 2.4 byte-compiled
50!:mime application/x-bytecode.python
510	belong		0x6ef20d0a	python 2.4 byte-compiled
52!:mime application/x-bytecode.python
530	belong		0x77f20d0a	python 2.5 byte-compiled
54!:mime application/x-bytecode.python
550	belong		0x81f20d0a	python 2.5 byte-compiled
56!:mime application/x-bytecode.python
570	belong		0x8bf20d0a	python 2.5 byte-compiled
58!:mime application/x-bytecode.python
590	belong		0x8cf20d0a	python 2.5 byte-compiled
60!:mime application/x-bytecode.python
610	belong		0x95f20d0a	python 2.5 byte-compiled
62!:mime application/x-bytecode.python
630	belong		0x9ff20d0a	python 2.5 byte-compiled
64!:mime application/x-bytecode.python
650	belong		0xa9f20d0a	python 2.5 byte-compiled
66!:mime application/x-bytecode.python
670	belong		0xb3f20d0a	python 2.5 byte-compiled
68!:mime application/x-bytecode.python
690	belong		0xb4f20d0a	python 2.5 byte-compiled
70!:mime application/x-bytecode.python
710	belong		0xc7f20d0a	python 2.6 byte-compiled
72!:mime application/x-bytecode.python
730	belong		0xd1f20d0a	python 2.6 byte-compiled
74!:mime application/x-bytecode.python
750	belong		0xd2f20d0a	python 2.6 byte-compiled
76!:mime application/x-bytecode.python
770	belong		0xdbf20d0a	python 2.7 byte-compiled
78!:mime application/x-bytecode.python
790	belong		0xe5f20d0a	python 2.7 byte-compiled
80!:mime application/x-bytecode.python
810	belong		0xeff20d0a	python 2.7 byte-compiled
82!:mime application/x-bytecode.python
830	belong		0xf9f20d0a	python 2.7 byte-compiled
84!:mime application/x-bytecode.python
850	belong		0x03f30d0a	python 2.7 byte-compiled
86!:mime application/x-bytecode.python
870	belong		0x04f30d0a	python 2.7 byte-compiled
88!:mime application/x-bytecode.python
890	belong		0x0af30d0a	PyPy2.7 byte-compiled
90!:mime application/x-bytecode.python
910	belong		0xb80b0d0a	python 3.0 byte-compiled
92!:mime application/x-bytecode.python
930	belong		0xc20b0d0a	python 3.0 byte-compiled
94!:mime application/x-bytecode.python
950	belong		0xcc0b0d0a	python 3.0 byte-compiled
96!:mime application/x-bytecode.python
970	belong		0xd60b0d0a	python 3.0 byte-compiled
98!:mime application/x-bytecode.python
990	belong		0xe00b0d0a	python 3.0 byte-compiled
100!:mime application/x-bytecode.python
1010	belong		0xea0b0d0a	python 3.0 byte-compiled
102!:mime application/x-bytecode.python
1030	belong		0xf40b0d0a	python 3.0 byte-compiled
104!:mime application/x-bytecode.python
1050	belong		0xf50b0d0a	python 3.0 byte-compiled
106!:mime application/x-bytecode.python
1070	belong		0xff0b0d0a	python 3.0 byte-compiled
108!:mime application/x-bytecode.python
1090	belong		0x090c0d0a	python 3.0 byte-compiled
110!:mime application/x-bytecode.python
1110	belong		0x130c0d0a	python 3.0 byte-compiled
112!:mime application/x-bytecode.python
1130	belong		0x1d0c0d0a	python 3.0 byte-compiled
114!:mime application/x-bytecode.python
1150	belong		0x1f0c0d0a	python 3.0 byte-compiled
116!:mime application/x-bytecode.python
1170	belong		0x270c0d0a	python 3.0 byte-compiled
118!:mime application/x-bytecode.python
1190	belong		0x3b0c0d0a	python 3.0 byte-compiled
120!:mime application/x-bytecode.python
1210	belong		0x450c0d0a	python 3.1 byte-compiled
122!:mime application/x-bytecode.python
1230	belong		0x4f0c0d0a	python 3.1 byte-compiled
124!:mime application/x-bytecode.python
1250	belong		0x580c0d0a	python 3.2 byte-compiled
126!:mime application/x-bytecode.python
1270	belong		0x620c0d0a	python 3.2 byte-compiled
128!:mime application/x-bytecode.python
1290	belong		0x6c0c0d0a	python 3.2 byte-compiled
130!:mime application/x-bytecode.python
1310	belong		0x760c0d0a	python 3.3 byte-compiled
132!:mime application/x-bytecode.python
1330	belong		0x800c0d0a	python 3.3 byte-compiled
134!:mime application/x-bytecode.python
1350	belong		0x8a0c0d0a	python 3.3 byte-compiled
136!:mime application/x-bytecode.python
1370	belong		0x940c0d0a	python 3.3 byte-compiled
138!:mime application/x-bytecode.python
1390	belong		0x9e0c0d0a	python 3.3 byte-compiled
140!:mime application/x-bytecode.python
1410	belong		0xb20c0d0a	python 3.4 byte-compiled
142!:mime application/x-bytecode.python
1430	belong		0xbc0c0d0a	python 3.4 byte-compiled
144!:mime application/x-bytecode.python
1450	belong		0xc60c0d0a	python 3.4 byte-compiled
146!:mime application/x-bytecode.python
1470	belong		0xd00c0d0a	python 3.4 byte-compiled
148!:mime application/x-bytecode.python
1490	belong		0xda0c0d0a	python 3.4 byte-compiled
150!:mime application/x-bytecode.python
1510	belong		0xe40c0d0a	python 3.4 byte-compiled
152!:mime application/x-bytecode.python
1530	belong		0xee0c0d0a	python 3.4 byte-compiled
154!:mime application/x-bytecode.python
1550	belong		0xf80c0d0a	python 3.5.1- byte-compiled
156!:mime application/x-bytecode.python
1570	belong		0x020d0d0a	python 3.5.1- byte-compiled
158!:mime application/x-bytecode.python
1590	belong		0x0c0d0d0a	python 3.5.1- byte-compiled
160!:mime application/x-bytecode.python
1610	belong		0x160d0d0a	python 3.5.1- byte-compiled
162!:mime application/x-bytecode.python
1630	belong		0x170d0d0a	python 3.5.2+ byte-compiled
164!:mime application/x-bytecode.python
1650	belong		0x200d0d0a	python 3.6 byte-compiled
166!:mime application/x-bytecode.python
1670	belong		0x210d0d0a	python 3.6 byte-compiled
168!:mime application/x-bytecode.python
1690	belong		0x2a0d0d0a	python 3.6 byte-compiled
170!:mime application/x-bytecode.python
1710	belong		0x2b0d0d0a	python 3.6 byte-compiled
172!:mime application/x-bytecode.python
1730	belong		0x2c0d0d0a	python 3.6 byte-compiled
174!:mime application/x-bytecode.python
1750	belong		0x2d0d0d0a	python 3.6 byte-compiled
176!:mime application/x-bytecode.python
1770	belong		0x2f0d0d0a	python 3.6 byte-compiled
178!:mime application/x-bytecode.python
1790	belong		0x300d0d0a	python 3.6 byte-compiled
180!:mime application/x-bytecode.python
1810	belong		0x310d0d0a	python 3.6 byte-compiled
182!:mime application/x-bytecode.python
1830	belong		0x320d0d0a	python 3.6 byte-compiled
184!:mime application/x-bytecode.python
1850	belong		0x330d0d0a	python 3.6 byte-compiled
186!:mime application/x-bytecode.python
1870	belong		0x3e0d0d0a	python 3.7 byte-compiled
188!:mime application/x-bytecode.python
1890	belong		0x3f0d0d0a	python 3.7 byte-compiled
190!:mime application/x-bytecode.python
191
192# magic 3392+ implements PEP 552: Deterministic pycs
1930	name		pyc-pep552
194# the flag field determines how .pyc validity is checked
195>4	ulelong&1	0		timestamp-based,
196>>8	uledate		x		.py timestamp: %s UTC,
197>>12	ulelong		x		.py size: %d bytes
198>4	ulelong&1	!0		hash-based, check-source flag
199>>4	ulelong&2	0		unset,
200>>4	ulelong&2	!0		set,
201>>8	ulequad		x		hash: 0x%llx
202
203# uleshort magic followed by \x0d\0xa
2042		string		\x0d\x0a
205# extra check: only two bits of flag field are currently used
206>4		ulelong		<0x4
207# \x0d as part of magic should suffice till Python 3.14 (magic 3600)
208>>1		ubyte		0x0d		Byte-compiled Python module for
209!:mime application/x-bytecode.python
210# now look at the magic number to determine the version
211>>>0		uleshort	<3400		CPython 3.7,
212>>>0		default		x
213>>>>0		uleshort	<3420		CPython 3.8,
214>>>>0		default		x
215>>>>>0		uleshort	<3430		CPython 3.9,
216>>>>>0		default		x
217>>>>>>0		uleshort	<3450		CPython 3.10,
218>>>>>>0		default		x
219>>>>>>>0	uleshort	<3500		CPython 3.11,
220>>>>>>>0	default		x		CPython 3.12 or newer,
221>>>0		use		pyc-pep552
222>>0		uleshort	240		Byte-compiled Python module for PyPy3.7,
223!:mime application/x-bytecode.python
224>>>0		use		pyc-pep552
225>>0		uleshort	256		Byte-compiled Python module for PyPy3.8,
226!:mime application/x-bytecode.python
227>>>0		use		pyc-pep552
228>>0		uleshort	336		Byte-compiled Python module for PyPy3.9,
229!:mime application/x-bytecode.python
230>>>0		use		pyc-pep552
231
2320	search/1/w	#!\040/usr/bin/python	Python script text executable
233!:strength + 15
234!:mime text/x-script.python
2350	search/1/w	#!\040/usr/local/bin/python	Python script text executable
236!:strength + 15
237!:mime text/x-script.python
2380	search/10/w	#!\040/usr/bin/env\040python	Python script text executable
239!:strength + 15
240!:mime text/x-script.python
241
242
243# from module.submodule import func1, func2
2440	search/8192	import
245>0	regex		\^from[\040\t]+([A-Za-z0-9_]|\\.)+[\040\t]+import.*$	Python script text executable
246!:strength + 15
247!:mime text/x-script.python
248
249# def __init__ (self, ...):
2500	search/4096	def\ __init__
251>&0	search/64 self	Python script text executable
252!:strength + 15
253!:mime text/x-script.python
254
255# if __name__ == "__main__":
2560 search/4096 if\ __name__
257>&0 search/64 '__main__'	Python script text executable
258>&0 search/64 "__main__"	Python script text executable
259!:strength + 15
260!:mime text/x-script.python
261
262# import module [as abrev]
2630	search/8192	import
264>0	regex	\^import\ [_[:alpha:]]+\ as\ [[:alpha:]][[:space:]]*$ Python script text executable
265!:mime text/x-script.python
266
267# comments
268#0	search/4096	'''
269#>&0	regex	.*'''$	Python script text executable
270#!:mime text/x-script.python
271
272#0	search/4096	"""
273#>&0	regex	.*"""$	Python script text executable
274#!:mime text/x-script.python
275
276# try:
277# except: or finally:
278# block
2790	search/4096	try:
280>&0	regex	\^[[:space:]]*except.*:$	Python script text executable
281!:strength + 15
282!:mime text/x-script.python
283>&0	search/4096	finally:	Python script text executable
284!:mime text/x-script.python
285
286# class name[(base classes,)]: [pass]
2870	search/8192	class
288>0	regex	\^class\ [_[:alpha:]]+(\\(.*\\))?(\ )*:([\ \t]+pass)?$		Python script text executable
289!:strength + 15
290!:mime text/x-script.python
291
292# def name(*args, **kwargs):
2930	search/8192	def\
294>0	regex	 \^[[:space:]]{0,50}def\ {1,50}[_a-zA-Z]{1,100}
295>>&0	regex	 \\(([[:alpha:]*_,\ ]){0,255}\\):$ Python script text executable
296!:strength + 15
297!:mime text/x-script.python
298
299# https://numpy.org/devdocs/reference/generated/numpy.lib.format.html
3000	string	\223NUMPY		NumPy data file
301!:mime  application/x-numpy-data
302>6	byte	x			\b, version %d
303>7	byte	x			\b.%d
304#>8	leshort	x			\b, header length=%d
305>10	string	x			\b, description %s
306