Your IP : 216.73.216.172


Current Path : /lib/python3/dist-packages/libpasteurize/fixes/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/libpasteurize/fixes/__pycache__/fix_unpacking.cpython-38.pyc

U

,�]:�@s~dZddlmZddlmZddlmZmZmZm	Z	m
Z
mZmZm
Z
mZmZddlmZmZmZdd�ZGdd	�d	ej�Zd
S)zD
Fixer for:
(a,)* *b (,c)* [,] = s
for (a,)* *b (,c)* [,] in d: ...
�)�
fixer_base)�count)
�Assign�Comma�Call�Newline�Name�Number�token�syms�Node�Leaf)�indentation�suitify�	commatizecCs�g}t|�}t|�}|dkr�ttjt|�ttjttjd�ttj	ttj
d�t|�g�ttjd�g�g�}|�
|�|�
ttjddd��ttjttjddd�t|�ttjttjd�ttj	|dkr�t|�ntdd	�ttj
d�|dkr�ttjttjd
�t|�g�ntdd	�g�ttjd�ttjd�g�g�}|�
|�|dk�r�|�
ttjddd��ttjt|dd�ttjttjd�ttj	ttjttjd
�t|�g�ttj
d�g�ttjd�g�g�}	|�
|	�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���-)ZunicoderrZpowerrZtrailerr
r
�LSQBZ	subscript�COLONr	�RSQB�append�PLUSZfactor�MINUSZ
arith_expr)Znum_preZnum_post�LISTNAME�ITERNAME�children�pre�postZpre_partZ	main_partZ	post_part�source�r'�C/usr/lib/python3/dist-packages/libpasteurize/fixes/fix_unpacking.py�assignment_sourcesJ
�

b
r)c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�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
s��fdd�dD�\}}}}dd�|D�}d|_dd�|D�}dd�t||��g|�D�}|�t��d	|_tt|j�ttd
�|��g��}t|t	t
|�t
|�|j|j��}	||	fS)Nc3s|]}��|�VqdS�N��get��.0�n��resultsr'r(�	<genexpr>3sz4FixUnpacking.fix_explicit_context.<locals>.<genexpr>)r$�namer%r&cSs g|]}|jtjkr|���qSr'��typer
�NAME�cloner.r'r'r(�
<listcomp>4sz5FixUnpacking.fix_explicit_context.<locals>.<listcomp>rcSs g|]}|jtjkr|���qSr'r5r.r'r'r(r96scSsg|]}|���qSr'�r8r.r'r'r(r97sr�list)rrr8rrrrr!rr)�lenr")
�self�noder2r$r4r%r&�target�
setup_line�
power_liner'r1r(�fix_explicit_context2s   z!FixUnpacking.fix_explicit_contextcs��fdd�dD�\}}}}dd�|D�}d|_dd�|D�}dd�t||��g|�D�}|�t��|��}d	|_tt|j�ttd
�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|]}��|�VqdSr+r,r.r1r'r(r3Esz4FixUnpacking.fix_implicit_context.<locals>.<genexpr>)r$r4r%�itcSs g|]}|jtjkr|���qSr'r5r.r'r'r(r9Fsz5FixUnpacking.fix_implicit_context.<locals>.<listcomp>rcSs g|]}|jtjkr|���qSr'r5r.r'r'r(r9HscSsg|]}|���qSr'r:r.r'r'r(r9Isrr;)rrr8rrrrr!rr"r)r<)r=r>r2r$r4r%rCr?r&r@rAr'r1r(�fix_implicit_context@s " z!FixUnpacking.fix_implicit_contextc
Cs@|�d�|_|�d�|_|�d�|�d�}}|dk	r�|�||�\}}|j|_t|j�|_|�t	��|j}|�
�}|�||�|�||�n�|dk	�r<|�||�\}}t
|�dd�|jD�d}	d	|_|	jd
j|_t|	jd�|	jd_|	�dt	��|	�d|�|	�dt	��|	�d|�|�d��t|jd
d��dS)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	_3to2iter�expl�implNcSsg|]}|jtjkr|�qSr')r6r�suite)r/�kr'r'r(r9psz*FixUnpacking.transform.<locals>.<listcomp>rrr�Zlstrr)�new_namer!r"r-rBrr�parentZappend_childr�removeZinsert_childrDrr#�value�replacer)
r=r>r2rErFr@rArK�irGr'r'r(�	transformSs0
zFixUnpacking.transformN)�__name__�
__module__�__qualname__ZPATTERNrBrDrPr'r'r'r(r*&s
r*N)�__doc__Zlib2to3r�	itertoolsrZlib2to3.fixer_utilrrrrrr	r
rrr
Zlibfuturize.fixer_utilrrrr)ZBaseFixr*r'r'r'r(�<module>s0