o
    i                     @   s~   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZmZmZ ddlmZmZmZ dd ZG dd	 d	ejZd
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	commatizec                 C   s  g }z
t | }t |}W n ty   t| }t|}Y nw | dkrWttjt|ttjtt	j
dttjtt	jdt|gtt	jdgg}|| |tt	jddd ttjtt	j
dddt|ttjtt	j
dttj| dkrwt|ntdd	tt	jd|dkrttjtt	jd
t|gntdd	gtt	jdtt	jdgg}|| |dkr|tt	jddd ttjt|ddttjtt	j
dttjttjtt	jd
t|gtt	jdgtt	jdgg}	||	 ttj|}
|
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	NameErrorstrr   r   powerr   trailerr   r
   LSQBZ	subscriptCOLONr	   RSQBappendPLUSfactorMINUSZ
arith_expr)Znum_preZnum_postLISTNAMEITERNAMEchildrenprepostZpre_partZ	main_partZ	post_partsource r-   p/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/libpasteurize/fixes/fix_unpacking.pyassignment_source   s(   J

b
r/   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	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    fdddD \}}}}dd |D }d|_ dd |D }dd t|| g | D }|t  d	|_ tt| jttd
| g}t|t	t
|t
|| j| j}	||	fS )Nc                 3       | ]}  |V  qd S Nget.0nresultsr-   r.   	<genexpr>7       z4FixUnpacking.fix_explicit_context.<locals>.<genexpr>)r*   namer+   r,   c                 S       g | ]}|j tjkr| qS r-   typer
   NAMEcloner5   r-   r-   r.   
<listcomp>8        z5FixUnpacking.fix_explicit_context.<locals>.<listcomp>r   c                 S   r=   r-   r>   r5   r-   r-   r.   rB   :   rC   c                 S      g | ]}|  qS r-   rA   r5   r-   r-   r.   rB   ;       r   list)r   r   rA   r#   r   r   r   r'   r   r/   lenr(   )
selfnoder9   r*   r<   r+   r,   target
setup_line
power_liner-   r8   r.   fix_explicit_context6   s      z!FixUnpacking.fix_explicit_contextc                    s    fdddD \}}}}dd |D }d|_ dd |D }dd t|| g | D }|t  | }d	|_ tt| jttd
t| j	g}	t|t
t|t|| j| j	}
|	|
fS )z_
        Only example of the implicit context is
        a for loop, so only fix that.
        c                 3   r1   r2   r3   r5   r8   r-   r.   r:   I   r;   z4FixUnpacking.fix_implicit_context.<locals>.<genexpr>)r*   r<   r+   itc                 S   r=   r-   r>   r5   r-   r-   r.   rB   J   rC   z5FixUnpacking.fix_implicit_context.<locals>.<listcomp>r   c                 S   r=   r-   r>   r5   r-   r-   r.   rB   L   rC   c                 S   rD   r-   rE   r5   r-   r-   r.   rB   M   rF   r   rG   )r   r   rA   r#   r   r   r   r'   r   r(   r/   rH   )rI   rJ   r9   r*   r<   r+   rO   rK   r,   rL   rM   r-   r8   r.   fix_implicit_contextD   s    " z!FixUnpacking.fix_implicit_contextc           
      C   sD  |  d| _|  d| _|d|d}}|durH| ||\}}|j|_t|j|_|t	  |j}|
 }||| ||| dS |dur| ||\}}t| dd |jD d }	d	|_|	jd
 j|_t|	jd |	jd _|	dt	  |	d| |	dt	  |	d| |dt| jdd dS dS )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implNc                 S   s   g | ]
}|j tjkr|qS r-   )r?   r   suite)r6   kr-   r-   r.   rB   t   s    z*FixUnpacking.transform.<locals>.<listcomp>r   r   r      lstr   r   )new_namer'   r(   r4   rN   r   r   parentZappend_childr   removeZinsert_childrP   r   r)   valuereplacer   )
rI   rJ   r9   rQ   rR   rL   rM   rX   irS   r-   r-   r.   	transformW   s2   zFixUnpacking.transformN)__name__
__module____qualname__ZPATTERNrN   rP   r]   r-   r-   r-   r.   r0   *   s
    
r0   N)__doc__Zlib2to3r   	itertoolsr   Zlib2to3.fixer_utilr   r   r   r   r   r	   r
   r   r   r   Zlibfuturize.fixer_utilr   r   r   r/   ZBaseFixr0   r-   r-   r-   r.   <module>   s    0