\d| XdZddlmZddlmZddlmZmZGddejZdS)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) fixer_base)Name parenthesizeceZdZdZdZdZdS) FixHasKeyTa anchor=power< before=any+ trailer< '.' 'has_key' > trailer< '(' ( not(arglist | argument) arg=any ','> ) ')' > after=any* > | negation=not_test< 'not' anchor=power< before=any+ trailer< '.' 'has_key' > trailer< '(' ( not(arglist | argument) arg=any ','> ) ')' > > > c R|sJ|j}|jj|jkr!|j|jrdS|d}|d}|j}d|dD}|d}|d} | r d| D} |j|j |j|j |j |j |j |jfvrt|}t!|dkr |d }nt#j|j|}d |_t)d d } |r-t)d d } t#j|j| | f} t#j|j || |f} | r:t| } t#j|j| ft-| z} |jj|j |j|j|j|j|j|j|j|jf vrt| } || _| S)Nnegationanchorc6g|]}|Sclone.0ns *..\python\lib\lib2to3\fixes\fix_has_key.py z'FixHasKey.transform..Rs 777!''))777beforeargafterc6g|]}|Sr rrs rrz'FixHasKey.transform..Vs ...1QWWYY...r in)prefixnot)symsparenttypenot_testpatternmatchgetrr comparisonand_testor_testtestlambdefargumentrlenrNodepowerrcomp_optupleexprxor_exprand_expr shift_expr arith_exprtermfactor) selfnoderesultsr r r rrrrn_opn_notnews r transformzFixHasKey.transformGs#y K  - - L  t{ + + .4;;z**"77WX%6777en""$$ G$$  /.....E 8  dit}N N Ns##C v;;!  AYFF[V44F D%%%  <s+++E;t|eT];;Dk$/Cv+>??  As##C+dj3&5<<*?@@C ; DM $ t $ $ TZ 9 9 9s##C  rN)__name__ __module__ __qualname__ BM_compatiblePATTERNr?r rrrr&s/MG<&&&&&rrN) __doc__rr fixer_utilrrBaseFixrr rrrIs:++++++++GGGGG "GGGGGr