Formatting in < 3.0 is different for name ops

This commit is contained in:
rocky
2019-06-11 14:08:50 -04:00
parent 08f23567a6
commit 002720988c
4 changed files with 11 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
from uncompyle6 import PYTHON_VERSION
from uncompyle6.scanners.tok import Token
def test_token():
@@ -16,7 +17,10 @@ def test_token():
# Make sure formatting of: LOAD_CONST False. We assume False is the 0th index
# of co_consts.
t = Token('LOAD_CONST', offset=1, attr=False, pattr=False, has_arg=True)
expect = ' 1 LOAD_CONST 0 False'
if PYTHON_VERSION >= 3.0:
expect = ' 1 LOAD_CONST False'
else:
expect = ' 1 LOAD_CONST 0 False'
assert t.format() == expect
if __name__ == '__main__':

View File

@@ -8,5 +8,5 @@
9 STORE_NAME 2 'b'
12 JUMP_FORWARD 0 'to 15'
15_0 COME_FROM 12 '12'
15 LOAD_CONST 0 None
15 LOAD_CONST None
18 RETURN_VALUE

View File

@@ -4,12 +4,12 @@
3 0 LOAD_NAME 0 'True'
3 POP_JUMP_IF_FALSE 15 'to 15'
4 6 LOAD_CONST 0 1
4 6 LOAD_CONST 1
9 STORE_NAME 1 'b'
12 JUMP_FORWARD 6 'to 21'
6 15 LOAD_CONST 1 2
6 15 LOAD_CONST 2
18 STORE_NAME 2 'd'
21_0 COME_FROM 12 '12'
21 LOAD_CONST 2 None
21 LOAD_CONST None
24 RETURN_VALUE

View File

@@ -118,7 +118,8 @@ class Token():
elif self.op in self.opc.hasvargs:
return "%s%s%s" % (prefix, offset_opname, argstr)
elif self.op in self.opc.NAME_OPS:
return "%s%s%s %s" % (prefix, offset_opname, argstr, self.attr)
if self.opc.version >= 3.0:
return "%s%s%s %s" % (prefix, offset_opname, argstr, self.attr)
elif name == 'EXTENDED_ARG':
return "%s%s%s 0x%x << %s = %s" % (prefix, offset_opname, argstr, self.attr,
self.opc.EXTENDED_ARG_SHIFT, pattr)