î j f ã@s�dZddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z dd„Z Gdd „d ejƒZd S) aªFixer for except statements with named exceptions. The following cases will be converted: - "except E, T:" where T is a name: except E as T: - "except E, T:" where T is not a name, tuple or list: except E as t: T = t This is done because the target of an "except" clause must be a name. - "except E, T:" where T is a tuple or list literal: except E as t: T = t.args é)Úpytree)Útoken)Ú fixer_base)ÚAssignÚAttrÚNameÚis_tupleÚis_listÚsymsccsbx[t|ƒD]M\}}|jtjkr |jdjdkrZ|||dfVqZq q WdS)NéÚexceptr)Ú enumerateÚtyper Ú except_clauseÚchildrenÚvalue)ZnodesÚiÚn©rú=/opt/alt/python34/lib64/python3.4/lib2to3/fixes/fix_except.pyÚ find_exceptssrc@s(eZdZdZdZdd„ZdS)Ú FixExceptTa1 try_stmt< 'try' ':' (simple_stmt | suite) cleanup=(except_clause ':' (simple_stmt | suite))+ tail=(['except' ':' (simple_stmt | suite)] ['else' ':' (simple_stmt | suite)] ['finally' ':' (simple_stmt | suite)]) > cCs|j}dd„|dDƒ}dd„|dDƒ}x¢t|ƒD]”\}}t|jƒdkrD|jdd…\}} } | jtdd d ƒƒ| jtjkrºt|j ƒd d ƒ} | j ƒ} d | _ | j| ƒ| j ƒ} |j} x0t | ƒD]"\}}t |tjƒrPqqWt| ƒsFt| ƒrgt| t| td ƒƒƒ}nt| | ƒ}x.t| d|…ƒD]}|jd |ƒq�W|j||ƒqØ| j d krØd | _ qØqDqDWdd„|jdd…Dƒ||}tj|j|ƒS)NcSsg|]}|jƒ‘qSr)Úclone)Ú.0rrrrú 2s z'FixExcept.transform..ÚtailcSsg|]}|jƒ‘qSr)r)rZchrrrr4s ZcleanupééÚasÚprefixú ÚÚargsr cSsg|]}|jƒ‘qSr)r)rÚcrrrr\s é)r rÚlenrÚreplacerrrÚNAMEÚnew_namerrr Ú isinstancerZNoderr rrÚreversedZ insert_child)ÚselfZnodeZresultsr rZ try_cleanuprZe_suiteÚEZcommaÚNZnew_NÚtargetZ suite_stmtsrZstmtZassignZchildrrrrÚ transform/s6      !(zFixExcept.transformN)Ú__name__Ú __module__Ú __qualname__Z BM_compatibleZPATTERNr/rrrrr$s rN)Ú__doc__r!rZpgen2rrZ fixer_utilrrrrr r rZBaseFixrrrrrÚs .