a
    xd                     @  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   M/var/www/html/Ranjet/env/lib/python3.9/site-packages/exceptiongroup/_catch.py__init__   s    z_Catcher.__init__None)returnc                 C  s   d S r   r   )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 ur0|  |}||u rdS |d u 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 }| j D ]^\}}||\}}|rz|| W n. ty~ } z|| W Y d }~n
d }~0 0 |s* qq*|r|r|| td|S |rt|jdkr|jd |u r|S |S d S )N r   r   )	
isinstancer   r   itemssplitr   appendlen
exceptions)r   r   ZexcgroupZnew_exceptionsZ	exc_typeshandlermatchednew_excr   r   r   r   (   s2    
 

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 }|  D ]\}}t |trBt|trB|f}nt |trVt|}ntdt	|sntd|D ]2}t |trt|tstdt|t
rrtdqr|||< q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:    




r5   )
__future__r   syscollections.abcr   r   r   
contextlibr   typesr   typingr   r	   version_info_exceptionsr   r   Z_Handlerr   r5   r   r   r   r   <module>   s   
8