__init__.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. """
  2. Copyright (c) 2015-2017, 2020-2024 by Rocky Bernstein
  3. Copyright (c) 2000 by hartmut Goebel <h.goebel@crazy-compilers.com>
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. NB. This is not a masterpiece of software, but became more like a hack.
  16. Probably a complete rewrite would be sensefull. hG/2000-12-27
  17. """
  18. __docformat__ = "restructuredtext"
  19. # Export various things from the modules
  20. from xdis.bytecode import (
  21. Bytecode,
  22. get_instructions_bytes,
  23. list2bytecode,
  24. next_offset,
  25. offset2line,
  26. op_has_argument,
  27. )
  28. from xdis.codetype import (
  29. Code2,
  30. Code3,
  31. Code13,
  32. Code15,
  33. Code38,
  34. Code310,
  35. Code311,
  36. codeType2Portable,
  37. )
  38. from xdis.codetype.base import code_has_star_arg, code_has_star_star_arg, iscode
  39. from xdis.cross_dis import (
  40. code_info,
  41. extended_arg_val,
  42. findlabels,
  43. findlinestarts,
  44. format_code_info,
  45. get_code_object,
  46. get_jump_target_maps,
  47. instruction_size,
  48. op_size,
  49. pretty_flags as pretty_code_flags,
  50. show_code,
  51. )
  52. from xdis.disasm import (
  53. disassemble_file,
  54. disco_loop,
  55. disco_loop_asm_format,
  56. get_opcode,
  57. show_module_header,
  58. )
  59. from xdis.instruction import Instruction
  60. from xdis.lineoffsets import (
  61. LineOffsetInfo,
  62. LineOffsets,
  63. LineOffsetsCompact,
  64. lineoffsets_in_file,
  65. lineoffsets_in_module,
  66. )
  67. from xdis.load import (
  68. check_object_path,
  69. is_bytecode_extension,
  70. is_pypy,
  71. is_python_source,
  72. load_file,
  73. load_module,
  74. load_module_from_file_object,
  75. write_bytecode_file,
  76. )
  77. from xdis.magics import (
  78. PYTHON_MAGIC_INT,
  79. canonic_python_version,
  80. int2magic,
  81. magic2int,
  82. sysinfo2magic,
  83. )
  84. from xdis.op_imports import get_opcode_module
  85. from xdis.opcodes import (
  86. opcode_13,
  87. opcode_14,
  88. opcode_15,
  89. opcode_22,
  90. opcode_23,
  91. opcode_24,
  92. opcode_25,
  93. opcode_26,
  94. opcode_27,
  95. opcode_30,
  96. opcode_31,
  97. opcode_32,
  98. opcode_33,
  99. opcode_34,
  100. opcode_35,
  101. opcode_36,
  102. opcode_37,
  103. opcode_38,
  104. opcode_39,
  105. opcode_310,
  106. opcode_311,
  107. )
  108. from xdis.util import (
  109. CO_ABSOLUTE_IMPORT,
  110. CO_ASYNC_GENERATOR,
  111. CO_COROUTINE,
  112. CO_FUTURE_ANNOTATIONS,
  113. CO_FUTURE_BARRY_AS_DBFL,
  114. CO_FUTURE_DIVISION,
  115. CO_FUTURE_GENERATOR_STOP,
  116. CO_FUTURE_PRINT_FUNCTION,
  117. CO_FUTURE_UNICODE_LITERALS,
  118. CO_FUTURE_WITH_STATEMENT,
  119. CO_GENERATOR,
  120. CO_GENERATOR_ALLOWED,
  121. CO_ITERABLE_COROUTINE,
  122. CO_NESTED,
  123. CO_NEWLOCALS,
  124. CO_NOFREE,
  125. CO_OPTIMIZED,
  126. CO_VARARGS,
  127. CO_VARKEYWORDS,
  128. COMPILER_FLAG_BIT,
  129. COMPILER_FLAG_NAMES,
  130. PYPY_COMPILER_FLAG_NAMES,
  131. co_flags_is_async,
  132. code2num,
  133. )
  134. # This ensures __version__ will appear in pydoc
  135. from xdis.version import __version__ # noqa
  136. from xdis.version_info import (
  137. IS_GRAAL,
  138. IS_PYPY,
  139. PYTHON3,
  140. PYTHON_VERSION_STR,
  141. PYTHON_VERSION_TRIPLE,
  142. )
  143. __all__ = [
  144. # bytecode
  145. "Bytecode",
  146. "get_instructions_bytes",
  147. "list2bytecode",
  148. "next_offset",
  149. "offset2line",
  150. "op_has_argument",
  151. # codetype
  152. "CO_ABSOLUTE_IMPORT",
  153. "CO_ASYNC_GENERATOR",
  154. "CO_COROUTINE",
  155. "CO_FUTURE_ANNOTATIONS",
  156. "CO_FUTURE_BARRY_AS_DBFL",
  157. "CO_FUTURE_DIVISION",
  158. "CO_FUTURE_GENERATOR_STOP",
  159. "CO_FUTURE_PRINT_FUNCTION",
  160. "CO_FUTURE_UNICODE_LITERALS",
  161. "CO_FUTURE_WITH_STATEMENT",
  162. "CO_GENERATOR",
  163. "CO_GENERATOR_ALLOWED",
  164. "CO_ITERABLE_COROUTINE",
  165. "CO_NESTED",
  166. "CO_NEWLOCALS",
  167. "CO_NOFREE",
  168. "CO_OPTIMIZED",
  169. "CO_VARARGS",
  170. "CO_VARKEYWORDS",
  171. "Code13",
  172. "Code15",
  173. "Code2",
  174. "Code3",
  175. "Code310",
  176. "Code311",
  177. "Code38",
  178. "code_has_star_star_arg",
  179. "code_has_star_arg",
  180. "codeType2Portable",
  181. "iscode",
  182. # cross_dis
  183. "code_info",
  184. "extended_arg_val",
  185. "findlinestarts",
  186. "findlabels",
  187. "format_code_info",
  188. "get_code_object",
  189. "get_jump_target_maps",
  190. "instruction_size",
  191. "pretty_code_flags",
  192. "op_size",
  193. "show_code",
  194. # disasm
  195. "get_opcode",
  196. "show_module_header",
  197. "disco_loop",
  198. "disco_loop_asm_format",
  199. "disassemble_file",
  200. # load
  201. "check_object_path",
  202. "is_bytecode_extension",
  203. "is_pypy",
  204. "is_python_source",
  205. "load_file",
  206. "load_module",
  207. "load_module_from_file_object",
  208. "write_bytecode_file",
  209. # lineoffsets
  210. "LineOffsetInfo",
  211. "LineOffsets",
  212. "LineOffsetsCompact",
  213. "lineoffsets_in_file",
  214. "lineoffsets_in_module",
  215. # instruction
  216. "Instruction",
  217. # magic
  218. "canonic_python_version",
  219. "int2magic",
  220. "magic2int",
  221. "PYTHON_MAGIC_INT",
  222. "sysinfo2magic",
  223. # opcodes
  224. "opcode_13",
  225. "opcode_14",
  226. "opcode_15",
  227. "opcode_22",
  228. "opcode_23",
  229. "opcode_24",
  230. "opcode_25",
  231. "opcode_26",
  232. "opcode_27",
  233. "opcode_30",
  234. "opcode_31",
  235. "opcode_32",
  236. "opcode_33",
  237. "opcode_34",
  238. "opcode_35",
  239. "opcode_36",
  240. "opcode_37",
  241. "opcode_38",
  242. "opcode_39",
  243. "opcode_310",
  244. "opcode_311",
  245. # op_imports
  246. "get_opcode_module",
  247. # util
  248. "COMPILER_FLAG_BIT",
  249. "COMPILER_FLAG_NAMES",
  250. "CO_ABSOLUTE_IMPORT",
  251. "CO_ASYNC_GENERATOR",
  252. "CO_COROUTINE",
  253. "CO_FUTURE_ANNOTATIONS",
  254. "CO_FUTURE_BARRY_AS_DBFL",
  255. "CO_FUTURE_DIVISION",
  256. "CO_FUTURE_GENERATOR_STOP",
  257. "CO_FUTURE_PRINT_FUNCTION",
  258. "CO_FUTURE_UNICODE_LITERALS",
  259. "CO_FUTURE_WITH_STATEMENT",
  260. "CO_GENERATOR",
  261. "CO_GENERATOR_ALLOWED",
  262. "CO_ITERABLE_COROUTINE",
  263. "CO_NESTED",
  264. "CO_NEWLOCALS",
  265. "CO_NOFREE",
  266. "CO_OPTIMIZED",
  267. "CO_VARARGS",
  268. "CO_VARKEYWORDS",
  269. "PYPY_COMPILER_FLAG_NAMES",
  270. "code2num",
  271. "co_flags_is_async",
  272. # version_info
  273. "IS_GRAAL",
  274. "IS_PYPY",
  275. "PYTHON3",
  276. "PYTHON_VERSION_STR",
  277. "PYTHON_VERSION_TRIPLE",
  278. "__version__",
  279. ]