o
    hH                     @  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 r7dd	lmZ erBeee gef ZG d
d dZdddZdS )    )annotationsN)CallableIterableMapping)AbstractContextManager)TracebackType)TYPE_CHECKINGAny)         )BaseExceptionGroupc                   @  s4   e Zd ZdddZdddZdddZdddZdS )_Catcherhandler_map2Mapping[tuple[type[BaseException], ...], _Handler]c                 C  s
   || _ d S N)_handler_map)selfr    r   i/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/exceptiongroup/_catch.py__init__   s   
z_Catcher.__init__returnNonec                 C  s   d S r   r   )r   r   r   r   	__enter__   s   z_Catcher.__enter__etypetype[BaseException] | NoneexcBaseException | NonetbTracebackType | Noneboolc                 C  s`   |d ur.|  |}||u rdS |d u rdS t|tr+z||j ty*   |j|_ w ||dS )NFT)handle_exception
isinstancer   	__cause____context__)r   r   r   r   	unhandledr   r   r   __exit__   s   

z_Catcher.__exit__BaseExceptionc           	      C  sP  t |tr|}ntd|g}g }| j D ]m\}}||\}}|r~zz| ty2   ||}Y nw W n8 tyV } z||u rF|| n||j W Y d }~n,d }~w tyl } z|| W Y d }~nd }~ww t	
|r~td|d|d||s nq|rt|dkr|d S td|S |rt|jdkr|jd |u r|S |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   excgroupnew_exceptions	exc_typeshandlermatchedresultnew_excr   r   r   r!   2   sR   


z_Catcher.handle_exceptionN)r   r   )r   r   )r   r   r   r   r   r   r   r    )r   r'   r   r   )__name__
__module____qualname__r   r   r&   r!   r   r   r   r   r      s
    


r   
__handlersFMapping[type[BaseException] | Iterable[type[BaseException]], _Handler]r   AbstractContextManager[None]c                 C  s   t | ts	tdi }|  D ]H\}}t |tr!t|tr!|f}nt |tr+t|}ntdt	|s7td|D ]}t |trEt|tsItdt|t
rRtdq9|||< 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   r0   r)   type
issubclassr'   r   tuplecallabler   r   )r<   r   type_or_iterabler5   iterableexc_typer   r   r   catch`   s<   




rF   )r<   r=   r   r>   )
__future__r   r.   syscollections.abcr   r   r   
contextlibr   typesr   typingr   r	   version_info_exceptionsr   _Handlerr   rF   r   r   r   r   <module>   s    
O