AlkantarClanX12

Your IP : 18.191.9.9


Current Path : /opt/alt/python34/lib64/python3.4/lib2to3/fixes/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/lib2to3/fixes/__pycache__/fix_idioms.cpython-34.pyc

�
j f�@smdZddlmZddlmZmZmZmZmZm	Z	dZ
dZGdd�dej�Z
dS)	a�Adjust some old Python 2 idioms to their modern counterparts.

* Change some type comparisons to isinstance() calls:
    type(x) == T -> isinstance(x, T)
    type(x) is T -> isinstance(x, T)
    type(x) != T -> not isinstance(x, T)
    type(x) is not T -> not isinstance(x, T)

* Change "while 1:" into "while True:".

* Change both

    v = list(EXPR)
    v.sort()
    foo(v)

and the more general

    v = EXPR
    v.sort()
    foo(v)

into

    v = sorted(EXPR)
    foo(v)
�)�
fixer_base)�Call�Comma�Name�Node�	BlankLine�symsz0(n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)z(power< 'type' trailer< '(' x=any ')' > >csneZdZdZdeeeefZ�fdd�Zdd�Zdd�Z	d	d
�Z
dd�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*
        >
    csJtt|�j|�}|rFd|krF|d|dkrB|SdS|S)N�sortedZid1Zid2)�superr	�match)�self�node�r)�	__class__��=/opt/alt/python34/lib64/python3.4/lib2to3/fixes/fix_idioms.pyrOszFixIdioms.matchcCsdd|kr|j||�Sd|kr8|j||�Sd|krT|j||�Std��dS)N�
isinstance�whiler
z
Invalid match)�transform_isinstance�transform_while�transform_sort�RuntimeError)r
r�resultsrrr�	transformZszFixIdioms.transformcCs�|dj�}|dj�}d|_d|_ttd�|t�|g�}d|kr�d|_ttjtd�|g�}n|j|_|S)N�x�T�� r�n�not)�clone�prefixrrrrrZnot_test)r
rrrrZtestrrrrds		!	!zFixIdioms.transform_isinstancecCs*|d}|jtdd|j��dS)Nr�Truer")�replacerr")r
rrZonerrrrps
zFixIdioms.transform_whilecCsv|d}|d}|jd�}|jd�}|rW|jtdd|j��nR|r�|j�}d|_|jttd�|gd|j��ntd��|j�|j}d	|krr|r|jd	�d
|d
jf}	d	j	|	�|d
_qr|j
st�|jdks+t�t
�}
|j
j|
�|j|
ksYt�|jd	�d
|
_ndS)N�sort�next�list�exprr
r"rzshould not have reached here�
�)�getr$rr"r!rr�remove�
rpartition�join�parent�AssertionErrorZnext_siblingrZappend_child)r
rrZ	sort_stmtZ	next_stmtZ	list_callZsimple_expr�newZbtwnZprefix_linesZend_linerrrrts0

	
	 	zFixIdioms.transform_sort)�__name__�
__module__�__qualname__Zexplicit�TYPE�CMPZPATTERNrrrrrrr)rrr	%s'
r	N)�__doc__rrZ
fixer_utilrrrrrrr6r5ZBaseFixr	rrrr�<module>s
.