
    ,hg                       d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZmZmZmZmZ d dlmZ er/d dlZd dlZd dlmZmZ d d	lmZmZmZ d d
lmZmZ  edeed      Znd dl
mZ  eded      Z eded      Z  ede      Z! ede      Z" ede#      Z$ ede#      Z%ejL                  dk  rd dl'm(Z(m)Z) e G d dee                Z*ere*Z+n	 d dl,m+Z+ d,dZ. ej^                  d      j`                  Z1d-dZ2d.dZ3d/dZ4	 	 	 	 	 	 d0d Z5 G d! d"eee          Z6e G d# d$e6e                Z7e G d% d&e6e(e                    Z8e G d' d(             Z9 G d) d*      Z:d1d2d+Z;y# e-$ r e*Z+Y w xY w)3    )annotationsN)ABCabstractmethod)Pattern)indent)TYPE_CHECKINGGenericLiteralcastoverload)final)CallableSequence)ExceptionChainReprReprExceptionInfo	Traceback)	TypeGuardTypeVarMatchET)bounddefault	covariant)r   )r   r   BaseExcT_co
BaseExcT_1)r   
BaseExcT_2ExcT_1ExcT_2)      )BaseExceptionGroupExceptionGroupc                      e Zd ZU dZded<   	 	 	 	 ddZ	 	 	 	 ddZedd       Ze	dd       Z
e	dd       Ze	dd	       Zddd
Z	 	 	 	 ddZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)_ExceptionInfozMinimal re-implementation of pytest.ExceptionInfo, only used if pytest is not available. Supports a subset of its features necessary for functionality of :class:`trio.testing.RaisesGroup` and :class:`trio.testing.Matcher`.7tuple[type[MatchE], MatchE, types.TracebackType] | None_excinfoc                    || _         y Nr%   )selfexcinfos     \/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/trio/testing/_raises_group.py__init__z_ExceptionInfo.__init__:   s          c                8    | j                   J d       || _         y)z<Fill an unfilled ExceptionInfo created with ``for_later()``.Nz ExceptionInfo was already filledr(   )r)   exc_infos     r+   fill_unfilledz_ExceptionInfo.fill_unfilled@   s    
 }}$H&HH r-   c                     | d      S )z!Return an unfilled ExceptionInfo.N )clss    r+   	for_laterz_ExceptionInfo.for_laterH   s     4yr-   c                F    | j                   J d       | j                   d   S )zThe exception class.z6.type can only be used after the context manager exitsr   r(   r)   s    r+   typez_ExceptionInfo.typeN   s.     MM%	DC	D }}Qr-   c                F    | j                   J d       | j                   d   S )zThe exception value.z7.value can only be used after the context manager exits   r(   r6   s    r+   valuez_ExceptionInfo.valueV   s.     MM%	ED	E }}Qr-   c                F    | j                   J d       | j                   d   S )zThe exception raw traceback.z4.tb can only be used after the context manager exits   r(   r6   s    r+   tbz_ExceptionInfo.tb^   s.     MM%	BA	B }}Qr-   c                    t        d      Nz_This is a helper method only available if you use RaisesGroup with the pytest package installedNotImplementedError)r)   tryshorts     r+   exconlyz_ExceptionInfo.exconlyf   s    !m
 	
r-   c                    t        d      r?   r@   )r)   excs     r+   errisinstancez_ExceptionInfo.errisinstancek   s     "m
 	
r-   c                    t        d      r?   r@   )r)   
showlocalsstyleabspathtbfilterfuncargstruncate_localschains           r+   getreprz_ExceptionInfo.getreprs   s     "m
 	
r-   N)r*   r$   returnNone)r/   z0tuple[type[MatchE], MatchE, types.TracebackType]rP   rQ   )rP   z_ExceptionInfo[MatchE])rP   type[MatchE])rP   r   )rP   ztypes.TracebackType)F)rB   boolrP   str)rE   zGbuiltins.type[BaseException] | tuple[builtins.type[BaseException], ...]rP   rS   )FlongFTFTT)rH   rS   rI   rT   rJ   rS   rK   z,bool | Callable[[_ExceptionInfo], Traceback]rL   rS   rM   rS   rN   rS   rP   z&ReprExceptionInfo | ExceptionChainRepr)__name__
__module____qualname____doc____annotations__r,   r0   classmethodr4   propertyr7   r:   r=   rC   rF   rO   r2   r-   r+   r#   r#   4   s    iEE H  
 !B! 
!  
            


T
 

 !AE $

 
 	

 ?
 
 
 
 
0
r-   r#   )ExceptionInfoc           	     h    dj                  t        | dt        |             gt        | dg             S )N
message	__notes__)joingetattrrT   )rE   s    r+   _stringify_exceptionrd      s9    99CCH-	
S+r*	
 r-    c                D    | j                   t        k(  r| j                  S | S )zJhelper function to remove redundant `re.compile` calls when printing regex)flags_REGEX_NO_FLAGSpattern)matchs    r+   _match_patternrk      s    !KK?:5==EEr-   c                    t        |       S )zuGet the repr of a ``check`` parameter.

    Split out so it can be monkeypatched (e.g. by our hypothesis plugin)
    )repr)funs    r+   repr_callablero      s    
 9r-   c                ,    t        | j                        S r'   )rm   rV   es    r+   _exception_type_namers      s    

r-   c                    | y t        ||       sNt        t        |            }t        |       }t        |t              rt	        | t              sd| d| S | d| S y )NzUnexpected nested z, expected z is not of type )
isinstancers   r7   r    
issubclass)expected_type	exceptionactual_type_strexpected_type_strs       r+   _check_raw_typer{      s~      /tI?0?i!34Z->
 ('8DUCVWW!""23D2EFFr-   c                  p    e Zd ZdZ	 	 	 	 	 	 ddZed	d       Z	 	 	 	 	 	 d
dZddZe		 	 	 	 	 	 dd       Z
y)AbstractMatcherzDABC with common functionality shared between Matcher and RaisesGroupc                    t        |t              rt        j                  |      | _        n|| _        || _        d | _        d| _        y )NF)ru   rT   recompilerj   check_fail_reason_nestedr)   rj   r   s      r+   r,   zAbstractMatcher.__init__   s=    
 eS!.0jj.?DJDJ
(, #r-   c                    | j                   S )zSet after a call to `matches` to give a human-readable
        reason for why the match failed.
        When used as a context manager the string will be given as the text of an
        `AssertionError`)r   r6   s    r+   fail_reasonzAbstractMatcher.fail_reason   s        r-   c                    | j                   y| j                  |      ry| j                  rdndt        | j                         z   }d| d| _        y)NTre    r   z did not return TrueF)r   r   ro   r   )r)   rx   
check_reprs      r+   _check_checkzAbstractMatcher._check_check   sP     ::::i <<RS=3L-L
#J</CDr-   c                d   | j                   +t        j                  | j                   t        |      x}      ryt	        |t
              rdt        t        |             nd}dt        | j                         d|| | _	        t        | j                         |k(  r| xj                  dz  c_	        y)NTz of re   zRegex pattern z did not match z+
  Did you mean to `re.escape()` the regex?F)
rj   r   searchrd   ru   r    rs   r7   rk   r   )r)   rr   stringified_exceptionmaybe_specify_types       r+   _check_matchzAbstractMatcher._check_match   s    ::JJ%9!%<<!"
  !/0 'Q012 	
 -^DJJ-G,J/ZoYr  tF  sG  H$**%)>>!OOr-   c                     y)zCheck if an exception matches the requirements of this AbstractMatcher.
        If it fails, `AbstractMatcher.fail_reason` should be set.
        Nr2   r)   exc_vals     r+   matcheszAbstractMatcher.matches   s    r-   N)rj   str | Pattern[str] | Noner   z$Callable[[BaseExcT_co], bool] | NonerP   rQ   )rP   
str | None)r)   AbstractMatcher[BaseExcT_1]rx   r   rP   rS   )rr   BaseExceptionrP   rS   )r)   r   r   r   rP   zTypeGuard[BaseExcT_1])rV   rW   rX   rY   r,   r\   r   r   r   r   r   r2   r-   r+   r}   r}      s    N#(# 4# 
	# ! !) 
& )4A	 r-   r}   c                       e Zd ZdZe	 	 d	 	 	 	 	 	 	 dd       Zedd	 	 	 	 	 	 	 dd       Zedd       Z	 	 	 d	 	 	 	 	 d fdZ	 	 	 	 ddZdd	Zdd
Z xZ	S )Matchera  Helper class to be used together with RaisesGroups when you want to specify requirements on sub-exceptions. Only specifying the type is redundant, and it's also unnecessary when the type is a nested `RaisesGroup` since it supports the same arguments.
    The type is checked with `isinstance`, and does not need to be an exact match. If that is wanted you can use the ``check`` parameter.
    :meth:`Matcher.matches` can also be used standalone to check individual exceptions.

    Examples::

        with RaisesGroups(Matcher(ValueError, match="string")):
            ...
        with RaisesGroups(Matcher(check=lambda x: x.args == (3, "hello"))):
            ...
        with RaisesGroups(Matcher(check=lambda x: type(x) is ValueError)):
            ...

    Tip: if you install ``hypothesis`` and import it in ``conftest.py`` you will get
    readable ``repr``s of ``check`` callables in the output.
    .c                     y r'   r2   )r)   exception_typerj   r   s       r+   r,   zMatcher.__init__  s     r-   )r   c                    y r'   r2   r   s      r+   r,   zMatcher.__init__%       r-   c                    y r'   r2   )r)   r   s     r+   r,   zMatcher.__init__.  s    KNr-   c                    t         |   ||       |||t        d      |t        |t              st        d| d      || _        y )Nz4You must specify at least one parameter to match on.zexception_type z$ must be a subclass of BaseException)superr,   
ValueErrorrv   r   r   )r)   r   rj   r   	__class__s       r+   r,   zMatcher.__init__1  sb     	&!emSTT%j.W!.!11UV  -r-   c                l    | j                  |      sy| j                  |      sy| j                  |      S )a  Check if an exception matches the requirements of this Matcher.
        If it fails, `Matcher.fail_reason` will be set.

        Examples::

            assert Matcher(ValueError).matches(my_exception)
            # is equivalent to
            assert isinstance(my_exception, ValueError)

            # this can be useful when checking e.g. the ``__cause__`` of an exception.
            with pytest.raises(ValueError) as excinfo:
                ...
            assert Matcher(SyntaxError, match="foo").matches(excinfo.value.__cause__)
            # above line is equivalent to
            assert isinstance(excinfo.value.__cause__, SyntaxError)
            assert re.search("foo", str(excinfo.value.__cause__))

        F)_check_typer   r   r)   rx   s     r+   r   zMatcher.matches@  s7    , 	*  +  ++r-   c                ^   g }| j                   %|j                  | j                   j                         | j                  '|j                  dt	        | j                               | j
                  '|j                  dt        | j
                                ddj                  |       dS )Nmatch=check=zMatcher(, ))r   appendrV   rj   rk   r   ro   rb   )r)   
parameterss     r+   __repr__zMatcher.__repr__^  s    
*d11::;::!

367 ::!}TZZ'@&ABC$))J/022r-   c                T    t        | j                  |      | _        | j                  d u S r'   )r{   r   r   r   s     r+   r   zMatcher._check_typek  s(    +D,?,?K  D((r-   )..)r   rR   rj   str | Pattern[str]r   zCallable[[MatchE], bool]rP   rQ   )r)   zMatcher[BaseException]rj   r   r   Callable[[BaseException], bool]rP   rQ   )r   r   rP   rQ   )NNN)r   ztype[MatchE] | Nonerj   r   r   zCallable[[MatchE], bool] | None)rx   r   rP   zTypeGuard[MatchE]rP   rT   )
rV   rW   rX   rY   r   r,   r   r   r   __classcell__r   s   @r+   r   r   	  s    $  %(*-	$ " (	
 
   25$ "
 / 
  N N /3+/15	-+- )- /	-, , 
,<3)r-   r   c                      e Zd Z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e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	 	 	 	 	 	 	 	 	 	 	 	 	 d' fdZe	 	 	 	 d(d       Ze	 	 	 	 d)d       Zd*dZd+dZ	 	 	 	 d,dZe	 	 	 	 	 	 d-d       Z	e	 	 	 	 	 	 d.d       Z		 	 	 	 d/dZ	e
	 	 	 	 	 	 d0d       Ze
d1d       Ze	 	 	 	 	 	 	 	 d2d       Ze	 	 	 	 	 	 	 	 d3d       Z	 	 	 	 	 	 d4dZ	 	 	 	 	 	 	 	 d5dZd+dZ xZS )6RaisesGroupa  Contextmanager for checking for an expected `ExceptionGroup`.
    This works similar to ``pytest.raises``, and a version of it will hopefully be added upstream, after which this can be deprecated and removed. See https://github.com/pytest-dev/pytest/issues/11538


    The catching behaviour differs from :ref:`except* <except_star>` in multiple different ways, being much stricter by default. By using ``allow_unwrapped=True`` and ``flatten_subgroups=True`` you can match ``except*`` fully when expecting a single exception.

    #. All specified exceptions must be present, *and no others*.

       * If you expect a variable number of exceptions you need to use ``pytest.raises(ExceptionGroup)`` and manually check the contained exceptions. Consider making use of :func:`Matcher.matches`.

    #. It will only catch exceptions wrapped in an exceptiongroup by default.

       * With ``allow_unwrapped=True`` you can specify a single expected exception or `Matcher` and it will match the exception even if it is not inside an `ExceptionGroup`. If you expect one of several different exception types you need to use a `Matcher` object.

    #. By default it cares about the full structure with nested `ExceptionGroup`'s. You can specify nested `ExceptionGroup`'s by passing `RaisesGroup` objects as expected exceptions.

       * With ``flatten_subgroups=True`` it will "flatten" the raised `ExceptionGroup`, extracting all exceptions inside any nested :class:`ExceptionGroup`, before matching.

    It does not care about the order of the exceptions, so ``RaisesGroups(ValueError, TypeError)`` is equivalent to ``RaisesGroups(TypeError, ValueError)``.

    Examples::

        with RaisesGroups(ValueError):
            raise ExceptionGroup("", (ValueError(),))
        with RaisesGroups(ValueError, ValueError, Matcher(TypeError, match="expected int")):
            ...
        with RaisesGroups(KeyboardInterrupt, match="hello", check=lambda x: type(x) is BaseExceptionGroup):
            ...
        with RaisesGroups(RaisesGroups(ValueError)):
            raise ExceptionGroup("", (ExceptionGroup("", (ValueError(),)),))

        # flatten_subgroups
        with RaisesGroups(ValueError, flatten_subgroups=True):
            raise ExceptionGroup("", (ExceptionGroup("", (ValueError(),)),))

        # allow_unwrapped
        with RaisesGroups(ValueError, allow_unwrapped=True):
            raise ValueError


    `RaisesGroup.matches` can also be used directly to check a standalone exception group.


    The matching algorithm is greedy, which means cases such as this may fail::

        with RaisesGroups(ValueError, Matcher(ValueError, match="hello")):
            raise ExceptionGroup("", (ValueError("hello"), ValueError("goodbye")))

    even though it generally does not care about the order of the exceptions in the group.
    To avoid the above you should specify the first ValueError with a Matcher as well.

    Tip: if you install ``hypothesis`` and import it in ``conftest.py`` you will get
    readable ``repr``s of ``check`` callables in the output.
    F)flatten_subgroupsc                    y r'   r2   )r)   rx   allow_unwrappedr   s       r+   r,   zRaisesGroup.__init__  r   r-   N)rj   r   c                    y r'   r2   )r)   rx   r   rj   r   other_exceptionss         r+   r,   zRaisesGroup.__init__  s     r-   c                    y r'   r2   r)   rx   rj   r   r   s        r+   r,   zRaisesGroup.__init__  r   r-   c                    y r'   r2   r   s        r+   r,   zRaisesGroup.__init__  r   r-   c                    y r'   r2   r   s        r+   r,   zRaisesGroup.__init__       r-   c                    y r'   r2   r   s        r+   r,   zRaisesGroup.__init__  r   r-   c                    y r'   r2   r   s        r+   r,   zRaisesGroup.__init__  r   r-   c                    y r'   r2   r   s        r+   r,   zRaisesGroup.__init__  s     r-   )r   r   rj   r   c                   t        d|      }t        | 	  ||       |g|| _        || _        || _        d| _        |r|rt        d      |rt        |t              rt        d      |r||t        d      | j                  D ]  }t        |t              r>| j
                  rt        d      | xj                  |j                  z  c_        d|_
        Qt        |t              rB|j                  .| xj                  t        |j                  t               z  c_        d|_
        t        |t              r5t        |t               r%| xj                  t        |t               z  c_        t        d|d	       y )
NzVCallable[[BaseExceptionGroup[ExcT_1|BaseExcT_1|BaseExceptionGroup[BaseExcT_2]]], bool]FzYou cannot specify multiple exceptions with `allow_unwrapped=True.` If you want to match one of multiple possible exceptions you should use a `Matcher`. E.g. `Matcher(check=lambda e: isinstance(e, (...)))`z`allow_unwrapped=True` has no effect when expecting a `RaisesGroup`. You might want it in the expected `RaisesGroup`, or `flatten_subgroups=True` if you don't care about the structure.av  `allow_unwrapped=True` bypasses the `match` and `check` parameters if the exception is unwrapped. If you intended to match/check the exception you should use a `Matcher` object. If you want to match/check the exceptiongroup when the exception *is* wrapped you need to do e.g. `if isinstance(exc.value, ExceptionGroup): assert RaisesGroup(...).matches(exc.value)` afterwards.zYou cannot specify a nested structure inside a RaisesGroup with `flatten_subgroups=True`. The parameter will flatten subgroups in the raised exceptiongroup before matching, which would never match a nested structure.TzInvalid argument "z2" must be exception type, Matcher, or RaisesGroup.)r   r   r,   expected_exceptionsr   r   is_baseexceptiongroupr   ru   r   r   r   r   rv   	Exceptionr7   r   )	r)   rx   r   r   rj   r   r   rE   r   s	           r+   r,   zRaisesGroup.__init__  s   $  	
 	& 

 	   /'8+0"/H  z)[AS 
  1U5FK  ++ 	C#{+))$5  **c.G.GG*"C)%%1..j**!7 3 . #C&:c=+I***S)2L.LL* ( 0$ $ -	r-   c                     y r'   r2   r6   s    r+   	__enter__zRaisesGroup.__enter__]  s     14r-   c                     y r'   r2   r6   s    r+   r   zRaisesGroup.__enter__a  s     9<r-   c                L    t        j                         | _        | j                  S r'   )r]   r4   r*   r6   s    r+   r   zRaisesGroup.__enter__f  s!    ##% 	 ||r-   c                &   | j                   D cg c])  }t        |t              r|j                  n
t	        |      + }}| j
                  r|j                  d| j
                          | j                  r|j                  d| j                          | j                  '|j                  dt        | j                               | j                  '|j                  dt        | j                                ddj                  |       dS c c}w )Nzallow_unwrapped=zflatten_subgroups=r   r   zRaisesGroup(r   r   )r   ru   r7   rV   rm   r   r   r   rj   rk   r   ro   rb   )r)   rr   r   s      r+   r   zRaisesGroup.__repr__l  s     --
 %Q-AJJ47:

 
  01E1E0FGH!! 243I3I2JKL::!~djj'A&DEF::!}TZZ'@&ABCdii
34A66
s   .Dc                    g }|D ]N  }t        |t              r+|j                  | j                  |j                               >|j                  |       P |S )z!Used if `flatten_subgroups=True`.)ru   r    extend_unroll_exceptions
exceptionsr   )r)   r   resrE   s       r+   r   zRaisesGroup._unroll_exceptions|  sR    
 $& 	 C#12

4223>>BC 

3	  
r-   c                     y r'   r2   r   s     r+   r   zRaisesGroup.matches  s     -0r-   c                     y r'   r2   r   s     r+   r   zRaisesGroup.matches  s     58r-   c           
     T   d| _         |d| _         yt        |t              st        |      j                  d}t        | j                        dkD  r|| _         y| j                  | j                  d   |      }|| j                  ry|| d| _         y| j                  r|| _         y|| _         y|j                  }| j                  r| j                  |      }| j                  |      s| j                   }t        |      t        | j                        cxk(  rdk(  rn nt        | j                  d   x}t              rt        |d   x}|      r| j                  |      ru| j                  J d	       | j                   |cxu rJ  J | xj                   d
| j                  |       d|j                   dt        | j                        dz  c_         y|| _         y| j!                  ||      s| j                   J | j                   }| j                  szt#        d | j                  D              s^t#        d |D              rL| j!                  || j                  |j                              r!d| j                   vrdnd}|d| dz   | _         y|| _         y| j%                  |      S )a1  Check if an exception matches the requirements of this RaisesGroup.
        If it fails, `RaisesGroup.fail_reason` will be set.

        Example::

            with pytest.raises(TypeError) as excinfo:
                ...
            assert RaisesGroups(ValueError).matches(excinfo.value.__cause__)
            # the above line is equivalent to
            myexc = excinfo.value.__cause
            assert isinstance(myexc, BaseExceptionGroup)
            assert len(myexc.exceptions) == 1
            assert isinstance(myexc.exceptions[0], ValueError)
        Nzexception is NoneFz is not an exception groupr9   r   Tz-, but would match with `allow_unwrapped=True`z$can't be None if _check_match failedz, but matched the expected z%. You might want RaisesGroup(Matcher(z, match=z))c              3  <   K   | ]  }t        |t                y wr'   )ru   r   .0rr   s     r+   	<genexpr>z&RaisesGroup.matches.<locals>.<genexpr>  s      34Jq+.   c              3  <   K   | ]  }t        |t                y wr'   )ru   r    r   s     r+   r   z&RaisesGroup.matches.<locals>.<genexpr>  s     Ua
1&89Ur   r_     re   z-Did you mean to use `flatten_subgroups=True`?)r   ru   r    r7   rV   lenr   _check_expectedr   r   r   r   r   rj   _repr_expectedrk   _check_exceptionsanyr   )	r)   r   not_group_msgr   actual_exceptions
old_reasonexpectedactualr   s	            r+   r   zRaisesGroup.matches  s   $ !? 3D'#56  $G}5588RSM4++,q0$1! &&t'?'?'BGLC{t33{$o%RS ! 	 %%$'!  %2!5<5G5G!! $ 7 78I J  )**J%&#d.F.F*GL1L4+C+CA+FFxM):1)==vxH%%f-zz-U/UU((JBBBB!!'B4CVCVW_C`Ba  bG  HP  HY  HY  GZ  Zb  cq  rv  r|  r|  c}  b@  @B  &C  C!  %/! %%
 $$00**J ** 8<8P8P  UCTUU**++G,>,>? "&T->->!>B6("OPQ !  %/!   ))r-   c                   t        | t              rt        | |      S | j                  |      }|ry| j                  J | j                  j                  d      rd| dt        | j                  d       S | d| j                   S )zHelper method for `RaisesGroup.matches` and `RaisesGroup._check_exceptions`
        to check one of potentially several expected exceptions.Nr_   z: r   )ru   r7   r{   r   r   
startswithr   )rw   rx   r   s      r+   r   zRaisesGroup._check_expected  s     mT*"=)<<##I.((44$$//5(6-2K2KT+R*STT""]%>%>$?@@r-   c                N    t        | t              rt        |       S t        |       S )zfGet the repr of an expected type/Matcher/RaisesGroup, but we only want
        the name if it's a type)ru   r7   rs   rm   rq   s    r+   r   zRaisesGroup._repr_expected  s"     a'**Awr-   c                     y r'   r2   r)   _exc_valr   s      r+   r   zRaisesGroup._check_exceptions  s    
 -0r-   c                     y r'   r2   r   s      r+   r   zRaisesGroup._check_exceptions  s    
 58r-   c                    t         j                  |      }t        t        t	        |                  }g }i }t         j                        D ]_  \  }}|D ]D  }	 j                  |||	         }
|j                  ||	|
       |
.|j                  |	       |	||<    N |j                  |       a |s|sydt	        |      cxk(  rt	         j                        k(  rn n|rJ 
 _
        yt         j                        D ]N  \  }}t        |      D ];  \  }}|j                  ||      r|j                  || j                  ||             = P |r!t	        |       dt	        |      dkD  rdnd dnd}|s/|j                  |      r| d|D cg c]  }||   	 c} _
        y|s7|j                  |      r&| d	d
j                   fd|D               d _
        ydt	        |      cxk(  rt	        |      k(  rGn nD|j                  |      r3|j                  |      r"| |j                  |d   |d           _
        yd}|r|d| z  }d}d}|s|dz  }n|s|dz  }|r(|dz  }|j!                         D ci c]  \  }}||
 }}}|D ]{  }|d|  j#                   j                  |          z  }t        |      D ]E  \  }}|j                  |      |d| d|d j#                   j                  |             z  }G } |r|dz  }|D ]  }|d| ||   dz  }t         j                        D ]a  \  }}|j                  ||      }
||v r |
J |
d   dk7  r|dz  }|t%        |
|      z  }|
?|d| d j#                  |       d|||      z  }c  t	         j                        t	        |      k(  rt'        |      r|dz  }| _
        yc c}w c c}}w )z]helper method for RaisesGroup.matches that attempts to pair up expected and actual exceptionsTr9   Fz matched exceptionsre   z. zUnexpected exception(s): z0Too few exceptions raised, found no match for: [r   c              3  Z   K   | ]"  }j                  j                  |          $ y wr'   )r   r   )r   ir)   s     r+   r   z0RaisesGroup._check_exceptions.<locals>.<genexpr>\  sW       mx  cdmq  nA  nA  BF  BZ  BZ  [\  B]  n^  mxs   (+]r   r_   r   z    z
Too few exceptions raised!z
Unexpected exception(s)!z8
The following expected exceptions did not find a match:zIt matches z which was paired with z5
The following raised exceptions did not find a match:z
There exist a possible match when attempting an exhaustive check, but RaisesGroup uses a greedy algorithm. Please make your expected exceptions more stringent with `Matcher` etc so the greedy algorithm can function.)ResultHolderr   listranger   	enumerater   
set_resultremover   r   
has_resultno_match_for_actualno_match_for_expectedrb   
get_resultitemsr   r   possible_match)r)   r   r   resultsremaining_actualfailed_expectedr   i_expr   i_remr   i_actualr   successful_strr   r   indent_1indent_2kvrev_matchesi_faileds   `                     r+   r   zRaisesGroup._check_exceptions   s6    t779JK  c*;&< =>%'"$  ))A)AB 		.OE8) .**85Fu5MN""5%5;$++E2%*GEN.  &&u-		.   %&G#d.F.F*GG #D  ))A)AB 	OE8$-.?$@  &%%eX6""8T%9%9(F%K	  7|n.c'lQ6FsB.OrR 	 7#>#>?O#P#1"22Kk{L|fgM^_`MaL|K  !ADG$A$A/$R#1"22bcgclcl  mx  hw  mx  dx  cy  yz  !{D
 %&>#o*>>++,<=--o>#1"273E3EoVWFXZjklZm3n2o pD 2n%&&A//A --ALLA,3MMO<DAq1a4<K<' 	[HXJt2243K3KH3UVWXA %..?$@ [ &%%eX6>2hZ{6*<STXTgTghl  iA  iA  BM  NV  BW  iX  UY  TZ  [  [A[		[ IIA( 	OH2hZ 1( ;>a@@A#,T-E-E#F 	Ox((9O+?*1v~T	X..A;2hZ{43F3Fx3P2QQhiz  |C  DI  |J  jK  iN  O  OA	O	O t''(C0A,BB~H
   m  mA{ M}> =s   O=O c                F   d}|J d| j                                 | j                  J d       | j                  rt        |t              sdnd}| j                  |      sJ d| d| j                          t        d|||f      }| j                  j                  |       y)	NTz&DID NOT RAISE any exception, expected z:Internal error - should have been constructed in __enter__z(group)groupzRaised exception z did not match: zbtuple[type[BaseExceptionGroup[BaseExcT_co]], BaseExceptionGroup[BaseExcT_co], types.TracebackType])	rw   r*   r   rv   r    r   r   r   r0   )r)   exc_typer   exc_tb__tracebackhide__	group_strr/   s          r+   __exit__zRaisesGroup.__exit__  s     ! 	K3D4F4F4H3IJ	K LL$	HG	H ##JxAS,T  	 ||
 	Nyk)9$:K:K9LM	N
 pw'
 	""8,r-   c                   g }| j                   D ]  }t        |t              r|j                  t	        |             .t        |t
              r |j                  |j                                ^t        |t              r|j                  |j                         t        d       | j                  rdnd}| ddj                  |       dS )Nzunknown typeBasere   zExceptionGroup(r   r   )r   ru   r   r   rT   r   rw   r7   rV   AssertionErrorr   rb   )r)   subexcsrr   
group_types       r+   rw   zRaisesGroup.expected_type  s    )) 	5A!W%s1v&A{+q01At$qzz*$^44	5  $99Vr
_TYYw-?,@BBr-   )rx   (type[BaseExcT_co] | Matcher[BaseExcT_co]r   Literal[True]r   rS   rP   rQ   )rx   r  r   r  r   r  rj   r   r   z8Callable[[BaseExceptionGroup[BaseExcT_co]], bool] | NonerP   rQ   )r)   RaisesGroup[ExcT_1]rx   type[ExcT_1] | Matcher[ExcT_1]r   r  rj   r   r   z/Callable[[ExceptionGroup[ExcT_1]], bool] | NonerP   rQ   )r)   z#RaisesGroup[ExceptionGroup[ExcT_2]]rx   RaisesGroup[ExcT_2]r   r  rj   r   r   z?Callable[[ExceptionGroup[ExceptionGroup[ExcT_2]]], bool] | NonerP   rQ   )r)   z,RaisesGroup[ExcT_1 | ExceptionGroup[ExcT_2]]rx   4type[ExcT_1] | Matcher[ExcT_1] | RaisesGroup[ExcT_2]r   r  rj   r   r   zHCallable[[ExceptionGroup[ExcT_1 | ExceptionGroup[ExcT_2]]], bool] | NonerP   rQ   )r)   RaisesGroup[BaseExcT_1]rx   &type[BaseExcT_1] | Matcher[BaseExcT_1]r   r  rj   r   r   z7Callable[[BaseExceptionGroup[BaseExcT_1]], bool] | NonerP   rQ   )r)   z+RaisesGroup[BaseExceptionGroup[BaseExcT_2]]rx   RaisesGroup[BaseExcT_2]r   r  rj   r   r   zKCallable[[BaseExceptionGroup[BaseExceptionGroup[BaseExcT_2]]], bool] | NonerP   rQ   )r)   z8RaisesGroup[BaseExcT_1 | BaseExceptionGroup[BaseExcT_2]]rx   @type[BaseExcT_1] | Matcher[BaseExcT_1] | RaisesGroup[BaseExcT_2]r   r   rj   r   r   zXCallable[[BaseExceptionGroup[BaseExcT_1 | BaseExceptionGroup[BaseExcT_2]]], bool] | NonerP   rQ   )r)   zARaisesGroup[ExcT_1 | BaseExcT_1 | BaseExceptionGroup[BaseExcT_2]]rx   r   r   r   r   rS   r   rS   rj   r   r   zbCallable[[BaseExceptionGroup[BaseExcT_1]], bool] | Callable[[ExceptionGroup[ExcT_1]], bool] | None)r)   r  rP   z%ExceptionInfo[ExceptionGroup[ExcT_1]])r)   r  rP   z-ExceptionInfo[BaseExceptionGroup[BaseExcT_1]])rP   z0ExceptionInfo[BaseExceptionGroup[BaseException]]r   )r   Sequence[BaseException]rP   r!  )r)   r  r   BaseException | NonerP   !TypeGuard[ExceptionGroup[ExcT_1]])r)   r  r   r"  rP   )TypeGuard[BaseExceptionGroup[BaseExcT_1]])r   r"  rP   *TypeGuard[BaseExceptionGroup[BaseExcT_co]])rw   zItype[BaseException] | Matcher[BaseException] | RaisesGroup[BaseException]rx   r   rP   r   )rr   z4type[BaseException] | AbstractMatcher[BaseException]rP   rT   )r)   r  r   r   r   zSequence[Exception]rP   r#  )r)   r  r   r   r   r!  rP   r$  )r   r   r   r!  rP   r%  )r  type[BaseException] | Noner   r"  r  ztypes.TracebackType | NonerP   rS   )rV   rW   rX   rY   r   r,   r   r   r   r   staticmethodr   r   r   r  rw   r   r   s   @r+   r   r   p  s   5r  #(; '	
   
   ,0JN; D )	
 ) H 
  
 ,0AE!1 : )	
 ? 
  
 ,0QU1& / )	
 O 
  
 ,0 :G P )	 U 
  
 ,0IM%9 B )	
 G 
  
 ,0 9* 3 )	 X 
   ,0 FS" ) 
 , !&"'+/
 TOTST"T T  T )TTl 4!4	.4 4 <%<	6< <7 + 
! 0!0%0 
+0 0 8%8%8 
38 8
a*%a* 
4a*F AUA !	A
 
A A$   0!00 /0 
+	0 0
 8%88 38 
3	8 8uu 3u 
4	un, & +	
 
@Cr-   r   c                      e Zd Zy)
NotCheckedN)rV   rW   rX   r2   r-   r+   r)  r)    s    r-   r)  c                  H    e Zd Z	 	 	 	 	 	 ddZd	dZd
dZddZddZddZy)r   c                f    |D cg c]  }|D cg c]  }t         
 c} c}| _        y c c}w c c}w r'   )r)  r   )r)   r   r   _s       r+   r,   zResultHolder.__init__  s4     @QC
:;!45AZ5C
5C
s   	.)
..c                (    || j                   |   |<   y r'   )r   )r)   r   r   results       r+   r   zResultHolder.set_result  s    )/VX&r-   c                N    | j                   |   |   }t        |t              rJ |S r'   )r   ru   r7   )r)   r   r   r   s       r+   r   zResultHolder.get_result  s'    ll6"8,c4((
r-   c                2    | j                   |   |   t        uS r'   r   r)  )r)   r   r   s      r+   r   zResultHolder.has_result  s    ||F#H-Z??r-   c                ^    |D ](  }| j                   D ]  }||   t        usJ ||     y * yNFTr1  )r)   r   r   actual_resultss       r+   r   z"ResultHolder.no_match_for_expected  sG     	!A"&,, !%a(
::!!$, !	!
 r-   c                X    |D ]%  }| j                   |   D ]  }|t        usJ |  y ' yr3  r1  )r)   r   r   r   s       r+   r   z ResultHolder.no_match_for_actual  s@     	!A||A !*,,; !	!
 r-   N)r   z@tuple[type[BaseException] | AbstractMatcher[BaseException], ...]r   r!  rP   rQ   )r   intr   r6  r.  r   rP   rQ   )r   r6  r   r6  rP   r   )r   r6  r   r6  rP   rS   )r   	list[int]rP   rS   )r   r7  rP   rS   )	rV   rW   rX   r,   r   r   r   r   r   r2   r-   r+   r   r     s?    	

	

 3	
 
	
0@r-   r   c                    |
t               }t        |      }|t        | j                        k(  ryt        | j                  |         D ]  \  }}|	||vst	        | ||hz        s y y)NTF)setr   r   r   r   )r   usedcurr_rowr   vals        r+   r   r     sn    |u4yH3w''GOOH56 3;1D=^GTQCZ-P r-   )rE   r   rP   rT   )rj   zPattern[str]rP   r   )rn   zCallable[[BaseExcT_1], bool]rP   rT   )rr   ztype[BaseException]rP   rT   )rw   r&  rx   r   rP   r   r'   )r   r   r:  zset[int] | NonerP   rS   )<
__future__r   r   sysabcr   r   r   textwrapr   typingr   r	   r
   r   r   
trio._utilr   builtinstypescollections.abcr   r   _pytest._code.coder   r   r   typing_extensionsr   r   r   r   r   r   r   r   r   r   version_infoexceptiongroupr    r!   r#   r]   pytestImportErrorrd   r   rg   rh   rk   ro   rs   r{   r}   r   r   r)  r   r   r2   r-   r+   <module>rL     s   " 	 
 #     2SS4 	F X]dCF m=DI\7
\7
		+		+gA J
WV_ J
 J
d "M'( "**S/''F
- *Ac7;/ AH c)of% c) c)L R	C/"4["AB R	C R	Cj     & &R
M  '&'s   E/ /E98E9