î
\á[\–  ã               @   si   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z m Z Gd d „  d e j	 ƒ Z
 d S)	a&  Fixer for has_key().

Calls to .has_key() methods are expressed in terms of the 'in'
operator:

    d.has_key(k) -> k in d

CAVEATS:
1) While the primary target of this fixer is dict.has_key(), the
   fixer will change any has_key() method call, regardless of its
   class.

2) Cases like this will not be converted:

    m = d.has_key
    if m(k):
        ...

   Only *calls* to has_key() are converted. While it is possible to
   convert the above to something like

    m = d.__contains__
    if m(k):
        ...

   this is currently not done.
é   )Úpytree)Útoken)Ú
fixer_base)ÚNameÚparenthesizec               @   s(   e  Z d  Z d Z d Z d d „  Z d S)Ú	FixHasKeyTa•  
    anchor=power<
        before=any+
        trailer< '.' 'has_key' >
        trailer<
            '('
            ( not(arglist | argument<any '=' any>) arg=any
            | arglist<(not argument<any '=' any>) arg=any ','>
            )
            ')'
        >
        after=any*
    >
    |
    negation=not_test<
        'not'
        anchor=power<
            before=any+
            trailer< '.' 'has_key' >
            trailer<
                '('
                ( not(arglist | argument<any '=' any>) arg=any
                | arglist<(not argument<any '=' any>) arg=any ','>
                )
                ')'
            >
        >
    >
    c          
   C   s=  | s t  ‚ |  j } | j j | j k rC |  j j | j ƒ rC d  S| j d ƒ } | d } | j } d d „  | d Dƒ } | d j	 ƒ  } | j d ƒ }	 |	 r· d d „  |	 Dƒ }	 n  | j | j
 | j | j | j | j | j | j f k rÿ t | ƒ } n  t | ƒ d	 k r| d
 } n t j | j | ƒ } d | _ t d d d ƒ}
 | r„t d d d ƒ} t j | j | |
 f ƒ }
 n  t j | j
 | |
 | f ƒ } |	 rÙt | ƒ } t j | j | f t |	 ƒ ƒ } n  | j j | j
 | j | j | j | j | j | j | j | j f	 k r0t | ƒ } n  | | _ | S)NÚnegationÚanchorc             S   s   g  |  ] } | j  ƒ  ‘ q S© )Úclone)Ú.0Únr
   r
   ú//usr/lib/python3.4/lib2to3/fixes/fix_has_key.pyú
<listcomp>S   s   	 z'FixHasKey.transform.<locals>.<listcomp>ÚbeforeÚargÚafterc             S   s   g  |  ] } | j  ƒ  ‘ q Sr
   )r   )r   r   r
   r
   r   r   W   s   	 é   é    ú ÚinÚprefixÚnot)ÚAssertionErrorÚsymsÚparentÚtypeZnot_testÚpatternÚmatchÚgetr   r   Z
comparisonZand_testZor_testZtestZlambdefZargumentr   Úlenr   ZNodeZpowerr   Zcomp_opÚtupleÚexprZxor_exprZand_exprZ
shift_exprZ
arith_exprZtermZfactor)ÚselfZnodeZresultsr   r   r	   r   r   r   r   Zn_opZn_notÚnewr
   r
   r   Ú	transformH   sF    	
	!	%	zFixHasKey.transformN)Ú__name__Ú
__module__Ú__qualname__ZBM_compatibleZPATTERNr%   r
   r
   r
   r   r   '   s   r   N)Ú__doc__Ú r   Zpgen2r   r   Z
fixer_utilr   r   ZBaseFixr   r
   r
   r
   r   Ú<module>   s
   