From b54be24e143acb96659173c376c9b65b982640bb Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 31 Mar 2018 23:07:06 -0400 Subject: [PATCH] 3.6 argument parsing --- test/bytecode_3.6_run/10_argparse.pyc | Bin 0 -> 1153 bytes test/simple_source/bug36/10_argparse.py | 37 +++++++++++++++++++++++ uncompyle6/parsers/parse36.py | 6 ++-- uncompyle6/semantics/customize.py | 38 +++++++++++++----------- 4 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 test/bytecode_3.6_run/10_argparse.pyc create mode 100644 test/simple_source/bug36/10_argparse.py diff --git a/test/bytecode_3.6_run/10_argparse.pyc b/test/bytecode_3.6_run/10_argparse.pyc new file mode 100644 index 0000000000000000000000000000000000000000..891345a826d877ef4ba4f33ac51f09dd21c8fa55 GIT binary patch literal 1153 zcmY*XOK;Oa5VjpBag!!36iRt7k4q4tKqZ7kQ_%yx@DKt{zEpN*oNVitcGrnw#D$(K z@i(~e3pjA*7a(7ekb38Ygv6|yw87Sn_M7*9GaIc|qxa&Q``0#%pT^u*r~6Yn(lHGK z3@}5(HPF~I!Gg-6=~`&*Rlp{V4b=k^YETE~&^C=yzW@zr!XmUzG;LUdWvs#(ID1%~ zdab}Y@;X1~wF(zt4KBi^leo)pg?z5g`CKD>op7bhQado*I@b3bVEdN*q82`ygc`6+ z=<5_UOWXG;S{xW;`!Pi=SR?dnirS^;?wj7S-4j z16kNZ4Ab1|MtQBaVuVban2&0V7_-ynICWtaHLtH55PGJR zE6iKnE{_3Y72*iPBbvRDKh~YZS>&T&Nx=Nji}xk-Cu}_A{UK8cI}TwUi*d|eZohfX z%5ZAA4j6b@s6>@A&B}Orqucf3I8mO${Ne1z(4%xAC(_1T4Jn-*CPJ|!?I(b2jxcI9 z)j8;qo+dhP_j+6Gee6Z}fo=AB`AZ%gv#y3-T#jLme#Rw}DfW555$>{7@K`Z5B(0Bu z9#z@LDOHn>C7N^XE6unVSogLbfcX}5p)Oyh {name} <==' +assert args.test == False +assert args.v == False diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 254fd929..f3925400 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -205,11 +205,9 @@ class Python36Parser(Python35Parser): self.add_unique_rule('expr ::= async_call', token.kind, uniq_param, customize) if opname.startswith('CALL_FUNCTION_KW'): - self.addRule("expr ::= call_kw", nop_func) + self.addRule("expr ::= call_kw36", nop_func) values = 'expr ' * token.attr - rule = 'call_kw ::= expr kwargs_36 {token.kind}'.format(**locals()) - self.addRule(rule, nop_func) - rule = 'kwargs_36 ::= {values} LOAD_CONST'.format(**locals()) + rule = "call_kw36 ::= expr {values} LOAD_CONST {opname}".format(**locals()) self.add_unique_rule(rule, token.kind, token.attr, customize) elif opname == 'CALL_FUNCTION_EX_KW': self.addRule("""expr ::= call_ex_kw diff --git a/uncompyle6/semantics/customize.py b/uncompyle6/semantics/customize.py index d85a24f1..a0d34f48 100644 --- a/uncompyle6/semantics/customize.py +++ b/uncompyle6/semantics/customize.py @@ -407,8 +407,9 @@ def customize_for_version(self, is_pypy, version): # Value 100 is important; it is exactly # module/function precidence. - PRECEDENCE['call_kw'] = 100 - PRECEDENCE['call_ex'] = 100 + PRECEDENCE['call_kw'] = 100 + PRECEDENCE['call_kw36'] = 100 + PRECEDENCE['call_ex'] = 100 TABLE_DIRECT.update({ 'tryfinally36': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', @@ -731,40 +732,43 @@ def customize_for_version(self, is_pypy, version): # return # self.n_kwargs_only_36 = kwargs_only_36 - def kwargs_36(node): - self.write('(') - keys = node[-1].attr + def n_call_kw36(node): + self.template_engine(("%c(", 0), node) + keys = node[-2].attr num_kwargs = len(keys) - num_posargs = len(node) - (num_kwargs + 1) + num_posargs = len(node) - (num_kwargs + 2) n = len(node) assert n >= len(keys)+1, \ 'not enough parameters keyword-tuple values' - # try: - # assert n >= len(keys)+1, \ - # 'not enough parameters keyword-tuple values' - # except: - # from trepan.api import debug; debug() sep = '' - # FIXME: adjust output for line breaks? - for i in range(num_posargs): + + line_number = self.line_number + for i in range(1, num_posargs): self.write(sep) self.preorder(node[i]) - sep = ', ' + if line_number != self.line_number: + sep = ",\n" + self.indent + " " + else: + sep = ", " + line_number = self.line_number i = num_posargs j = 0 # FIXME: adjust output for line breaks? - while i < n-1: + while i < n-2: self.write(sep) self.write(keys[j] + '=') self.preorder(node[i]) - sep=', ' + if line_number != self.line_number: + sep = ",\n" + self.indent + " " + else: + sep = ", " i += 1 j += 1 self.write(')') self.prune() return - self.n_kwargs_36 = kwargs_36 + self.n_call_kw36 = n_call_kw36 def starred(node): l = len(node)