python 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #------------------------------------------------------------------------------
  2. # $File: python,v 1.45 2022/07/24 23:59:37 christos Exp $
  3. # python: file(1) magic for python
  4. #
  5. # Outlook puts """ too for urgent messages
  6. # From: David Necas <yeti@physics.muni.cz>
  7. # often the module starts with a multiline string
  8. 0 string/t """ Python script text executable
  9. # MAGIC as specified in Python/import.c (1.0 to 3.7)
  10. # and in Lib/importlib/_bootstrap_external.py (3.5+)
  11. # two bytes of magic followed by "\r\n" in little endian order
  12. 0 belong 0x02099900 python 1.0 byte-compiled
  13. !:mime application/x-bytecode.python
  14. 0 belong 0x03099900 python 1.1/1.2 byte-compiled
  15. !:mime application/x-bytecode.python
  16. 0 belong 0x892e0d0a python 1.3 byte-compiled
  17. !:mime application/x-bytecode.python
  18. 0 belong 0x04170d0a python 1.4 byte-compiled
  19. !:mime application/x-bytecode.python
  20. 0 belong 0x994e0d0a python 1.5 byte-compiled
  21. !:mime application/x-bytecode.python
  22. 0 belong 0xfcc40d0a python 1.6 byte-compiled
  23. !:mime application/x-bytecode.python
  24. 0 belong 0xfdc40d0a python 1.6 byte-compiled
  25. !:mime application/x-bytecode.python
  26. 0 belong 0x87c60d0a python 2.0 byte-compiled
  27. !:mime application/x-bytecode.python
  28. 0 belong 0x88c60d0a python 2.0 byte-compiled
  29. !:mime application/x-bytecode.python
  30. 0 belong 0x2aeb0d0a python 2.1 byte-compiled
  31. !:mime application/x-bytecode.python
  32. 0 belong 0x2beb0d0a python 2.1 byte-compiled
  33. !:mime application/x-bytecode.python
  34. 0 belong 0x2ded0d0a python 2.2 byte-compiled
  35. !:mime application/x-bytecode.python
  36. 0 belong 0x2eed0d0a python 2.2 byte-compiled
  37. !:mime application/x-bytecode.python
  38. 0 belong 0x3bf20d0a python 2.3 byte-compiled
  39. !:mime application/x-bytecode.python
  40. 0 belong 0x3cf20d0a python 2.3 byte-compiled
  41. !:mime application/x-bytecode.python
  42. 0 belong 0x45f20d0a python 2.3 byte-compiled
  43. !:mime application/x-bytecode.python
  44. 0 belong 0x59f20d0a python 2.4 byte-compiled
  45. !:mime application/x-bytecode.python
  46. 0 belong 0x63f20d0a python 2.4 byte-compiled
  47. !:mime application/x-bytecode.python
  48. 0 belong 0x6df20d0a python 2.4 byte-compiled
  49. !:mime application/x-bytecode.python
  50. 0 belong 0x6ef20d0a python 2.4 byte-compiled
  51. !:mime application/x-bytecode.python
  52. 0 belong 0x77f20d0a python 2.5 byte-compiled
  53. !:mime application/x-bytecode.python
  54. 0 belong 0x81f20d0a python 2.5 byte-compiled
  55. !:mime application/x-bytecode.python
  56. 0 belong 0x8bf20d0a python 2.5 byte-compiled
  57. !:mime application/x-bytecode.python
  58. 0 belong 0x8cf20d0a python 2.5 byte-compiled
  59. !:mime application/x-bytecode.python
  60. 0 belong 0x95f20d0a python 2.5 byte-compiled
  61. !:mime application/x-bytecode.python
  62. 0 belong 0x9ff20d0a python 2.5 byte-compiled
  63. !:mime application/x-bytecode.python
  64. 0 belong 0xa9f20d0a python 2.5 byte-compiled
  65. !:mime application/x-bytecode.python
  66. 0 belong 0xb3f20d0a python 2.5 byte-compiled
  67. !:mime application/x-bytecode.python
  68. 0 belong 0xb4f20d0a python 2.5 byte-compiled
  69. !:mime application/x-bytecode.python
  70. 0 belong 0xc7f20d0a python 2.6 byte-compiled
  71. !:mime application/x-bytecode.python
  72. 0 belong 0xd1f20d0a python 2.6 byte-compiled
  73. !:mime application/x-bytecode.python
  74. 0 belong 0xd2f20d0a python 2.6 byte-compiled
  75. !:mime application/x-bytecode.python
  76. 0 belong 0xdbf20d0a python 2.7 byte-compiled
  77. !:mime application/x-bytecode.python
  78. 0 belong 0xe5f20d0a python 2.7 byte-compiled
  79. !:mime application/x-bytecode.python
  80. 0 belong 0xeff20d0a python 2.7 byte-compiled
  81. !:mime application/x-bytecode.python
  82. 0 belong 0xf9f20d0a python 2.7 byte-compiled
  83. !:mime application/x-bytecode.python
  84. 0 belong 0x03f30d0a python 2.7 byte-compiled
  85. !:mime application/x-bytecode.python
  86. 0 belong 0x04f30d0a python 2.7 byte-compiled
  87. !:mime application/x-bytecode.python
  88. 0 belong 0x0af30d0a PyPy2.7 byte-compiled
  89. !:mime application/x-bytecode.python
  90. 0 belong 0xb80b0d0a python 3.0 byte-compiled
  91. !:mime application/x-bytecode.python
  92. 0 belong 0xc20b0d0a python 3.0 byte-compiled
  93. !:mime application/x-bytecode.python
  94. 0 belong 0xcc0b0d0a python 3.0 byte-compiled
  95. !:mime application/x-bytecode.python
  96. 0 belong 0xd60b0d0a python 3.0 byte-compiled
  97. !:mime application/x-bytecode.python
  98. 0 belong 0xe00b0d0a python 3.0 byte-compiled
  99. !:mime application/x-bytecode.python
  100. 0 belong 0xea0b0d0a python 3.0 byte-compiled
  101. !:mime application/x-bytecode.python
  102. 0 belong 0xf40b0d0a python 3.0 byte-compiled
  103. !:mime application/x-bytecode.python
  104. 0 belong 0xf50b0d0a python 3.0 byte-compiled
  105. !:mime application/x-bytecode.python
  106. 0 belong 0xff0b0d0a python 3.0 byte-compiled
  107. !:mime application/x-bytecode.python
  108. 0 belong 0x090c0d0a python 3.0 byte-compiled
  109. !:mime application/x-bytecode.python
  110. 0 belong 0x130c0d0a python 3.0 byte-compiled
  111. !:mime application/x-bytecode.python
  112. 0 belong 0x1d0c0d0a python 3.0 byte-compiled
  113. !:mime application/x-bytecode.python
  114. 0 belong 0x1f0c0d0a python 3.0 byte-compiled
  115. !:mime application/x-bytecode.python
  116. 0 belong 0x270c0d0a python 3.0 byte-compiled
  117. !:mime application/x-bytecode.python
  118. 0 belong 0x3b0c0d0a python 3.0 byte-compiled
  119. !:mime application/x-bytecode.python
  120. 0 belong 0x450c0d0a python 3.1 byte-compiled
  121. !:mime application/x-bytecode.python
  122. 0 belong 0x4f0c0d0a python 3.1 byte-compiled
  123. !:mime application/x-bytecode.python
  124. 0 belong 0x580c0d0a python 3.2 byte-compiled
  125. !:mime application/x-bytecode.python
  126. 0 belong 0x620c0d0a python 3.2 byte-compiled
  127. !:mime application/x-bytecode.python
  128. 0 belong 0x6c0c0d0a python 3.2 byte-compiled
  129. !:mime application/x-bytecode.python
  130. 0 belong 0x760c0d0a python 3.3 byte-compiled
  131. !:mime application/x-bytecode.python
  132. 0 belong 0x800c0d0a python 3.3 byte-compiled
  133. !:mime application/x-bytecode.python
  134. 0 belong 0x8a0c0d0a python 3.3 byte-compiled
  135. !:mime application/x-bytecode.python
  136. 0 belong 0x940c0d0a python 3.3 byte-compiled
  137. !:mime application/x-bytecode.python
  138. 0 belong 0x9e0c0d0a python 3.3 byte-compiled
  139. !:mime application/x-bytecode.python
  140. 0 belong 0xb20c0d0a python 3.4 byte-compiled
  141. !:mime application/x-bytecode.python
  142. 0 belong 0xbc0c0d0a python 3.4 byte-compiled
  143. !:mime application/x-bytecode.python
  144. 0 belong 0xc60c0d0a python 3.4 byte-compiled
  145. !:mime application/x-bytecode.python
  146. 0 belong 0xd00c0d0a python 3.4 byte-compiled
  147. !:mime application/x-bytecode.python
  148. 0 belong 0xda0c0d0a python 3.4 byte-compiled
  149. !:mime application/x-bytecode.python
  150. 0 belong 0xe40c0d0a python 3.4 byte-compiled
  151. !:mime application/x-bytecode.python
  152. 0 belong 0xee0c0d0a python 3.4 byte-compiled
  153. !:mime application/x-bytecode.python
  154. 0 belong 0xf80c0d0a python 3.5.1- byte-compiled
  155. !:mime application/x-bytecode.python
  156. 0 belong 0x020d0d0a python 3.5.1- byte-compiled
  157. !:mime application/x-bytecode.python
  158. 0 belong 0x0c0d0d0a python 3.5.1- byte-compiled
  159. !:mime application/x-bytecode.python
  160. 0 belong 0x160d0d0a python 3.5.1- byte-compiled
  161. !:mime application/x-bytecode.python
  162. 0 belong 0x170d0d0a python 3.5.2+ byte-compiled
  163. !:mime application/x-bytecode.python
  164. 0 belong 0x200d0d0a python 3.6 byte-compiled
  165. !:mime application/x-bytecode.python
  166. 0 belong 0x210d0d0a python 3.6 byte-compiled
  167. !:mime application/x-bytecode.python
  168. 0 belong 0x2a0d0d0a python 3.6 byte-compiled
  169. !:mime application/x-bytecode.python
  170. 0 belong 0x2b0d0d0a python 3.6 byte-compiled
  171. !:mime application/x-bytecode.python
  172. 0 belong 0x2c0d0d0a python 3.6 byte-compiled
  173. !:mime application/x-bytecode.python
  174. 0 belong 0x2d0d0d0a python 3.6 byte-compiled
  175. !:mime application/x-bytecode.python
  176. 0 belong 0x2f0d0d0a python 3.6 byte-compiled
  177. !:mime application/x-bytecode.python
  178. 0 belong 0x300d0d0a python 3.6 byte-compiled
  179. !:mime application/x-bytecode.python
  180. 0 belong 0x310d0d0a python 3.6 byte-compiled
  181. !:mime application/x-bytecode.python
  182. 0 belong 0x320d0d0a python 3.6 byte-compiled
  183. !:mime application/x-bytecode.python
  184. 0 belong 0x330d0d0a python 3.6 byte-compiled
  185. !:mime application/x-bytecode.python
  186. 0 belong 0x3e0d0d0a python 3.7 byte-compiled
  187. !:mime application/x-bytecode.python
  188. 0 belong 0x3f0d0d0a python 3.7 byte-compiled
  189. !:mime application/x-bytecode.python
  190. # magic 3392+ implements PEP 552: Deterministic pycs
  191. 0 name pyc-pep552
  192. # the flag field determines how .pyc validity is checked
  193. >4 ulelong&1 0 timestamp-based,
  194. >>8 uledate x .py timestamp: %s UTC,
  195. >>12 ulelong x .py size: %d bytes
  196. >4 ulelong&1 !0 hash-based, check-source flag
  197. >>4 ulelong&2 0 unset,
  198. >>4 ulelong&2 !0 set,
  199. >>8 ulequad x hash: 0x%llx
  200. # uleshort magic followed by \x0d\0xa
  201. 2 string \x0d\x0a
  202. # extra check: only two bits of flag field are currently used
  203. >4 ulelong <0x4
  204. # \x0d as part of magic should suffice till Python 3.14 (magic 3600)
  205. >>1 ubyte 0x0d Byte-compiled Python module for
  206. !:mime application/x-bytecode.python
  207. # now look at the magic number to determine the version
  208. >>>0 uleshort <3400 CPython 3.7,
  209. >>>0 default x
  210. >>>>0 uleshort <3420 CPython 3.8,
  211. >>>>0 default x
  212. >>>>>0 uleshort <3430 CPython 3.9,
  213. >>>>>0 default x
  214. >>>>>>0 uleshort <3450 CPython 3.10,
  215. >>>>>>0 default x
  216. >>>>>>>0 uleshort <3500 CPython 3.11,
  217. >>>>>>>0 default x CPython 3.12 or newer,
  218. >>>0 use pyc-pep552
  219. >>0 uleshort 240 Byte-compiled Python module for PyPy3.7,
  220. !:mime application/x-bytecode.python
  221. >>>0 use pyc-pep552
  222. >>0 uleshort 256 Byte-compiled Python module for PyPy3.8,
  223. !:mime application/x-bytecode.python
  224. >>>0 use pyc-pep552
  225. >>0 uleshort 336 Byte-compiled Python module for PyPy3.9,
  226. !:mime application/x-bytecode.python
  227. >>>0 use pyc-pep552
  228. 0 search/1/w #!\040/usr/bin/python Python script text executable
  229. !:strength + 15
  230. !:mime text/x-script.python
  231. 0 search/1/w #!\040/usr/local/bin/python Python script text executable
  232. !:strength + 15
  233. !:mime text/x-script.python
  234. 0 search/10/w #!\040/usr/bin/env\040python Python script text executable
  235. !:strength + 15
  236. !:mime text/x-script.python
  237. # from module.submodule import func1, func2
  238. 0 search/8192 import
  239. >0 regex \^from[\040\t]+([A-Za-z0-9_]|\\.)+[\040\t]+import.*$ Python script text executable
  240. !:strength + 15
  241. !:mime text/x-script.python
  242. # def __init__ (self, ...):
  243. 0 search/4096 def\ __init__
  244. >&0 search/64 self Python script text executable
  245. !:strength + 15
  246. !:mime text/x-script.python
  247. # if __name__ == "__main__":
  248. 0 search/4096 if\ __name__
  249. >&0 search/64 '__main__' Python script text executable
  250. >&0 search/64 "__main__" Python script text executable
  251. !:strength + 15
  252. !:mime text/x-script.python
  253. # import module [as abrev]
  254. 0 search/8192 import
  255. >0 regex \^import\ [_[:alpha:]]+\ as\ [[:alpha:]][[:space:]]*$ Python script text executable
  256. !:mime text/x-script.python
  257. # comments
  258. #0 search/4096 '''
  259. #>&0 regex .*'''$ Python script text executable
  260. #!:mime text/x-script.python
  261. #0 search/4096 """
  262. #>&0 regex .*"""$ Python script text executable
  263. #!:mime text/x-script.python
  264. # try:
  265. # except: or finally:
  266. # block
  267. 0 search/4096 try:
  268. >&0 regex \^[[:space:]]*except.*:$ Python script text executable
  269. !:strength + 15
  270. !:mime text/x-script.python
  271. >&0 search/4096 finally: Python script text executable
  272. !:mime text/x-script.python
  273. # class name[(base classes,)]: [pass]
  274. 0 search/8192 class
  275. >0 regex \^class\ [_[:alpha:]]+(\\(.*\\))?(\ )*:([\ \t]+pass)?$ Python script text executable
  276. !:strength + 15
  277. !:mime text/x-script.python
  278. # def name(*args, **kwargs):
  279. 0 search/8192 def\
  280. >0 regex \^[[:space:]]{0,50}def\ {1,50}[_a-zA-Z]{1,100}
  281. >>&0 regex \\(([[:alpha:]*_,\ ]){0,255}\\):$ Python script text executable
  282. !:strength + 15
  283. !:mime text/x-script.python
  284. # https://numpy.org/devdocs/reference/generated/numpy.lib.format.html
  285. 0 string \223NUMPY NumPy data file
  286. !:mime application/x-numpy-data
  287. >6 byte x \b, version %d
  288. >7 byte x \b.%d
  289. #>8 leshort x \b, header length=%d
  290. >10 string x \b, description %s