î i f– ã@sidZddlmZddlmZddlmZddlmZmZGdd„dej ƒZ dS) 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(eZdZdZdZdd„ZdS)Ú 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 Cs1|j}|jj|jkr7|jj|jƒr7dS|jdƒ}|d}|j}dd„|dDƒ}|djƒ}|jdƒ} | r«dd„| Dƒ} n|j|j |j|j |j |j |j |jfkrót|ƒ}nt|ƒd kr|d }ntj|j|ƒ}d |_td d d ƒ} |rxtdd d ƒ} tj|j| | fƒ} ntj|j || |fƒ} | rÍt| ƒ} tj|j| ft| ƒƒ} n|jj|j |j|j|j|j|j|j|j|jf kr$t| ƒ} n|| _| S)NÚnegationÚanchorcSsg|]}|jƒ‘qS©)Úclone)Ú.0Únr r ú>/opt/alt/python34/lib64/python3.4/lib2to3/fixes/fix_has_key.pyú Ss z'FixHasKey.transform..ÚbeforeÚargÚaftercSsg|]}|jƒ‘qSr )r )r r r r rrWs ééú ÚinÚprefixÚnot)ÚsymsÚparentÚtypeZnot_testÚpatternÚmatchÚgetrr Z comparisonZand_testZor_testZtestZlambdefZargumentrÚlenrZNodeZpowerrZcomp_opÚtupleÚexprZxor_exprZand_exprZ shift_exprZ arith_exprZtermZfactor) ÚselfZnodeZresultsrrr rrrrZn_opZn_notÚnewr r rÚ transformHsD   !   %   zFixHasKey.transformN)Ú__name__Ú __module__Ú __qualname__Z BM_compatibleZPATTERNr$r r r rr's rN) Ú__doc__ÚrZpgen2rrZ fixer_utilrrZBaseFixrr r r rÚs