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

Class Token

uncompyle6/scanners/tok.py:47–212  ·  view source on GitHub ↗

Class representing a byte-code instruction. A byte-code token is equivalent to Python 3's dis.instruction or the contents of one line as output by dis.dis().

Source from the content-addressed store, hash-verified

45
46
47class Token:
48 """
49 Class representing a byte-code instruction.
50
51 A byte-code token is equivalent to Python 3's dis.instruction or
52 the contents of one line as output by dis.dis().
53 """
54
55 # FIXME: match Python 3.4's terms:
56 # linestart = starts_line
57 # attr = argval
58 # pattr = argrepr
59 def __init__(
60 self,
61 opname,
62 attr=None,
63 pattr=None,
64 offset: Union[int, str] = -1,
65 linestart=None,
66 op=None,
67 has_arg=None,
68 opc=None,
69 has_extended_arg=False,
70 optype=None,
71 ):
72 self.kind = intern(opname)
73 self.has_arg = has_arg
74 self.attr: Optional[int] = attr
75 self.pattr = pattr
76 self.optype = optype
77 if has_extended_arg:
78 self.offset = "%d_%d" % (offset, offset + 2)
79 else:
80 self.offset = offset
81
82 self.linestart = linestart
83 if has_arg is False:
84 self.attr = None
85 self.pattr = None
86
87 if opc is None:
88 try:
89 from xdis.std import _std_api
90 except KeyError as e:
91 print(f"I don't know about Python version {e} yet.")
92 try:
93 version_tuple = tuple(int(i) for i in str(e)[1:-1].split("."))
94 except Exception:
95 pass
96 else:
97 if version_tuple > (3, 9):
98 print("Python versions 3.9 and greater are not supported.")
99 else:
100 print(f"xdis might need to be informed about version {e}")
101 return
102
103 self.opc = _std_api.opc
104 else:

Callers 15

ingestMethod · 0.90
ingestMethod · 0.90
ingestMethod · 0.90
ingestMethod · 0.90
is_return_noneMethod · 0.90
build_classMethod · 0.90
build_astMethod · 0.90
n_yieldMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_tokenFunction · 0.72