3 jf@s~dZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZmZddlmZmZmZddZGdd d ejZd S) zD Fixer for: (a,)* *b (,c)* [,] = s for (a,)* *b (,c)* [,] in d: ... ) fixer_base)count) AssignCommaCallNewlineNameNumbertokensymsNodeLeaf) indentationsuitify commatizec Csg}yt|}t|}Wn$tk r<t|}t|}YnX|dkrttjt|ttjtt j dttj tt j dt |gtt jdgg}|j||jtt jdddttjtt j dddt|ttjtt j dttj |dkrt |ntdd tt j d|dkr(ttjtt jd t |gntdd gtt jdtt jdgg}|j||dkr|jtt jdddttjt|ddttjtt j dttj ttjtt jd t |gtt j dgtt jdgg} |j| ttj|} | S) z Accepts num_pre and num_post, which are counts of values before and after the starg (not including the starg) Returns a source fit for Assign() from fixer_util r[:]+ )prefix-)unicode NameErrorstrr r powerrtrailerr r LSQBZ subscriptCOLONr RSQBappendPLUSZfactorMINUSZ arith_expr) Znum_preZnum_postLISTNAMEITERNAMEchildrenprepostZpre_partZ main_partZ post_partsourcer+C/tmp/pip-build-s1i5078x/future/libpasteurize/fixes/fix_unpacking.pyassignment_sources& J   b  r-c@s(eZdZdZddZddZddZdS) FixUnpackinga9 expl=expr_stmt< testlist_star_expr< pre=(any ',')* star_expr< '*' name=NAME > post=(',' any)* [','] > '=' source=any > | impl=for_stmt< 'for' lst=exprlist< pre=(any ',')* star_expr< '*' name=NAME > post=(',' any)* [','] > 'in' it=any ':' suite=any>c sfdddD\}}}}dd|D}d |_d d|D}d dt||jg|D}|jtd |_tt|jttd |jg}t|t t |t ||j|j } || fS)Nc3s|]}j|VqdS)N)get).0n)resultsr+r, 7sz4FixUnpacking.fix_explicit_context..r(namer)r*cSs g|]}|jtjkr|jqSr+)typer NAMEclone)r0r1r+r+r, 8sz5FixUnpacking.fix_explicit_context..rcSs g|]}|jtjkr|jqSr+)r5r r6r7)r0r1r+r+r,r8:scSsg|] }|jqSr+)r7)r0r1r+r+r,r8;srlist)r(r4r)r*) rrr7r"rrrr%rr-lenr&) selfnoder2r(r4r)r*target setup_line power_liner+)r2r,fix_explicit_context6s    z!FixUnpacking.fix_explicit_contextc sfdddD\}}}}dd|D}d |_d d|D}d dt||jg|D}|jt|j}d |_tt|jttd t|j g} t|t t |t ||j|j } | | fS)z_ Only example of the implicit context is a for loop, so only fix that. c3s|]}j|VqdS)N)r/)r0r1)r2r+r,r3Isz4FixUnpacking.fix_implicit_context..r(r4r)itcSs g|]}|jtjkr|jqSr+)r5r r6r7)r0r1r+r+r,r8Jsz5FixUnpacking.fix_implicit_context..rcSs g|]}|jtjkr|jqSr+)r5r r6r7)r0r1r+r+r,r8LscSsg|] }|jqSr+)r7)r0r1r+r+r,r8Msrr9)r(r4r)rA) rrr7r"rrrr%rr&r-r:) r;r<r2r(r4r)rAr=r*r>r?r+)r2r,fix_implicit_contextDs  " z!FixUnpacking.fix_implicit_contextc Cs@|jd|_|jd|_|jd|jd}}|dk r|j||\}}|j|_t|j|_|jt |j}|j }|j |||j ||n|dk r<|j ||\}}t |dd|jDd} d |_| jd j|_t| jd | jd _| j d t | j d || j d t | j d ||jd jt|jd ddS)a a,b,c,d,e,f,*g,h,i = range(100) changes to _3to2list = list(range(100)) a,b,c,d,e,f,g,h,i, = _3to2list[:6] + [_3to2list[6:-2]] + _3to2list[-2:] and for a,b,*c,d,e in iter_of_iters: do_stuff changes to for _3to2iter in iter_of_iters: _3to2list = list(_3to2iter) a,b,c,d,e, = _3to2list[:2] + [_3to2list[2:-2]] + _3to2list[-2:] do_stuff Z _3to2listZ _3to2iterexplimplNcSsg|]}|jtjkr|qSr+)r5r suite)r0kr+r+r,r8tsz*FixUnpacking.transform..rrrlstr)r)new_namer%r&r/r@rrparentZ append_childrremoveZ insert_childrBrr'valuereplacer) r;r<r2rCrDr>r?rJirEr+r+r, transformWs0        zFixUnpacking.transformN)__name__ __module__ __qualname__ZPATTERNr@rBrOr+r+r+r,r.*s r.N)__doc__Zlib2to3r itertoolsrZlib2to3.fixer_utilrrrrrr r r r r Zlibfuturize.fixer_utilrrrr-ZBaseFixr.r+r+r+r,s   0