Your IP : 18.191.205.149
�
��f c @ sm d Z d d l m Z d d l m Z m Z m Z m Z m Z m Z d Z
d Z Gd d � d e j � Z
d S( u� 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)
i ( u
fixer_base( u Callu Commau Nameu Nodeu BlankLineu symsu0 (n='!=' | '==' | 'is' | n=comp_op< 'is' 'not' >)u( power< 'type' trailer< '(' x=any ')' > >c sr | Ee 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 � S(
u FixIdiomsu�
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 sJ t t | � j | � } | rF d | k rF | d | d k rB | Sd S| S( Nu sortedu id1u id2( u superu FixIdiomsu matchu None( u selfu nodeu r( u __class__( u= /opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_idioms.pyu matchO s u FixIdioms.matchc C sd d | k r | j | | � Sd | k r8 | j | | � Sd | k rT | j | | � St d � � d S( Nu
isinstanceu whileu sortedu
Invalid match( u transform_isinstanceu transform_whileu transform_sortu RuntimeError( u selfu nodeu results( ( u= /opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_idioms.pyu transformZ s u FixIdioms.transformc C s� | d j � } | d j � } d | _ d | _ t t d � | t � | g � } d | k r� d | _ t t j t d � | g � } n | j | _ | S( Nu xu Tu u u
isinstanceu nu not( u cloneu prefixu Callu Nameu Commau Nodeu symsu not_test( u selfu nodeu resultsu xu Tu test( ( u= /opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_idioms.pyu transform_isinstanced s ! !u FixIdioms.transform_isinstancec C s* | d } | j t d d | j �� d S( Nu whileu Trueu prefix( u replaceu Nameu prefix( u selfu nodeu resultsu one( ( u= /opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_idioms.pyu transform_whilep s
u FixIdioms.transform_whilec C sv | d } | d } | j d � } | j d � } | rW | j t d d | j �� nR | r� | j � } d | _ | j t t d � | g d | j �� n t d � � | j � | j } d | k rr| r| j d � d
| d
j f } d j | � | d
_ qr| j
st � | j d k s+t � t � }
| j
j |
� | j |
k sYt � | j d � d
|
_ n d S( Nu sortu nextu listu expru sortedu prefixu u should not have reached hereu
i ( u getu replaceu Nameu prefixu cloneu Callu RuntimeErroru removeu
rpartitionu joinu parentu AssertionErroru next_siblingu Noneu BlankLineu append_child( u selfu nodeu resultsu sort_stmtu next_stmtu list_callu simple_expru newu btwnu prefix_linesu end_line( ( u= /opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_idioms.pyu transform_sortt s0
u FixIdioms.transform_sortT(
u __name__u
__module__u __qualname__u Trueu explicitu TYPEu CMPu PATTERNu matchu transformu transform_isinstanceu transform_whileu transform_sort( u
__locals__( ( u __class__u= /opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_idioms.pyu FixIdioms% s '
u FixIdiomsN( u __doc__u u
fixer_baseu
fixer_utilu Callu Commau Nameu Nodeu BlankLineu symsu CMPu TYPEu BaseFixu FixIdioms( ( ( u= /opt/alt/python33/lib64/python3.3/lib2to3/fixes/fix_idioms.pyu <module> s
.