B
    ,‹dú  ã               @  sš   d dl mZ d dlZd dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZmZ ejdk rfdd	lmZ erxeegef ZG d
d„ dƒZdddœdd„ZdS )é    )ÚannotationsN)ÚCallableÚIterableÚMapping)ÚAbstractContextManager)ÚTracebackType)ÚTYPE_CHECKINGÚAny)é   é   é   )ÚBaseExceptionGroupc               @  sL   e Zd Zddœdd„Zddœdd„Zd	d
dddœdd„Zdddœdd„ZdS )Ú_Catcherz2Mapping[tuple[type[BaseException], ...], _Handler])Úhandler_mapc             C  s
   || _ d S )N)Ú_handler_map)Úselfr   © r   úb/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/exceptiongroup/_catch.pyÚ__init__   s    z_Catcher.__init__ÚNone)Úreturnc             C  s   d S )Nr   )r   r   r   r   Ú	__enter__   s    z_Catcher.__enter__ztype[BaseException] | NonezBaseException | NonezTracebackType | NoneÚbool)ÚetypeÚexcÚtbr   c             C  s4   |d k	r0|   |¡}||krdS |d kr*dS |d ‚dS )NFT)Úhandle_exception)r   r   r   r   Z	unhandledr   r   r   Ú__exit__   s    
z_Catcher.__exit__ÚBaseExceptionzBaseExceptionGroup | None)r   r   c             C  sÒ   t |tƒr|}ntd|gƒ}g }xh| j ¡ D ]Z\}}| |¡\}}|r€y||ƒ W n, tk
r~ } z| |¡ W d d }~X Y nX |s,P q,W |r¦|rœ| |¡ td|ƒS |rÊt|jƒdkrÊ|jd |krÊ|S |S d S )NÚ r   r   )	Ú
isinstancer   r   ÚitemsÚsplitr   ÚappendÚlenÚ
exceptions)r   r   ZexcgroupZnew_exceptionsZ	exc_typesÚhandlerZmatchedÚnew_excr   r   r   r   (   s(    


 z_Catcher.handle_exceptionN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r      s   r   zFMapping[type[BaseException] | Iterable[type[BaseException]], _Handler]zAbstractContextManager[None])Ú
__handlersr   c             C  sÀ   t | tƒstdƒ‚i }x |  ¡ D ]”\}}t |tƒrDt|tƒrD|f}nt |tƒrXt|ƒ}ntdƒ‚t	|ƒsptdƒ‚x:|D ]2}t |tƒrŽt|tƒs–tdƒ‚t|t
ƒrvtdƒ‚qvW |||< q W t|ƒS )Nzthe argument must be a mappingzCeach key must be either an exception classes or an iterable thereofzhandlers must be callablezHcatching ExceptionGroup with catch() is not allowed. Use except instead.)r    r   Ú	TypeErrorr!   ÚtypeÚ
issubclassr   r   ÚtupleÚcallabler   r   )r+   r   Ztype_or_iterabler&   ÚiterableÚexc_typer   r   r   ÚcatchH   s.    





r3   )Ú
__future__r   ÚsysÚcollections.abcr   r   r   Ú
contextlibr   Útypesr   Útypingr   r	   Úversion_infoÚ_exceptionsr   r   Z_Handlerr   r3   r   r   r   r   Ú<module>   s   
8