11from __future__ import print_function
22import datetime , os , sys
33
4- from uncompyle6 import verify , PYTHON_VERSION , IS_PYPY
4+ from uncompyle6 import verify , IS_PYPY
55from xdis .code import iscode
66from uncompyle6 .disas import check_object_path
77from uncompyle6 .semantics import pysource
88from uncompyle6 .parser import ParserError
9+ from uncompyle6 .version import VERSION
910
1011from xdis .load import load_module
1112
1213def uncompyle (
13- version , co , out = None , showasm = False , showast = False ,
14+ bytecode_version , co , out = None , showasm = False , showast = False ,
1415 timestamp = None , showgrammar = False , code_objects = {},
15- is_pypy = False , magic_int = None ):
16+ source_size = None , is_pypy = False , magic_int = None ):
1617 """
1718 ingests and deparses a given code block 'co'
1819 """
@@ -22,21 +23,26 @@ def uncompyle(
2223 real_out = out or sys .stdout
2324 co_pypy_str = 'PyPy ' if is_pypy else ''
2425 run_pypy_str = 'PyPy ' if IS_PYPY else ''
25- print ('# %sPython bytecode %s%s disassembled from %sPython %s' %
26- (co_pypy_str , version ,
26+ print ('# uncompyle6 version %s\n '
27+ '# %sPython bytecode %s%s\n # Disassembled from: %sPython %s' %
28+ (VERSION , co_pypy_str , bytecode_version ,
2729 " (%d)" % magic_int if magic_int else "" ,
28- run_pypy_str , PYTHON_VERSION ),
29- file = real_out )
30+ run_pypy_str , ' \n # ' . join ( sys . version . split ( ' \n ' )) ),
31+ file = real_out )
3032 if co .co_filename :
3133 print ('# Embedded file name: %s' % co .co_filename ,
3234 file = real_out )
3335 if timestamp :
3436 print ('# Compiled at: %s' % datetime .datetime .fromtimestamp (timestamp ),
3537 file = real_out )
38+ if source_size :
39+ print ('# Size of source mod 2**32: %d bytes' % source_size ,
40+ file = real_out )
3641
3742 try :
38- pysource .deparse_code (version , co , out , showasm , showast , showgrammar ,
39- code_objects = code_objects , is_pypy = is_pypy )
43+ pysource .deparse_code (bytecode_version , co , out , showasm , showast ,
44+ showgrammar , code_objects = code_objects ,
45+ is_pypy = is_pypy )
4046 except pysource .SourceWalkerError as e :
4147 # deparsing failed
4248 print ("\n " )
@@ -55,7 +61,8 @@ def uncompyle_file(filename, outstream=None, showasm=False, showast=False,
5561
5662 filename = check_object_path (filename )
5763 code_objects = {}
58- version , timestamp , magic_int , co , is_pypy = load_module (filename , code_objects )
64+ (version , timestamp , magic_int , co , is_pypy ,
65+ source_size ) = load_module (filename , code_objects )
5966
6067
6168 if type (co ) == list :
@@ -65,7 +72,8 @@ def uncompyle_file(filename, outstream=None, showasm=False, showast=False,
6572 is_pypy = is_pypy , magic_int = magic_int )
6673 else :
6774 uncompyle (version , co , outstream , showasm , showast ,
68- timestamp , showgrammar , code_objects = code_objects ,
75+ timestamp , showgrammar ,
76+ code_objects = code_objects , source_size = source_size ,
6977 is_pypy = is_pypy , magic_int = magic_int )
7078 co = None
7179
@@ -118,7 +126,10 @@ def _get_outstream(outfile):
118126 elif out_base is None :
119127 outstream = sys .stdout
120128 else :
121- outfile = os .path .join (out_base , filename ) + '_dis'
129+ if filename .endswith ('.pyc' ):
130+ outfile = os .path .join (out_base , filename [0 :- 1 ])
131+ else :
132+ outfile = os .path .join (out_base , filename ) + '_dis'
122133 outstream = _get_outstream (outfile )
123134 # print(outfile, file=sys.stderr)
124135
0 commit comments