a
    mJh,                     @  s   d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZmZmZmZmZmZ ejdk rvd dlmZ ed	ed
edZededZeded
edZededZedddZedddZddddddZdddddZdd  ZG d!d deee ZG d"d dee eZ dS )#    )annotationsN)CallableSequence)partial)getmroisclass)TYPE_CHECKINGGenericTypeTypeVarcastoverload)      )r   _BaseExceptionT_coT)bound	covariantdefault_BaseExceptionT)r   _ExceptionT_co_ExceptionT_ExceptionGroupSelfExceptionGroup_BaseExceptionGroupSelfBaseExceptionGroupBaseExceptionztuple[type[BaseException]]bool)excparentsreturnc                 C  s*   t | jd d D ]}||v r dS qdS )NTF)r   	__class__)r   r   cls r#   L/var/www/shaz/venv/lib/python3.9/site-packages/exceptiongroup/_exceptions.pycheck_direct_subclass   s    r%   `type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...] | Callable[[_BaseExceptionT_co], bool]z$Callable[[_BaseExceptionT_co], bool])	conditionr   c                 C  sr   t | r*tttt | tr*tt| fdS t| trTt	dd | D rftt| dS nt
| rftd| S tdd S )N)r   c                 s  s    | ]}t |ot|tV  qd S N)r   
issubclassr   ).0xr#   r#   r$   	<genexpr>-       z'get_condition_filter.<locals>.<genexpr>zCallable[[BaseException], bool]z?expected a function, exception type or tuple of exception types)r   r)   r   r
   r   r   r%   
isinstancetupleallcallable	TypeError)r'   r#   r#   r$   get_condition_filter#   s    


r3   c                 C  s<   |  |}| j|_| j|_| j|_t| dr8t| j|_|S )N	__notes__)derive	__cause____context____traceback__hasattrlistr4   )selfZexcsegr#   r#   r$   _derive_and_copy_attributes5   s    

r=   c                      s`  e Zd ZdZddddd fddZddd	d
dddZdd
dddZeddddZeddddZ	e
dddddZe
dddddZe
dd dd!dZd"ddd#dZe
dd$dd%d&Ze
dd'dd(d&Ze
dd)dd*d&Zd+d,dd-d&Ze
d.d/d0d1d2Ze
d3d4d0d5d2Zd3d4d0d6d2Zddd7d8Zddd9d:Z  ZS );r   z/A combination of multiple unrelated exceptions.ztype[_BaseExceptionGroupSelf]strzSequence[_BaseExceptionT_co]r   )r"   _BaseExceptionGroup__message_BaseExceptionGroup__exceptionsr   c                   s   t |tstdt| t |ts.td|s:tdt|D ]"\}}t |tsBtd| dqB| tu rt	dd |D rt
} t| tr|D ]0}t |ts| t
u rtdqtd	| jqt | ||}t||_|S )
Nzargument 1 must be str, not z/second argument (exceptions) must be a sequencez9second argument (exceptions) must be a non-empty sequencezItem z4 of second argument (exceptions) is not an exceptionc                 s  s   | ]}t |tV  qd S r(   )r.   	Exception)r*   r   r#   r#   r$   r,   X   r-   z-BaseExceptionGroup.__new__.<locals>.<genexpr>z/Cannot nest BaseExceptions in an ExceptionGroupzCannot nest BaseExceptions in )r.   r>   r2   typer   
ValueError	enumerater   r   r0   r   r)   rA   __name__super__new__r/   _exceptions)r"   r?   r@   ir   instancer!   r#   r$   rG   C   s:    







zBaseExceptionGroup.__new__objectNone)r?   r@   argsr   c                 G  s   t j| ||g|R   d S r(   )r   __init__)r;   r?   r@   rN   r#   r#   r$   rO   k   s    zBaseExceptionGroup.__init__)noter   c                 C  sF   t |ts&td|dt|j dt| ds6g | _| j| d S )NzExpected a string, got note=z (type )r4   )r.   r>   r2   rB   rE   r9   r4   append)r;   rP   r#   r#   r$   add_notes   s    

zBaseExceptionGroup.add_noter   c                 C  s
   | j d S )Nr   )rN   r;   r#   r#   r$   message~   s    zBaseExceptionGroup.messagezGtuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]c                 C  s
   t | jS r(   )r/   rH   rU   r#   r#   r$   
exceptions   s    zBaseExceptionGroup.exceptions1type[_ExceptionT] | tuple[type[_ExceptionT], ...]"ExceptionGroup[_ExceptionT] | None)_BaseExceptionGroup__conditionr   c                 C  s   d S r(   r#   r;   rZ   r#   r#   r$   subgroup   s    zBaseExceptionGroup.subgroupz9type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]z*BaseExceptionGroup[_BaseExceptionT] | Nonec                 C  s   d S r(   r#   r[   r#   r#   r$   r\      s    z>Callable[[_BaseExceptionT_co | _BaseExceptionGroupSelf], bool]z-BaseExceptionGroup[_BaseExceptionT_co] | Nonec                 C  s   d S r(   r#   r[   r#   r#   r$   r\      s    zztype[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...] | Callable[[_BaseExceptionT_co | _BaseExceptionGroupSelf], bool]c                 C  s   t |}d}|| r| S g }| jD ]P}t|trZ||}|d urL|| ||urrd}q"||rn|| q"d}q"|s|| S |rt| |}|S d S d S )NFT)r3   rW   r.   r   r\   rR   r=   )r;   rZ   r'   modifiedrW   r   r\   groupr#   r#   r$   r\      s*    




zXtuple[ExceptionGroup[_ExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  s   d S r(   r#   r[   r#   r#   r$   split   s    zBaseExceptionGroup.splitz`tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  s   d S r(   r#   r[   r#   r#   r$   r_      s    zctuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c                 C  s   d S r(   r#   r[   r#   r#   r$   r_      s    r&   a!  tuple[ExceptionGroup[_ExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None] | tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None] | tuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]c           
      C  s   t |}|| r| d fS g }g }| jD ]`}t|trh||\}}|d urT|| |d ur|| q&||r||| q&|| q&d }|rt| |}d }	|rt| |}	||	fS r(   )r3   rW   r.   r   r_   rR   r=   )
r;   rZ   r'   Zmatching_exceptionsZnonmatching_exceptionsr   ZmatchingZnonmatchingZmatching_groupZnonmatching_groupr#   r#   r$   r_      s0    



zSequence[_ExceptionT]zExceptionGroup[_ExceptionT])_BaseExceptionGroup__excsr   c                 C  s   d S r(   r#   r;   r`   r#   r#   r$   r5     s    zBaseExceptionGroup.derivezSequence[_BaseExceptionT]z#BaseExceptionGroup[_BaseExceptionT]c                 C  s   d S r(   r#   ra   r#   r#   r$   r5     s    c                 C  s   t | j|S r(   )r   rV   ra   r#   r#   r$   r5     s    c                 C  s4   t | jdkrdnd}| j dt | j d| dS )N    sz (z sub-exceptionrQ   )lenrH   rV   )r;   suffixr#   r#   r$   __str__  s    zBaseExceptionGroup.__str__c                 C  s&   | j j d| jd d| jd dS )N(r   z, rb   rQ   )r!   rE   rN   rU   r#   r#   r$   __repr__  s    zBaseExceptionGroup.__repr__)rE   
__module____qualname____doc__rG   rO   rS   propertyrV   rW   r   r\   r_   r5   rg   ri   __classcell__r#   r#   rK   r$   r   @   s:   (!2c                      s   e Zd Zddddd fddZeredd	d
dZedddddZedddddZddd fddZedddddZ	edddddZ	dddd fddZ	  Z
S )r   ztype[_ExceptionGroupSelf]r>   zSequence[_ExceptionT_co]r   )r"   _ExceptionGroup__message_ExceptionGroup__exceptionsr   c                   s   t  | ||S r(   )rF   rG   )r"   ro   rp   rK   r#   r$   rG     s    zExceptionGroup.__new__z;tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]rT   c                 C  s   d S r(   r#   rU   r#   r#   r$   rW   #  s    zExceptionGroup.exceptionsrX   rY   )_ExceptionGroup__conditionr   c                 C  s   d S r(   r#   r;   rq   r#   r#   r$   r\   (  s    zExceptionGroup.subgroupz6Callable[[_ExceptionT_co | _ExceptionGroupSelf], bool]z%ExceptionGroup[_ExceptionT_co] | Nonec                 C  s   d S r(   r#   rr   r#   r#   r$   r\   -  s    zTtype[_ExceptionT] | tuple[type[_ExceptionT], ...] | Callable[[_ExceptionT_co], bool]c                   s   t  |S r(   )rF   r\   rr   rK   r#   r$   r\   2  s    zPtuple[ExceptionGroup[_ExceptionT] | None, ExceptionGroup[_ExceptionT_co] | None]c                 C  s   d S r(   r#   rr   r#   r#   r$   r_   :  s    zExceptionGroup.splitzStuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]c                 C  s   d S r(   r#   rr   r#   r#   r$   r_   A  s    )r;   rq   r   c                   s   t  |S r(   )rF   r_   rr   rK   r#   r$   r_   H  s    )rE   rj   rk   rG   r   rm   rW   r   r\   r_   rn   r#   r#   rK   r$   r     s   )!
__future__r   syscollections.abcr   r   	functoolsr   inspectr   r   typingr   r	   r
   r   r   r   version_infotyping_extensionsr   r   r   rA   r   r   r   r   r%   r3   r=   r   r   r#   r#   r#   r$   <module>   s.    

 Z