-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
62 lines (49 loc) · 1.17 KB
/
example.py
File metadata and controls
62 lines (49 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import ast
from decompiler import Decompiler
from decompiler.utils.bytecode import compile_without_peephole__
code = '''
import abcd.efgh as xyz
from ..a.b.c import d, e as f
raise
raise abc
raise abc from xyz
a = f'nice {formatted} {string:.{{{x}}}f} {b!r} {c!s} {d!a}'.a
a = b.c(g, k, l)
for a.b, c[d], e[e][f], *g, h in ggrr()()():
pass # notice how these turn into a continue
async for x in z:
pass
# chained with statement will decompile into nested with statements with single target
with a as b, c as d:
pass
async with v:
...
# try-finally statement decompiles into different source code, but equal bytecode
try:
1 / 0
except NamedException as E1:
named_handler
except NamedException2 as E2:
named_handler2
except:
default_generic_handler
else:
else_block
finally:
what_if_we_had_finally_too
________
# a for loop which decompiles into different bytecode, but functionally equivalent
for a in b:
if test1:
pass
else:
break
if test2:
break
else:
for_else
'''
cc = compile(code, '<test>', 'exec', flags=ast.PyCF_ALLOW_TOP_LEVEL_AWAIT)
d = Decompiler(cc)
d.decompile()
print(d.get_source_code())