xref: /freebsd/contrib/file/magic/Magdir/python (revision ae316d1d1cffd71ab7751f94e10118777a88e027)
1
2#------------------------------------------------------------------------------
3# $File: python,v 1.47 2024/08/27 18:50:57 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>0	uleshort	x	(magic: %04d),
195# the flag field determines how .pyc validity is checked
196>4	ulelong&1	0		timestamp-based,
197>>8	uledate		x		.py timestamp: %s UTC,
198>>12	ulelong		x		.py size: %d bytes
199>4	ulelong&1	!0		hash-based, check-source flag
200>>4	ulelong&2	0		unset,
201>>4	ulelong&2	!0		set,
202>>8	ulequad		x		hash: 0x%llx
203
204# uleshort magic followed by \x0d\0xa
2052		string		\x0d\x0a
206# extra check: only two bits of flag field are currently used
207>4		ulelong		<0x4
208# \x0d as part of magic should suffice till Python 3.14 (magic 3600)
209>>1		ubyte		0x0d		Byte-compiled Python module for
210!:mime application/x-bytecode.python
211# now look at the magic number to determine the version
212>>>0		uleshort	<3400		CPython 3.7
213>>>0		default		x
214>>>>0		uleshort	<3420		CPython 3.8
215>>>>0		default		x
216>>>>>0		uleshort	<3430		CPython 3.9
217>>>>>0		default		x
218>>>>>>0		uleshort	<3450		CPython 3.10
219>>>>>>0		default		x
220>>>>>>>0	uleshort	<3500		CPython 3.11
221>>>>>>>0	default		x
222>>>>>>>>0	uleshort	<3550		CPython 3.12
223>>>>>>>>0	default		x
224>>>>>>>>>0	uleshort	<3600		CPython 3.13
225>>>>>>>>>0	default		x		CPython 3.14 or newer
226>>>0		use		pyc-pep552
227>>0		uleshort	240		Byte-compiled Python module for PyPy3.7
228!:mime application/x-bytecode.python
229>>>0		use		pyc-pep552
230>>0		uleshort	256		Byte-compiled Python module for PyPy3.8
231!:mime application/x-bytecode.python
232>>>0		use		pyc-pep552
233>>0		uleshort	336		Byte-compiled Python module for PyPy3.9
234!:mime application/x-bytecode.python
235>>>0		use		pyc-pep552
236
2370	search/1/w	#!\040/usr/bin/python	Python script text executable
238!:strength + 15
239!:mime text/x-script.python
2400	search/1/w	#!\040/usr/local/bin/python	Python script text executable
241!:strength + 15
242!:mime text/x-script.python
2430	search/10/w	#!\040/usr/bin/env\040python	Python script text executable
244!:strength + 15
245!:mime text/x-script.python
246
247
248# from module.submodule import func1, func2
2490	search/8192	import
250>0	regex		\^from[\040\t]+([A-Za-z0-9_]|\\.)+[\040\t]+import.*$	Python script text executable
251!:strength + 15
252!:mime text/x-script.python
253>0	regex		\^import\ [_[:alpha:]]+\ as\ [[:alpha:]][[:space:]]*$ Python script text executable
254!:mime text/x-script.python
255
256
257# def __init__ (self, ...):
2580	search/4096	def\ __init__
259>&0	search/64 self	Python script text executable
260!:strength + 15
261!:mime text/x-script.python
262
263# if __name__ == "__main__":
2640 search/4096 if\ __name__
265>&0 search/64 '__main__'	Python script text executable
266>&0 search/64 "__main__"	Python script text executable
267!:strength + 15
268!:mime text/x-script.python
269
270# comments
271#0	search/4096	'''
272#>&0	regex	.*'''$	Python script text executable
273#!:mime text/x-script.python
274
275#0	search/4096	"""
276#>&0	regex	.*"""$	Python script text executable
277#!:mime text/x-script.python
278
279# try:
280# except: or finally:
281# block
2820	search/4096	try:
283>&0	regex	\^[[:space:]]*except.*:$	Python script text executable
284!:strength + 15
285!:mime text/x-script.python
286>&0	search/4096	finally:	Python script text executable
287!:mime text/x-script.python
288
289# class name[(base classes,)]: [pass]
2900	search/8192	class
291>0	regex	\^class\ [_[:alpha:]]+(\\(.*\\))?(\ )*:([\ \t]+pass)?$		Python script text executable
292!:strength + 15
293!:mime text/x-script.python
294
295# def name(*args, **kwargs):
2960	search/8192	def\
297>0	regex	 \^[[:space:]]{0,50}def\ {1,50}[_a-zA-Z]{1,100}
298>>&0	regex	 \\(([[:alpha:]*_,\ ]){0,255}\\):$ Python script text executable
299!:strength + 15
300!:mime text/x-script.python
301
302# https://numpy.org/devdocs/reference/generated/numpy.lib.format.html
3030	string	\223NUMPY		NumPy data file
304!:mime  application/x-numpy-data
305>6	byte	x			\b, version %d
306>7	byte	x			\b.%d
307#>8	leshort	x			\b, header length=%d
308>10	string	x			\b, description %s
309