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

Method ingest

uncompyle6/scanners/scanner3.py:393–813  ·  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

391 return new_tokens
392
393 def ingest(
394 self, co, classname=None, code_objects={}, show_asm=None
395 ) -> Tuple[list, dict]:
396 """
397 Create "tokens" the bytecode of an Python code object. Largely these
398 are the opcode name, but in some cases that has been modified to make parsing
399 easier.
400 returning a list of uncompyle6 Token's.
401
402 Some transformations are made to assist the deparsing grammar:
403 - various types of LOAD_CONST's are categorized in terms of what they load
404 - COME_FROM instructions are added to assist parsing control structures
405 - operands with stack argument counts or flag masks are appended to the
406 opcode name, e.g.:
407 * BUILD_LIST, BUILD_SET
408 * MAKE_FUNCTION and FUNCTION_CALLS append the number of positional
409 arguments
410 - EXTENDED_ARGS instructions are removed
411
412 Also, when we encounter certain tokens, we add them to a set
413 which will cause custom grammar rules. Specifically, variable
414 arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific rules
415 for the specific number of arguments they take.
416 """
417
418 if not show_asm:
419 show_asm = self.show_asm
420
421 bytecode = self.build_instructions(co)
422
423 # show_asm = 'both'
424 if show_asm in ("both", "before"):
425 print("\n# ---- disassembly:")
426 bytecode.disassemble_bytes(
427 co.co_code,
428 varnames=co.co_varnames,
429 names=co.co_names,
430 constants=co.co_consts,
431 cells=bytecode._cell_names,
432 line_starts=bytecode._linestarts,
433 asm_format="extended",
434 )
435
436 # "customize" is in the process of going away here
437 customize = {}
438
439 if self.is_pypy:
440 customize["PyPy"] = 0
441
442 # Scan for assertions. Later we will
443 # turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'.
444 # 'LOAD_ASSERT' is used in assert statements.
445 self.load_asserts = set()
446
447 n = len(self.insts)
448 for i, inst in enumerate(self.insts):
449 opname = inst.opname
450 # We need to detect the difference between:

Callers 13

scanner3.pyFile · 0.45
scanner24.pyFile · 0.45
scanner30.pyFile · 0.45
scanner34.pyFile · 0.45
scanner33.pyFile · 0.45
scanner27.pyFile · 0.45
scanner31.pyFile · 0.45
scanner32.pyFile · 0.45
scanner35.pyFile · 0.45
scanner25.pyFile · 0.45
code_deparseFunction · 0.45
code_deparseFunction · 0.45

Calls 13

find_jump_targetsMethod · 0.95
formatMethod · 0.95
TokenClass · 0.90
get_code_nameFunction · 0.90
build_instructionsMethod · 0.80
addMethod · 0.80
opname_for_offsetMethod · 0.80
next_offsetMethod · 0.80
get_targetMethod · 0.80
copyMethod · 0.80

Tested by

no test coverage detected