3
\
ã @ sf d Z ddlmZ ddlmZ ddlmZ ddlmZmZm Z m
Z
mZmZ dd„ Z
G dd „ 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Úsymsc c sH xBt | ƒD ]6\}}|jtjkr
|jd jdkr
|| |d fV q
W d S )Né Úexceptr )Ú enumerateÚtyper
Ú
except_clauseÚchildrenÚvalue)ZnodesÚiÚn© r ú0/usr/lib64/python3.6/lib2to3/fixes/fix_except.pyÚfind_excepts s r c @ s e Zd ZdZdZdd„ 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)]) >
c C s† | j }dd„ |d D ƒ}dd„ |d D ƒ}�x*t|ƒD �]\}}t|jƒdkr6|jdd… \}} }
| jtdd d
�ƒ |
jtjk�rDt| j ƒ d d
�}|
j
ƒ }d|_|
j|ƒ |j
ƒ }|j}
x"t|
ƒD ]\}}t
|tjƒrÂP qÂW t|
ƒsît|
ƒ�rt|t|tdƒƒƒ}n
t||ƒ}x&t|
d |… ƒD ]}|jd
|ƒ �q W |j||ƒ q6|
jdkr6d |
_q6W dd„ |jd d… D ƒ| | }tj|j|ƒS )Nc S s g | ]}|j ƒ ‘qS r )Úclone)Ú.0r r r r ú