forked from rocky/python-uncompyle6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow.py
More file actions
67 lines (58 loc) · 2.21 KB
/
show.py
File metadata and controls
67 lines (58 loc) · 2.21 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
63
64
65
66
67
import sys
def maybe_show_asm(showasm, tokens):
"""
Show the asm based on the showasm flag (or file object), writing to the
appropriate stream depending on the type of the flag.
:param showasm: Flag which determines whether the ingested code is
written to sys.stdout or not. (It is also to pass a file
like object, into which the asm will be written).
:param tokens: The asm tokens to show.
"""
if showasm:
if hasattr(showasm, 'write'):
stream = showasm
else:
stream = sys.stdout
for t in tokens:
stream.write(str(t))
stream.write('\n')
def maybe_show_ast(showast, ast):
"""
Show the ast based on the showast flag (or file object), writing to the
appropriate stream depending on the type of the flag.
:param showasm: Flag which determines whether the abstract syntax tree is
written to sys.stdout or not. (It is also to pass a file
like object, into which the ast will be written).
:param ast: The ast to show.
"""
if showast:
if hasattr(showast, 'write'):
stream = showast
else:
stream = sys.stdout
stream.write(str(ast))
stream.write('\n')
def maybe_show_ast_param_default(showast, name, default):
"""
Show a function parameter with default for an ast based on the showast flag
(or file object), writing to the appropriate stream depending on the type
of the flag.
:param showasm: Flag which determines whether the function parameter with
default is written to sys.stdout or not. (It is also to
pass a file like object, into which the ast will be
written).
:param name: The function parameter name.
:param default: The function parameter default.
"""
if showast:
if hasattr(showast, 'write'):
stream = showast
else:
stream = sys.stdout
stream.write('\n')
stream.write('--' + name)
stream.write('\n')
stream.write(str(default))
stream.write('\n')
stream.write('--')
stream.write('\n')