
     fZ              	      f   d dl mZ d dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZ er*d dlZd dl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j        dk     rd dlm Z  e G d dee                               Z!ere!Z"n	 d dl#m"Z" n# e$$ r e!Z"Y nw xY wddZ% ej&        d          j'        Z(e G d dee                               Z)ere Z*neZ*e G d dee"e e                           e*e                               Z+dS )    )annotationsN)	TYPE_CHECKINGCallableContextManagerGenericLiteralPatternSequencecastoverload)warn_deprecated)final)ExceptionChainReprReprExceptionInfo	Traceback)	TypeGuardTypeVarMatchET)bounddefault	covariant)r   )r   r   E)      )BaseExceptionGroupc                      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d0dZ	 	 	 	 	 	 	 d1d2d&Zd'S )3_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_excinfoexcinfoc                    || _         d S Nr   )selfr    s     ]/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/trio/testing/_raises_group.py__init__z_ExceptionInfo.__init__3   s          exc_info0tuple[type[MatchE], MatchE, types.TracebackType]returnNonec                6    | j         
J d            || _         dS )z<Fill an unfilled ExceptionInfo created with ``for_later()``.Nz ExceptionInfo was already filledr#   )r$   r(   s     r%   fill_unfilledz_ExceptionInfo.fill_unfilled8   s&     }$$&H$$$ r'   _ExceptionInfo[MatchE]c                     | d          S )z!Return an unfilled ExceptionInfo.N )clss    r%   	for_laterz_ExceptionInfo.for_later?   s     s4yyr'   type[MatchE]c                >    | j         
J d            | j         d         S )zThe exception class.Nz6.type can only be used after the context manager exitsr   r#   r$   s    r%   typez_ExceptionInfo.typeE   s*     M%%C &%%}Qr'   r   c                >    | j         
J d            | j         d         S )zThe exception value.Nz7.value can only be used after the context manager exits   r#   r5   s    r%   valuez_ExceptionInfo.valueM   s*     M%%D &%%}Qr'   types.TracebackTypec                >    | j         
J d            | j         d         S )zThe exception raw traceback.Nz4.tb can only be used after the context manager exits   r#   r5   s    r%   tbz_ExceptionInfo.tbU   s*     M%%A &%%}Qr'   Ftryshortboolstrc                     t          d          Nz_This is a helper method only available if you use RaisesGroup with the pytest package installedNotImplementedError)r$   r>   s     r%   exconlyz_ExceptionInfo.exconly]   s    !m
 
 	
r'   excGbuiltins.type[BaseException] | tuple[builtins.type[BaseException], ...]c                     t          d          rB   rC   )r$   rF   s     r%   errisinstancez_ExceptionInfo.errisinstanceb   s     "m
 
 	
r'   longT
showlocalsstyleabspathtbfilter,bool | Callable[[_ExceptionInfo], Traceback]funcargstruncate_localschain&ReprExceptionInfo | ExceptionChainReprc                     t          d          rB   rC   )r$   rK   rL   rM   rN   rP   rQ   rR   s           r%   getreprz_ExceptionInfo.getreprj   s     "m
 
 	
r'   N)r    r   )r(   r)   r*   r+   )r*   r.   )r*   r3   )r*   r   )r*   r:   )F)r>   r?   r*   r@   )rF   rG   r*   r?   )FrJ   FTFTT)rK   r?   rL   r@   rM   r?   rN   rO   rP   r?   rQ   r?   rR   r?   r*   rS   )__name__
__module____qualname____doc____annotations__r&   r-   classmethodr2   propertyr6   r9   r=   rE   rI   rU   r0   r'   r%   r   r   -   s3         i  iEEEE       
! ! ! !    [
       X        X        X 
 
 
 
 


 
 
 
 !AE $
 
 
 
 
 
 
r'   r   )ExceptionInforF   BaseExceptionr*   r@   c           	         d                     t          | dt          |                     gt          | dg                     S )N
message	__notes__)joingetattrr@   )rF   s    r%   _stringify_exceptionre      sF    99CCHH--	
S+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"dZd#dZd$dZd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:`trio.testing.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)):
            ...

    .r$   Matcher[MatchE]exception_typer3   matchstr | Pattern[str]checkCallable[[MatchE], bool]c                    d S r"   r0   r$   rj   rk   rm   s       r%   r&   zMatcher.__init__   s	     sr'   )rm   Matcher[BaseException]Callable[[BaseException], bool]c                   d S r"   r0   )r$   rk   rm   s      r%   r&   zMatcher.__init__   s	     sr'   c                   d S r"   r0   )r$   rm   s     r%   r&   zMatcher.__init__   s    CF3r'   Ntype[MatchE] | Nonestr | Pattern[str] | NoneCallable[[MatchE], bool] | Nonec                   |||t          d          |(t          |t                    st          d| d          || _        |  t	          |t
                    rt          j        |          | _        n|| _        || _	        d S )Nz4You must specify at least one parameter to match on.zexception_type z$ must be a subclass of BaseException)

ValueError
issubclassr^   rj   
isinstancer@   recompilerk   rm   rp   s       r%   r&   zMatcher.__init__   s     !emSTTT%j.W.W%V.VVV   -'eS!! 	E**DJJDJ


r'   	exceptionr^   r*   TypeGuard[MatchE]c                    | j         t          || j                   sdS | j        )t          j        | j        t          |                    sdS | j        du p'|                     t          t          |                    S )a  Check if an exception matches the requirements of this Matcher.

        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__)

        NF)	rj   r{   rk   r|   searchre   rm   r   r   )r$   r~   s     r%   matcheszMatcher.matches   s    $ *:t*4
 4
* 5:!")J,Y77+
 +
! 5 zT!HTZZVY0G0G%H%HHr'   r@   c                <   g }| j         |                    | j         j                   | j        x}/|                    d|j        t
          k    r|j        n|           | j        |                    d| j                   dd                    |           dS )Nzmatch=zcheck=zMatcher(, ))	rj   appendrV   rk   flags_regex_no_flagspatternrm   rc   )r$   reqsrk   s      r%   __str__zMatcher.__str__   s    *KK+4555ZE,KKW%+*H*HeWW   :!KK///000,$))D//,,,,r'   )..)r$   ri   rj   r3   rk   rl   rm   rn   )r$   rq   rk   rl   rm   rr   )rm   rr   )NNN)rj   ru   rk   rv   rm   rw   )r~   r^   r*   r   r*   r@   )rV   rW   rX   rY   r   r&   r   r   r0   r'   r%   rh   rh      s            %(*-	    X  25     X FFF XF /3+/15	    (I I I I<- - - - - -r'   rh   c                      e Zd ZdZerd1dZedd	d	d
d2d            Zedd	d	dd3d            Zeddd	d	dd4d            Zddd	d	d	dd5d Zd6d"Zd7d%Z	d8d)Z
d9d.Zd:d0Zd	S );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 currently does not care about the order of the exceptions, so ``RaisesGroups(ValueError, TypeError)`` is equivalent to ``RaisesGroups(TypeError, ValueError)``.

    This class is not as polished as ``pytest.raises``, and is currently not as helpful in e.g. printing diffs when strings don't match, suggesting you use ``re.escape``, etc.

    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.

    It is also not typechecked perfectly, and that's likely not possible with the current approach. Most common usage should work without issue though.
    argsobjectkwargsr*   RaisesGroup[E]c                    d S r"   r0   )r1   r   r   s      r%   __new__zRaisesGroup.__new__N  s      r'   FN)flatten_subgroupsrk   rm   r~   type[E] | Matcher[E]allow_unwrappedLiteral[True]r   r?   rk   r+   rm   c                   d S r"   r0   )r$   r~   r   r   rk   rm   s         r%   r&   zRaisesGroup.__init__R  	     sr'   )r   rk   rm   other_exceptionsLiteral[False]rv   .Callable[[BaseExceptionGroup[E]], bool] | Nonec                   d S r"   r0   r$   r~   r   r   rk   rm   r   s          r%   r&   zRaisesGroup.__init__^  r   r'   )r   r   rk   rm   type[E] | Matcher[E] | Ec                   d S r"   r0   r   s          r%   r&   zRaisesGroup.__init__i  r   r'   )r   r   rk   rm   strictr   c                  |g|R | _         || _        || _        || _        || _        d| _        |t          ddd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_        Ct          |t                    r2|j        `| xj        t          |j        t                     z  c_        t          |t                    r:t          |t                    r%| xj        t          |t                     z  c_        t          d|d          d S )NFzThe `strict` parameterz0.25.1i  z)flatten_subgroups=True (for strict=False})issueinsteadzYou 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.zInvalid argument "z2" must be exception type, Matcher, or RaisesGroup.)expected_exceptionsr   r   
match_exprrm   is_baseexceptiongroupr   ry   r{   r   rh   rj   rz   	Exceptionr6   r^   )	r$   r~   r   r   rk   rm   r   r   rF   s	            r%   r&   zRaisesGroup.__init__t  s4    J
J
 J
  (9.
%*"(C	    *0ZD" 	/ 	H    	z)[AA 	S  
  	 1U5FK   + 	 	C#{++ ) $5   **c.GG***C))  %-***&	3 3 / *** C&& :c=+I+I ***S)2L2L.LL*** $ $ $ $  -	 	r'   $ExceptionInfo[BaseExceptionGroup[E]]c                @    t          j                    | _        | j        S r"   )r]   r2   r    r5   s    r%   	__enter__zRaisesGroup.__enter__  s    =J=T=V=V|r'   
exceptionsSequence[BaseException]c                    g }|D ]Z}t          |t                    r.|                    |                     |j                             E|                    |           [|S )z!Used if `flatten_subgroups=True`.)r{   r   extend_unroll_exceptionsr   r   )r$   r   resrF   s       r%   r   zRaisesGroup._unroll_exceptions  sh     $& 	  	 C#122  

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

3
r'   exc_valBaseException | None TypeGuard[BaseExceptionGroup[E]]c                   |dS t          |t                    si| j        r`| j        d         }t          |t                    r|                    |          rdS t          |t                    rt          ||          rdS dS | j        )t          j	        | j        t          |                    sdS | j        |                     |          sdS t          | j                  }|j        }| j        r|                     |          }t!          |          t!          | j                  k    rdS |D ]}|D ]}t          |t                    rt          ||          sTt          |t"                    r|                    |          s*t          |t                    r,|                    |          r|                    |            n dS dS )a  Check if an exception matches the requirements of this RaisesGroup.

        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)
        NFr   T)r{   r   r   r   rh   r   r6   r   r|   r   re   rm   listr   r   r   lenr   remove)r$   r   exp_excremaining_exceptionsactual_exceptionserem_es          r%   r   zRaisesGroup.matches  s   " ?5 '#566 	#  215gw//  GOOG4L4L  4gt,,  GW1M1M  45?&ryO1'::0
 0
& 5:!$**W*=*=!5#D$<==5<5G! 	K $ 7 78I J J  !!S)A%B%BBB5
 # 
	 
	A- 	 	t,,1;Au1E1E"5+66;@==;K;K #5'22 8=}}Q7G7G
 )//666Euu  tr'   exc_typetype[BaseException] | Noneexc_tbtypes.TracebackType | Nonec                    d}|J d|                                               | j        
J d            |                     |          sdS t          d|||f          }| j                            |           dS )NTz&DID NOT RAISE any exception, expected z:Internal error - should have been constructed in __enter__FzNtuple[type[BaseExceptionGroup[E]], BaseExceptionGroup[E], types.TracebackType])expected_typer    r   r   r-   )r$   r   r   r   __tracebackhide__r(   s         r%   __exit__zRaisesGroup.__exit__  s     !  JD4F4F4H4HJJ !   L$$G %$$ ||G$$ 	5 \w'
 
 	""8,,,tr'   r@   c                   g }| j         D ]}t          |t                    r#|                    t	          |                     :t          |t
                    r(|                    |                                           wt          |t                    r|                    |j                   t          d          | j
        rdnd}| dd                    |           dS )Nzunknown typeBaserf   zExceptionGroup(r   r   )r   r{   rh   r   r@   r   r   r6   rV   AssertionErrorr   rc   )r$   subexcsr   
group_types       r%   r   zRaisesGroup.expected_type-  s    ) 	5 	5A!W%% 5s1vv&&&&A{++ 5q001111At$$ 5qz****$^444#9AVVr
BBTYYw-?-?BBBBr'   )r   r   r   r   r*   r   )
r~   r   r   r   r   r?   rk   r+   rm   r+   )r~   r   r   r   r   r   r   r   rk   rv   rm   r   )r~   r   r   r   r   r   r   r   rk   rv   rm   r   )r~   r   r   r   r   r?   r   r?   rk   rv   rm   r   r   r+   )r*   r   )r   r   r*   r   )r   r   r*   r   )r   r   r   r   r   r   r*   r?   r   )rV   rW   rX   rY   r   r   r   r&   r   r   r   r   r   r0   r'   r%   r   r     sy       6 6r  QPPPP  #(     X 
 +0+/@D     X 
 +0,1+/@D     X !&"'+/@DN N N N N N`      = = = =~   2C C C C C Cr'   r   )rF   r^   r*   r@   ),
__future__r   r|   systypingr   r   r   r   r   r	   r
   r   r   trio._deprecater   
trio._utilr   builtinstypes_pytest._code.coder   r   r   typing_extensionsr   r   r^   r   r   version_infoexceptiongroupr   r   r]   pytestImportErrorre   r}   r   r   rh   
SuperClassr   r0   r'   r%   <module>r      s   " " " " " " 				 




 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 , + + + + +       DOOO LLLSSSSSSSSSS44444444W}  FF WX]dCCCFGC}555 g111111 H
 H
 H
 H
 H
WV_ H
 H
 H
`  '"MM'((((((( ' ' '&'
    "*R..& b- b- b- b- b-gfo b- b- b-f  #JJ J gC gC gC gC gC./A!/D!EF
ST gC gC gC gC gCs   2B9 9CC