MCPcopy
hub / github.com/rocky/python-uncompyle6 / ingest

Method ingest

uncompyle6/scanners/scanner26.py:54–360  ·  view source on GitHub ↗

Create "tokens" the bytecode of an Python code object. Largely these are the opcode name, but in some cases that has been modified to make parsing easier. returning a list of uncompyle6 Token's. Some transformations are made to assist the deparsing grammar:

(self, co, classname=None, code_objects={}, show_asm=None)

Source from the content-addressed store, hash-verified

52 return
53
54 def ingest(self, co, classname=None, code_objects={}, show_asm=None):
55 """Create "tokens" the bytecode of an Python code object. Largely these
56 are the opcode name, but in some cases that has been modified to make parsing
57 easier.
58 returning a list of uncompyle6 Token's.
59
60 Some transformations are made to assist the deparsing grammar:
61 - various types of LOAD_CONST's are categorized in terms of what they load
62 - COME_FROM instructions are added to assist parsing control structures
63 - operands with stack argument counts or flag masks are appended to the
64 opcode name, e.g.:
65 * BUILD_LIST, BUILD_SET
66 * MAKE_FUNCTION and FUNCTION_CALLS append the number of positional
67 arguments
68 - EXTENDED_ARGS instructions are removed
69
70 Also, when we encounter certain tokens, we add them to a set
71 which will cause custom grammar rules. Specifically, variable
72 arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific
73 rules for the specific number of arguments they take.
74 """
75
76 if not show_asm:
77 show_asm = self.show_asm
78
79 bytecode = self.build_instructions(co)
80
81 # show_asm = 'after'
82 if show_asm in ("both", "before"):
83 print("\n# ---- disassembly:")
84 bytecode.disassemble_bytes(
85 co.co_code,
86 varnames=co.co_varnames,
87 names=co.co_names,
88 constants=co.co_consts,
89 cells=bytecode._cell_names,
90 line_starts=bytecode._linestarts,
91 asm_format="extended",
92 )
93 # Container for tokens
94 tokens = []
95
96 customize = {}
97 if self.is_pypy:
98 customize["PyPy"] = 0
99
100 codelen = len(self.code)
101
102 free, names, varnames = self.unmangle_code_names(co, classname)
103 self.names = names
104
105 # Scan for assertions. Later we will
106 # turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'.
107 # 'LOAD_ASSERT' is used in assert statements.
108 self.load_asserts = set()
109 for i in self.op_range(0, codelen):
110 # We need to detect the difference between:
111 # raise AssertionError

Callers 1

scanner26.pyFile · 0.45

Calls 14

formatMethod · 0.95
TokenClass · 0.90
build_instructionsMethod · 0.80
unmangle_code_namesMethod · 0.80
op_rangeMethod · 0.80
get_argumentMethod · 0.80
addMethod · 0.80
extended_arg_valMethod · 0.80
get_targetMethod · 0.80
copyMethod · 0.80
find_jump_targetsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected