diff --git a/tests/15_test_class.ref.py b/tests/15_test_class.ref.py new file mode 100644 index 0000000..90b75ac --- /dev/null +++ b/tests/15_test_class.ref.py @@ -0,0 +1,43 @@ +""" +test_class.py -- source test pattern for class definitions + +This source is part of the decompyle test suite. + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +class A: + + class A1: + def __init__(self): + print 'A1.__init__' + + def foo(self): + print 'A1.foo' + + def __init__(self): + print 'A.__init__' + + def foo(self): + print 'A.foo' + + +class B: + def __init__(self): + print 'B.__init__' + + def bar(self): + print 'B.bar' + + +class C(A, B): + def foobar(self): + print 'C.foobar' + + +c = C() +c.foo() +c.bar() +c.foobar() diff --git a/tests/15_test_del.ref.py b/tests/15_test_del.ref.py new file mode 100644 index 0000000..baf8e59 --- /dev/null +++ b/tests/15_test_del.ref.py @@ -0,0 +1,35 @@ +""" +test_del.py -- source test pattern for 'del' statements + +This source is part of the decompyle test suite. +Snippet taken from python libs's test_class.py + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +raise "This program can't be run" + +print 0 +a = b[5] +print 1 +del a +print 2 +del b[5] +print 3 + +del testme[1] +print 4 +del testme[:] +print '4a' +del testme[:42] +print '4b' +del testme[40:42] +print 5 +del testme[2:1024:10] +print '5a' +del testme[40, 41, 42] +print 6 +del testme[:42, ..., :24:, 24, 100] +print 7 diff --git a/tests/15_test_docstring.ref.py b/tests/15_test_docstring.ref.py new file mode 100644 index 0000000..25d50b5 --- /dev/null +++ b/tests/15_test_docstring.ref.py @@ -0,0 +1,41 @@ + + + + + + + + +""" +This is a doc string +""" + +def Doc_Test(): + """This has to be present""" + +class XXX: + def __init__(self): + """__init__: This has to be present""" + self.a = 1 + + def XXX22(): + """XXX22: This has to be present""" + pass + + def XXX11(): + """XXX22: This has to be present""" + pass + + def XXX12(): + foo = 'XXX22: This has to be present' + pass # Left for line number compatibility. Do not emit + + def XXX13(): + pass + +def Y11(): + def Y22(): + def Y33(): + pass + +print __doc__ diff --git a/tests/15_test_empty.ref.py b/tests/15_test_empty.ref.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/15_test_exceptions.ref.py b/tests/15_test_exceptions.ref.py new file mode 100644 index 0000000..75fde9a --- /dev/null +++ b/tests/15_test_exceptions.ref.py @@ -0,0 +1,107 @@ +import dis + +def x11(): + try: + a = 'try except' + except: + a = 2 + b = '--------' + + +def x12(): + try: + a = 'try except else(pass)' + except: + a = 2 + b = '--------' + + +def x13(): + try: + a = 'try except else(a=3)' + except: + a = 2 + else: + a = 3 + b = '--------' + + +def x21(): + try: + a = 'try KeyError' + except KeyError: + a = 8 + b = '--------' + + +def x22(): + try: + a = 'try (IdxErr, KeyError) else(pass)' + except (IndexError, KeyError): + a = 8 + b = '--------' + + +def x23(): + try: + a = 'try KeyError else(a=9)' + except KeyError: + a = 8 + else: + a = 9 + b = '--------' + + +def x31(): + try: + a = 'try KeyError IndexError' + except KeyError: + a = 8 + except IndexError: + a = 9 + b = '--------' + + +def x32(): + try: + a = 'try KeyError IndexError else(pass)' + except KeyError: + a = 8 + except IndexError: + a = 9 + b = '--------' + + +def x33(): + try: + a = 'try KeyError IndexError else(a=9)' + except KeyError: + a = 8 + except IndexError: + a = 9 + else: + a = 9 + b = '#################' + + +def x41(): + if a == 1: + a = 1 + elif b == 1: + b = 1 + else: + c = 1 + b = '#################' + + +def x42(): + if a == 1: + a = 1 + elif b == 1: + b = 1 + else: + c = 1 + xxx = 'mmm' + +if __name__ == '__main__': + dis.dis(xx) diff --git a/tests/15_test_exec.ref.py b/tests/15_test_exec.ref.py new file mode 100644 index 0000000..7c978a3 --- /dev/null +++ b/tests/15_test_exec.ref.py @@ -0,0 +1,13 @@ + + + + + + + + +testcode = 'a = 12' + +exec testcode +exec testcode in globals() +exec testcode in globals(), locals() diff --git a/tests/15_test_expressions.ref.py b/tests/15_test_expressions.ref.py new file mode 100644 index 0000000..236935e --- /dev/null +++ b/tests/15_test_expressions.ref.py @@ -0,0 +1,10 @@ + + + + + + + + +def _lsbStrToInt(str): + return ord(str[0]) + (ord(str[1]) << 8) + (ord(str[2]) << 16) + (ord(str[3]) << 24) diff --git a/tests/15_test_functions.ref.py b/tests/15_test_functions.ref.py new file mode 100644 index 0000000..52b13de --- /dev/null +++ b/tests/15_test_functions.ref.py @@ -0,0 +1,58 @@ + + + + + + + + +def x0(): + pass + +def x1(arg1): + pass + +def x2(arg1, arg2): + pass + +def x3a(*args): + pass + +def x3b(**kwargs): + pass + +def x3c(*args, **kwargs): + pass + +def x4a(foo, bar = 1, bla = 2, *args): + pass + +def x4b(foo, bar = 1, bla = 2, **kwargs): + pass + +def x4c(foo, bar = 1, bla = 2, *args, **kwargs): + pass + +def func_with_tuple_args((a, b)): + print a + print b + +def func_with_tuple_args2((a, b), (c, d)): + print a + print c + +def func_with_tuple_args3((a, b), (c, d), *args): + print a + print c + +def func_with_tuple_args4((a, b), (c, d), **kwargs): + print a + print c + +def func_with_tuple_args5((a, b), (c, d), *args, **kwargs): + print a + print c + +def func_with_tuple_args6((a, b), (c, d) = (2, 3), *args, **kwargs): + print a + print c diff --git a/tests/15_test_global.ref.py b/tests/15_test_global.ref.py new file mode 100644 index 0000000..c6bcf70 --- /dev/null +++ b/tests/15_test_global.ref.py @@ -0,0 +1,26 @@ +""" +test_global.py -- source test pattern for 'global' statement + +This source is part of the decompyle test suite. + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +i = 1; j = 7 +def a(): + def b(): + def c(): + k = 34 + global i + i = i + k + l = 42 + c() + global j + j = j + l + b() + print i, j + +a() +print i, j diff --git a/tests/15_test_globals.ref.py b/tests/15_test_globals.ref.py new file mode 100644 index 0000000..6982fa4 --- /dev/null +++ b/tests/15_test_globals.ref.py @@ -0,0 +1,18 @@ + + + + + + + + +def f(): + print x + x = x + 1 + print x + +raise "This program can't be run" + +x = 1 +f() +print x diff --git a/tests/15_test_import.ref.py b/tests/15_test_import.ref.py new file mode 100644 index 0000000..c8bfe13 --- /dev/null +++ b/tests/15_test_import.ref.py @@ -0,0 +1,21 @@ +""" +test_import.py -- source test pattern for import statements + +This source is part of the decompyle test suite. + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +import sys +import os, sys, BaseHTTPServer + +import test.test_MimeWriter + +from rfc822 import Message +from mimetools import Message, decode, choose_boundary +from os import * + +for (k, v) in globals().items(): + print `k`, v diff --git a/tests/15_test_integers.ref.py b/tests/15_test_integers.ref.py new file mode 100644 index 0000000..141c22b --- /dev/null +++ b/tests/15_test_integers.ref.py @@ -0,0 +1,33 @@ +""" +test_integers.py -- source test pattern for integers + +This source is part of the decompyle test suite. +Snippet taken from python libs's test_class.py + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +import sys + + +i = 1 +i = 42 +i = -1 +i = -42 +i = sys.maxint +minint = -sys.maxint - 1 +print sys.maxint +print minint +print long(minint) - 1 + +print +i = -2147483647 +print i, repr(i) +i = i - 1 +print i, repr(i) +i = -0x80000000L +print i, repr(i) +i = -0x80000001L +print i, repr(i) diff --git a/tests/15_test_lambda.ref.py b/tests/15_test_lambda.ref.py new file mode 100644 index 0000000..93c90fa --- /dev/null +++ b/tests/15_test_lambda.ref.py @@ -0,0 +1,16 @@ + + + + + + + + +palette = map(lambda a: (a, a, a), range(256)) +palette = map(lambda (r, g, b): chr(r) + chr(g) + chr(b), palette) +palette = map(lambda r: r, palette) + +palette = lambda (r, g, b): r +palette = lambda (r): r +palette = lambda r: r +palette = (lambda (r): r, palette) diff --git a/tests/15_test_loops.ref.py b/tests/15_test_loops.ref.py new file mode 100644 index 0000000..8ee3008 --- /dev/null +++ b/tests/15_test_loops.ref.py @@ -0,0 +1,48 @@ +""" +test_loops.py -- source test pattern for loops + +This source is part of the decompyle test suite. + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +for i in range(10): + if i == 3: + continue + if i == 5: + break + print i, +else: + print 'Else' +print + +for i in range(10): + if i == 3: + continue + print i, +else: + print 'Else' + + +i = 0 +while i < 10: + i = i + 1 + if i == 3: + continue + if i == 5: + break + print i, +else: + print 'Else' +print + +i = 0 +while i < 10: + i = i + 1 + if i == 3: + continue + print i, +else: + print 'Else' diff --git a/tests/15_test_misc.ref.py b/tests/15_test_misc.ref.py new file mode 100644 index 0000000..457bbc4 --- /dev/null +++ b/tests/15_test_misc.ref.py @@ -0,0 +1,32 @@ + + + + + + + + + +raise "This program can't be run" + +class A: + def __init__(self, num): + self.num = num + def __repr__(self): + return str(self.num) + +b = [] +for i in range(10): + b.append(A(i)) + +for i in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR', 'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_KW'): + + print i, '\t', len(i), len(i) - len('CALL_FUNCTION'), + print (len(i) - len('CALL_FUNCTION')) / 3, + print i[len('CALL_FUNCTION'):] + +p2 = (0, 0, None) +if p2[2]: + print 'has value' +else: + print ' no value' diff --git a/tests/15_test_nested_elif.ref.py b/tests/15_test_nested_elif.ref.py new file mode 100644 index 0000000..139eab4 --- /dev/null +++ b/tests/15_test_nested_elif.ref.py @@ -0,0 +1,89 @@ + + + + + + + + +a = None + +if a == 1: + print '1' +elif a == 2: + print '2' + +if a == 1: + print '1' +elif a == 2: + print '2' +else: + print 'other' + +if a == 1: + print '1' +elif a == 2: + print '2' +elif a == 3: + print '3' +else: + print 'other' + +if a == 1: + print '1' +elif a == 2: + print '2' +elif a == 3: + print '3' + +if a == 1: + print '1' + +elif a ==2: # No bytecode distinction between else: if: and elif: + print '2' + +elif a == 3: + print '3' +else: + print 'other' + +if a == 1: + print '1' + +elif a == 2: + print '2' +else: + print 'more' + if a == 3: + print '3' + else: + print 'other' + +if a == 1: + print '1' +else: + print 'more' + if a == 2: + print '2' + + elif a == 3: + print '3' + else: + print 'other' + +if a == 1: + print '1' +else: + print 'more' + if a == 2: + print '2' + else: + print 'more' + if a == 3: + print '3' + elif a == 4: + print '4' + elif a == 4: + print '4' + else: + print 'other' diff --git a/tests/15_test_prettyprint.ref.py b/tests/15_test_prettyprint.ref.py new file mode 100644 index 0000000..017802d --- /dev/null +++ b/tests/15_test_prettyprint.ref.py @@ -0,0 +1,127 @@ +""" +test_prettyprint.py -- source test pattern for tesing the prettyprint + funcionality of decompyle + +This source is part of the decompyle test suite. + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +import pprint + +aa = 'aa' + +dict0 = { + 'a': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'b': 1234, + 'd': aa, + aa: aa +} + + +dict = { # NOTE: Moving '}' output to fit line numbers + 'a': 'aaa', + 'b': 1234, + 'c': { + 'ca': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'cb': 1234, + 'cc': None }, + 'd': aa, + aa: aa } + +list1 = ['1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', aa, + '1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '1ccccccccccccccccccccccccccccccccccccccccccc'] + +list2 = ['2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + ['22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', aa, + '22bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '22ccccccccccccccccccccccccccccccccccccccccccc'], + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + 'ccccccccccccccccccccccccccccccccccccccccccc'] + +tuple1 = ('1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', aa, + '1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '1ccccccccccccccccccccccccccccccccccccccccccc') + +tuple2 = ('2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + ('22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', aa, + '22bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '22ccccccccccccccccccccccccccccccccccccccccccc'), + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + 'ccccccccccccccccccccccccccccccccccccccccccc') + + +def funcA(): + dict = { + 'a': 'aaa', + 'b': 1234, + 'c': { + 'ca': 'aaa', + 'cb': 1234, + 'cc': None }, + 'd': aa, + aa: aa } + + list1 = ['1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + '1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', aa, + '1ccccccccccccccccccccccccccccccccccccccccccc'] + + list2 = ['2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + ['22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', aa, + '22bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '22ccccccccccccccccccccccccccccccccccccccccccc'], + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + 'ccccccccccccccccccccccccccccccccccccccccccc'] + + tuple1 = ('1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + '1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', aa, + '1ccccccccccccccccccccccccccccccccccccccccccc') + + tuple2 = ('2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + ('22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', aa, + '22bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '22ccccccccccccccccccccccccccccccccccccccccccc'), + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + 'ccccccccccccccccccccccccccccccccccccccccccc') + + + def funcAB(): + dict = { + 'a': 'aaa', + 'b': 1234, + 'c': { + 'ca': 'aaa', + 'cb': 1234, + 'cc': None }, + 'd': aa, + aa: aa } + + list1 = ['1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + '1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '1ccccccccccccccccccccccccccccccccccccccccccc'] + list2= ['2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + ['22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + '22bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '22ccccccccccccccccccccccccccccccccccccccccccc'], + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + 'ccccccccccccccccccccccccccccccccccccccccccc'] + tuple1 = ('1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + '1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '1ccccccccccccccccccccccccccccccccccccccccccc') + tuple2 = ('2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + ('22aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + '22bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + '22ccccccccccccccccccccccccccccccccccccccccccc'), + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', + 'ccccccccccccccccccccccccccccccccccccccccccc') + +pprint.pprint(dict0) +print +pprint.pprint(dict) +print +pprint.pprint(list1) +print +pprint.pprint(list2) diff --git a/tests/15_test_print.ref.py b/tests/15_test_print.ref.py new file mode 100644 index 0000000..d7ec70a --- /dev/null +++ b/tests/15_test_print.ref.py @@ -0,0 +1,16 @@ + + + + + + + + +print 1, 2, 3, 4, 5 +a = b + 5 +print 1, 2, 3, 4, 5 +print 1, 2, 3, 4, 5 +print +print +print 1, 2, 3, 4, 5 +print diff --git a/tests/15_test_single_stmt.ref.py b/tests/15_test_single_stmt.ref.py new file mode 100644 index 0000000..79a0780 --- /dev/null +++ b/tests/15_test_single_stmt.ref.py @@ -0,0 +1 @@ +print 5 diff --git a/tests/15_test_slices.ref.py b/tests/15_test_slices.ref.py new file mode 100644 index 0000000..81d3d8e --- /dev/null +++ b/tests/15_test_slices.ref.py @@ -0,0 +1,43 @@ +""" +test_slices.py -- source test pattern for slices + +This source is part of the decompyle test suite. +Snippet taken from python libs's test_class.py + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +raise "This program can't be run" + +testme[1] +testme[1] = 1 +del testme[1] + +testme[:42] +testme[:42] = 'The Answer' +del testme[:42] + +testme[2:1024:] +testme[:1024:10] +testme[::] +testme[2:1024:10] +testme[2:1024:10] = 'A lot' +del testme[2:1024:10] + +testme[:42, ..., :24:, 24, 100] +testme[:42, ..., :24:, 24, 100] = 'Strange' +del testme[:42, ..., :24:, 24, 100] + +testme[:] +testme[:] = 'Take all' +del testme[:] + +testme[40:42] +testme[40:42] = 'Three' +del testme[40:42] + +testme[40, 41, 42] +testme[40, 41, 42] = 'Another Three' +del testme[40, 41, 42] diff --git a/tests/15_test_tuple_params.ref.py b/tests/15_test_tuple_params.ref.py new file mode 100644 index 0000000..485538d --- /dev/null +++ b/tests/15_test_tuple_params.ref.py @@ -0,0 +1,24 @@ +""" +test_tuple_params.py -- source test pattern for formal parameters of type tuple + +This source is part of the decompyle test suite. + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +def A(a, b, (x, y, z), c): + pass + +def B(a, b = 42, (x, y, z) = (1, 2, 3), c = 17): + pass + +def C((x, y, z)): + pass + +def D((x,)): + pass + +def E((x)): + pass diff --git a/tests/15_test_tuples.ref.py b/tests/15_test_tuples.ref.py new file mode 100644 index 0000000..4e67b00 --- /dev/null +++ b/tests/15_test_tuples.ref.py @@ -0,0 +1,25 @@ +""" +test_tuples.py -- source test pattern for tuples + +This source is part of the decompyle test suite. + +decompyle is a Python byte-code decompiler +See http://www.goebel-consult.de/decompyle/ for download and +for further information +""" + +a = (1,) +b = (2, 3) +a, b = (1, 2) +a, b = (1, 2), (3, 4, 5) + +x = {} +try: + x[1, 2, 3] +except: + pass +x[1, 2, 3] = 42 +print x[1, 2, 3] +print x[1, 2, 3] +assert x[1, 2, 3] == x[1, 2, 3] +del x[1, 2, 3] diff --git a/tests/15_tuple_params.pyc b/tests/15_tuple_params.pyc deleted file mode 100644 index 22178fb..0000000 Binary files a/tests/15_tuple_params.pyc and /dev/null differ