ó p”þfc@s´dZddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z d„Z dejfd„ƒYZd „Zd „Zgd d „Zd „Zd S(s:Fixer for function definitions with tuple parameters. def func(((a, b), c), d): ... -> def func(x, d): ((a, b), c) = x ... It will also support lambdas: lambda (x, y): x + y -> lambda t: t[0] + t[1] # The parens are a syntax error in Python 3 lambda (x): x + y -> lambda x: x + y i(tpytree(ttoken(t fixer_base(tAssigntNametNewlinetNumbert SubscripttsymscCs)t|tjƒo(|jdjtjkS(Ni(t isinstanceRtNodetchildrenttypeRtSTRING(tstmt((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyt is_docstringstFixTupleParamscBs,eZdZeZdZd„Zd„ZRS(is funcdef< 'def' any parameters< '(' args=any ')' > ['->' any] ':' suite=any+ > | lambda= lambdef< 'lambda' args=vfpdef< '(' inner=any ')' > ':' body=any > c s0d|krˆj||ƒSg‰|d}|d}|djdjtjkryd}|djdj}tƒ‰n!d}d}tjtjdƒ‰t ‡‡‡fd †}|jt j krÑ||ƒn`|jt j kr1xKt |jƒD]7\}} | jt j kró|| d |dkƒqóqóWnˆs;dSxˆD]} |d| _qBW|} |dkr{d ˆd_n1t|dj|ƒr¬|ˆd_|d} nxˆD]} |d| _q³Wˆ|dj| | +x=t| d| tˆƒdƒD]}||dj|_qW|djƒdS( Ntlambdatsuitetargsiiiu; ucs‡tˆjƒƒ}|jƒ}d|_t||jƒƒ}|rNd|_n|j|ƒˆjtjt j |ˆjƒgƒƒdS(Nuu ( Rtnew_nametclonetprefixRtreplacetappendRR Rt simple_stmt(t tuple_argt add_prefixtntargR(tendt new_linestself(s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyt handle_tupleCs    Ru (ttransform_lambdaR R RtINDENTtvalueRRtLeaftFalseRttfpdeft typedargslistt enumeratetparentRRtrangetlentchanged( R tnodetresultsRRtstarttindentR!tiRtlinetafter((RRR s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyt transform.sF            (cCsN|d}|d}t|dƒ}|jtjkr\|jƒ}d|_|j|ƒdSt|ƒ}t|ƒ}|j t |ƒƒ}t |ddƒ} |j| jƒƒx™|j ƒD]‹} | jtjkr»| j |kr»g|| j D]} | jƒ^qð} tjtj| jƒg| ƒ} | j| _| j| ƒq»q»WdS(NRtbodytinneru R(t simplify_argsR RtNAMERRRt find_paramst map_to_indexRt tuple_nameRt post_orderR$RR Rtpower(R R.R/RR6R7tparamstto_indexttup_namet new_paramRtct subscriptstnew((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyR"ns(       !&  (t__name__t __module__t run_ordertTruet BM_compatibletPATTERNR5R"(((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyRs   @cCso|jtjtjfkr|S|jtjkr[x#|jtjkrV|jd}q4W|Std|ƒ‚dS(NisReceived unexpected node %s(R RtvfplistRR9tvfpdefR t RuntimeError(R.((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyR8‹scCsn|jtjkr#t|jdƒS|jtjkr<|jSg|jD]$}|jtjkrFt|ƒ^qFS(Ni( R RRMR:R RR9R$tCOMMA(R.RC((s6/usr/lib64/python2.7/lib2to3/fixes/fix_tuple_params.pyR:–s cCs„|dkri}nxht|ƒD]Z\}}ttt|ƒƒƒg}t|tƒrnt||d|ƒq"||||s. l