3 \ @sfdZddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z ddZ Gdd d ejZd S) aFixer 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)AssignAttrNameis_tupleis_listsymsccsHxBt|D]6\}}|jtjkr |jdjdkr |||dfVq WdS)Nexceptr) enumeratetyper except_clausechildrenvalue)Znodesinr"/usr/lib64/python3.6/fix_except.py find_exceptss rc@seZdZdZdZddZdS) 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|jdkr6|jdd\}} } | jtdd d | jtjkrDt|j d d } | j } d | _ | j| | j } |j} x"t | D]\}}t |tjrPqWt| st| rt| t| td }n t| | }x&t| d|D]}|jd |q W|j||q6| j d kr6d | _ q6Wdd|jddD||}tj|j|S)NcSsg|] }|jqSr)clone).0rrrr 2sz'FixExcept.transform..tailcSsg|] }|jqSr)r)rZchrrrr4sZcleanupas )prefixargsr cSsg|] }|jqSr)r)rcrrrr\s)r rlenrreplacerrrNAMEnew_namerr r isinstancerZNoderr rrreversedZ insert_child)selfZnoderesultsr rZ try_cleanuprZe_suiteEZcommaNZnew_NtargetZ suite_stmtsrZstmtZassignZchildrrrr transform/s6      zFixExcept.transformN)__name__ __module__ __qualname__Z BM_compatibleZPATTERNr0rrrrr$srN)__doc__r!rZpgen2rrZ fixer_utilrrrrr r rZBaseFixrrrrrs