a
    ´i  ã                   @   sJ   d dl mZ d dlmZmZmZmZmZmZ dZ	dZ
G dd„ dejƒZdS )é   )Ú
fixer_base)ÚCallÚCommaÚNameÚNodeÚ	BlankLineÚsymsz0(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)z(power< 'type' trailer< '(' x=any ')' > >c                       sP   e Zd ZdZdeeeef Z‡ fdd„Zdd„ Zdd„ Z	d	d
„ Z
dd„ Z‡  ZS )Ú	FixIdiomsTaº  
        isinstance=comparison< %s %s T=any >
        |
        isinstance=comparison< T=any %s %s >
        |
        while_stmt< 'while' while='1' ':' any+ >
        |
        sorted=any<
            any*
            simple_stmt<
              expr_stmt< id1=any '='
                         power< list='list' trailer< '(' (not arglist<any+>) any ')' > >
              >
              '\n'
            >
            sort=
            simple_stmt<
              power< id2=any
                     trailer< '.' 'sort' > trailer< '(' ')' >
              >
              '\n'
            >
            next=any*
        >
        |
        sorted=any<
            any*
            simple_stmt< expr_stmt< id1=any '=' expr=any > '\n' >
            sort=
            simple_stmt<
              power< id2=any
                     trailer< '.' 'sort' > trailer< '(' ')' >
              >
              '\n'
            >
            next=any*
        >
    c                    s8   t t| ƒ |¡}|r4d|v r4|d |d kr0|S d S |S )NÚsortedZid1Zid2)Úsuperr	   Úmatch)ÚselfÚnodeÚr©Ú	__class__© ú0/usr/lib64/python3.9/lib2to3/fixes/fix_idioms.pyr   O   s    zFixIdioms.matchc                 C   sH   d|v r|   ||¡S d|v r(|  ||¡S d|v r<|  ||¡S tdƒ‚d S )NÚ
isinstanceÚwhiler
   zInvalid match)Útransform_isinstanceÚtransform_whileÚtransform_sortÚRuntimeError)r   r   Úresultsr   r   r   Ú	transformZ   s    zFixIdioms.transformc                 C   sh   |d   ¡ }|d   ¡ }d|_d|_ttdƒ|tƒ |gƒ}d|v r\d|_ttjtdƒ|gƒ}|j|_|S )NÚxÚTÚ ú r   ÚnÚnot)ÚcloneÚprefixr   r   r   r   r   Znot_test)r   r   r   r   r   Útestr   r   r   r   d   s    zFixIdioms.transform_isinstancec                 C   s    |d }|  td|jd�¡ d S )Nr   ÚTrue©r#   )Úreplacer   r#   )r   r   r   Zoner   r   r   r   p   s    zFixIdioms.transform_whilec                 C   sà   |d }|d }|  d¡}|  d¡}|r>| td|jd�¡ n8|rn| ¡ }d|_| ttdƒ|g|jd�¡ ntdƒ‚| ¡  |j}d	|v rÜ|rº| d	¡d
 |d
 jf}	d	 	|	¡|d
 _n"t
ƒ }
|j |
¡ | d	¡d
 |
_d S )NÚsortÚnextÚlistÚexprr
   r&   r   zshould not have reached hereÚ
é    )Úgetr'   r   r#   r"   r   r   ÚremoveÚ
rpartitionÚjoinr   ÚparentZappend_child)r   r   r   Z	sort_stmtZ	next_stmtZ	list_callZsimple_exprÚnewZbtwnZprefix_linesZend_liner   r   r   r   t   s,    

ÿ
zFixIdioms.transform_sort)Ú__name__Ú
__module__Ú__qualname__ZexplicitÚTYPEÚCMPZPATTERNr   r   r   r   r   Ú__classcell__r   r   r   r   r	   %   s   %
Û'
r	   N)r   r   Z
fixer_utilr   r   r   r   r   r   r8   r7   ZBaseFixr	   r   r   r   r   Ú<module>   s    