a
    [gH                     @  s   d dl mZ d dl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 rndd	lmZ eree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   c/var/www/html/cobodadashboardai.evdpl.com/venv/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  sh   |d urd|  |}||u rdS |d u r*dS t|tr^z||jW n ty\   |j|_ Y n0 ||dS )NFT)handle_exception
isinstancer   	__cause____context__)r   r   r   r   Z	unhandledr   r   r   __exit__   s    

z_Catcher.__exit__BaseException)r   r   c           	      C  sh  t |tr|}ntd|g}g }| j D ]\}}||\}}|rz(z|W n tyj   ||}Y n0 W np ty } z,||u r|| n||j W Y d }~nZd }~0  ty } z|| W Y d }~n.d }~0 0 t	
|rtd|d|d||s* qq*|r6t|dkr,|d S td|S |r`t|jdkr`|jd |u r`|S |S d S )N zError trying to handle z with z,. Exception handler must be a sync function.r   r   )r   r   r   itemssplitappendextend
exceptionsr"   inspectiscoroutine	TypeErrorlen)	r   r   ZexcgroupZnew_exceptionsZ	exc_typeshandlerZmatchedresultnew_excr   r   r   r   2   sL    
  
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   r+   r$   type
issubclassr"   r   tuplecallabler   r   )r3   r   Ztype_or_iterabler-   iterableexc_typer   r   r   catch`   s:    




r:   )
__future__r   r)   syscollections.abcr   r   r   
contextlibr   typesr   typingr   r	   version_info_exceptionsr   Z_Handlerr   r:   r   r   r   r   <module>   s   
O