a
    0c:                     @   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 }t | }t |}| dkrt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rt|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    -)unicoder   r   powerr   trailerr   r
   LSQB	subscriptCOLONr	   RSQBappendPLUSfactorMINUS
arith_expr)Znum_preZnum_postLISTNAMEITERNAMEchildrenprepostZpre_partZ	main_partZ	post_partsource r-   j/var/www/html/stable-diffusion-webui/venv/lib/python3.9/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   s   | ]}  |V  qd S Nget.0nresultsr-   r.   	<genexpr>3       z4FixUnpacking.fix_explicit_context.<locals>.<genexpr>)r*   namer+   r,   c                 S   s    g | ]}|j tjkr| qS r-   typer
   NAMEcloner4   r-   r-   r.   
<listcomp>4   r:   z5FixUnpacking.fix_explicit_context.<locals>.<listcomp>r   c                 S   s    g | ]}|j tjkr| qS r-   r<   r4   r-   r-   r.   r@   6   r:   c                 S   s   g | ]}|  qS r-   r?   r4   r-   r-   r.   r@   7   r:   r   list)r   r   r?   r"   r   r   r   r'   r   r/   lenr(   )
selfnoder8   r*   r;   r+   r,   target
setup_line
power_liner-   r7   r.   fix_explicit_context2   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   s   | ]}  |V  qd S r1   r2   r4   r7   r-   r.   r9   E   r:   z4FixUnpacking.fix_implicit_context.<locals>.<genexpr>)r*   r;   r+   itc                 S   s    g | ]}|j tjkr| qS r-   r<   r4   r-   r-   r.   r@   F   r:   z5FixUnpacking.fix_implicit_context.<locals>.<listcomp>r   c                 S   s    g | ]}|j tjkr| qS r-   r<   r4   r-   r-   r.   r@   H   r:   c                 S   s   g | ]}|  qS r-   rA   r4   r-   r-   r.   r@   I   r:   r   rB   )r   r   r?   r"   r   r   r   r'   r   r(   r/   rC   )rD   rE   r8   r*   r;   r+   rJ   rF   r,   rG   rH   r-   r7   r.   fix_implicit_context@   s     " z!FixUnpacking.fix_implicit_contextc           
      C   s@  |  d| _|  d| _|d|d }}|dur| ||\}}|j|_t|j|_|t	  |j}|
 }||| ||| n|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 )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)r5   kr-   r-   r.   r@   p   r:   z*FixUnpacking.transform.<locals>.<listcomp>r   r   r      lstr   r   )new_namer'   r(   r3   rI   r   r   parentappend_childr   removeinsert_childrK   r   r)   valuereplacer   )
rD   rE   r8   rL   rM   rG   rH   rS   irN   r-   r-   r.   	transformS   s0    
zFixUnpacking.transformN)__name__
__module____qualname__ZPATTERNrI   rK   rZ   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