
     fX                       U 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m	Z	m
Z
mZmZmZmZ ddlmZmZ ddl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mZ d dlmZm Z   ed          Z!ej"        dk     rd dl#m$Z$  ede          Z% ede          Z&e
g e	ee%e&f                  f         Z'de(d<    G d dee%e&f                   Z)e	 d+d,d            Z*d-d$Z+d.d'Z,d/d*Z-dS )0    )annotationsN)contextmanagersuppress)TYPE_CHECKING	AwaitableCallable	GeneratorGenericTupleTypeVar   )CancelScope_core)AsyncResourceHalfCloseableStreamReceiveStream
SendStreamStream)aclose_forcefully   )assert_checkpoints)TracebackType)	ParamSpec	TypeAliasArgsT)      )BaseExceptionGroupRes1)boundRes2r   StreamMakerc                  &    e Zd ZddZddZddZdS )_ForceCloseBothbothtuple[Res1, Res2]returnNonec                $    |\  | _         | _        d S N_first_second)selfr%   s     ^/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/trio/testing/_check_streams.py__init__z_ForceCloseBoth.__init__&   s    $(!T\\\    c                "   K   | j         | j        fS r*   r+   )r.   s    r/   
__aenter__z_ForceCloseBoth.__aenter__)   s      {DL((r1   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                   K   	 t          | j                   d {V  t          | j                   d {V  d S # t          | j                   d {V  w xY wr*   )r   r,   r-   )r.   r4   r6   r8   s       r/   	__aexit__z_ForceCloseBoth.__aexit__,   s~      	2#DK000000000#DL11111111111#DL1111111111s	   : AN)r%   r&   r'   r(   )r'   r&   )r4   r5   r6   r7   r8   r9   r'   r(   )__name__
__module____qualname__r0   r3   r;    r1   r/   r$   r$   %   sP        ) ) ) )) ) ) )	2 	2 	2 	2 	2 	2r1   r$   Fexpected_exctype[BaseException]wrappedboolr'   Generator[None, None, None]c              #    K   d}	 d V  t          d|            # t          $ rN}|s
J d            t          |j                  dk    sJ t	          |j        d         |           sJ Y d }~d S d }~w| $ r |r
J d            Y d S w xY w)NTzexpected exception: z:caught exceptiongroup, but expected an unwrapped exceptionr   r   z0caught exception, but expected an exceptiongroup)AssertionErrorr   len
exceptions
isinstance)r@   rB   __tracebackhide__excs       r/   _assert_raisesrL   :   s       
D BLBBCCC  ; ; ;TTTTTT3>""a''''#.+\::::::::::: O O ONNNNNNNNNOs    
BAA//BBstream_maker&StreamMaker[SendStream, ReceiveStream]clogged_stream_maker-StreamMaker[SendStream, ReceiveStream] | Noner(   c                z(  K   t           |              d{V           4 d{V \  t          t                    sJ t          t                    sJ d8fdd9d:fd
d;fdd<dt	          j                    4 d{V }|                    d           |                    d           ddd          d{V  n# 1 d{V swxY w Y   d=fd}t	          j                    4 d{V }|                    |           |                    d           ddd          d{V  n# 1 d{V swxY w Y   t	          j                    4 d{V }|                    t          d                     |                    d           ddd          d{V  n# 1 d{V swxY w Y   t	          j                    4 d{V }|                    t          d                     |                    d           ddd          d{V  n# 1 d{V swxY w Y   t          t                    5                      d           d{V  ddd           n# 1 swxY w Y   t          t                    5                      d           d{V  ddd           n# 1 swxY w Y   t          t                    5                      d           d{V  ddd           n# 1 swxY w Y   t	          j                    4 d{V }|                    d                         d{V dk    sJ 	 ddd          d{V  n# 1 d{V swxY w Y   t	          j                    4 d{V }|                    d            d           d{V dk    sJ 	 ddd          d{V  n# 1 d{V swxY w Y   t          t          j        d          5  t	          j                    4 d{V }|                    d           |                    d           ddd          d{V  n# 1 d{V swxY w Y   ddd           n# 1 swxY w Y   d>fd}t	          j                    4 d{V }|                    ||j                   |                    d           ddd          d{V  n# 1 d{V swxY w Y   d=fd}t	          j                    4 d{V }|                    |           |                               ddd          d{V  n# 1 d{V swxY w Y   t          t          j                  5   d            d{V  ddd           n# 1 swxY w Y   t          t          j                  5   d!           d{V  ddd           n# 1 swxY w Y               d{V              d{V              d{V  t          t          j                  5   d            d{V  ddd           n# 1 swxY w Y   t          t          j                  5   d"           d{V  ddd           n# 1 swxY w Y   t          t          j                  5  t#                      5                                   d{V  ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y               d{V              d{V  ddd          d{V  n# 1 d{V swxY w Y   t           |              d{V           4 d{V \  d=fd#}d=fd$}t	          j                    4 d{V }|                    |           |                    |           ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |              d{V           4 d{V \  t'                     d{V  t          t          j                  5  	  d            d{V  # 1 swxY w Y   t          t          j                  5   d!           d{V  ddd           n# 1 swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |              d{V           4 d{V \  t'                     d{V  t          t          j                  5   d%           d{V  ddd           n# 1 swxY w Y   t)          t          j                  5   d"           d{V  ddd           n# 1 swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |              d{V           4 d{V \  t	          j                    5 }|                                                                  d{V  ddd           n# 1 swxY w Y   t	          j                    5 }|                                                                  d{V  ddd           n# 1 swxY w Y   t          t          j                  5   d%           d{V  ddd           n# 1 swxY w Y   t          t          j                  5   d!           d{V  ddd           n# 1 swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |              d{V           4 d{V \  d?d,}	t	          j                    5 }|                                 t	          j                    4 d{V }|                    |	d           |                    |	d           ddd          d{V  n# 1 d{V swxY w Y   ddd           n# 1 swxY w Y   t	          j                    4 d{V }|                               |                               ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |              d{V           4 d{V \  fd-}
t	          j                    4 d{V }|                    |
           t	          j                     d{V  t'                     d{V  ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   |t           |             d{V           4 d{V \  g d@fd/}d=fd0}t	          j                    4 d{V }|                    ||j                   t	          j                     d{V  |                    |           ddd          d{V  n# 1 d{V swxY w Y   g d1k    sJ 	 ddd          d{V  n# 1 d{V swxY w Y   t           |             d{V           4 d{V \  t          t          j        d          5  t	          j                    4 d{V }|                    j                   |                    j                   ddd          d{V  n# 1 d{V swxY w Y   ddd           n# 1 swxY w Y   t          t          j        d          5  t	          j                    4 d{V }|                    j                   |                    j        d%           ddd          d{V  n# 1 d{V swxY w Y   ddd           n# 1 swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |             d{V           4 d{V \  t          t          j        d          5  t	          j                    4 d{V }|                    j        d%           |                    j        d%           ddd          d{V  n# 1 d{V swxY w Y   ddd           n# 1 swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |             d{V           4 d{V \  d=fd2}d=fd3}t	          j                    4 d{V }|                    |           |                    |           ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |             d{V           4 d{V \  t'                     d{V  	 t#                      5                                   d{V  ddd           n# 1 swxY w Y   n# t          j        $ r Y nw xY wddd          d{V  n# 1 d{V swxY w Y   dAd6}t           |             d{V           4 d{V \  t	          j                    4 d{V }|                    |           t          t          j                  5                      d7           d{V  ddd           n# 1 swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |             d{V           4 d{V \  t	          j                    4 d{V }|                    |           t          t          j                  5                                   d{V  ddd           n# 1 swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  dS # 1 d{V swxY w Y   dS dS )Ba  Perform a number of generic tests on a custom one-way stream
    implementation.

    Args:
      stream_maker: An async (!) function which returns a connected
          (:class:`~trio.abc.SendStream`, :class:`~trio.abc.ReceiveStream`)
          pair.
      clogged_stream_maker: Either None, or an async function similar to
          stream_maker, but with the extra property that the returned stream
          is in a state where ``send_all`` and
          ``wait_send_all_might_not_block`` will block until ``receive_some``
          has been called. This allows for more thorough testing of some edge
          cases, especially around ``wait_send_all_might_not_block``.

    Raises:
      AssertionError: if a test fails.

    Ndatabytes | bytearray | memoryviewr'   r(   c                   K   t                      5                      |            d {V J 	 d d d            d S # 1 swxY w Y   d S r*   )r   send_all)rR   ss    r/   do_send_allz)check_one_way_stream.<locals>.do_send_allf   s      #%% 6 6ZZ--------55556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   >AA	max_bytes
int | Nonebytes | bytearrayc                   K   t                      5                      |            d {V cd d d            S # 1 swxY w Y   d S r*   )r   receive_some)rX   rs    r/   do_receive_somez-check_one_way_stream.<locals>.do_receive_somej   s      #%% 7 7^^I666666667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s   :>>expectedbytesc                :   K    d           d {V | k    sJ d S Nr   r?   )r_   r^   s    r/   checked_receive_1z/check_one_way_stream.<locals>.checked_receive_1n   s:      (++++++++x777777r1   resourcer   c                   K   t                      5  |                                  d {V  d d d            d S # 1 swxY w Y   d S r*   )r   aclose)rd   s    r/   	do_aclosez'check_one_way_stream.<locals>.do_acloseq   s      #%% ( (oo'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   9= =   xc                 P   K     d           d {V    d           d {V  d S )Nr1      yr?   rW   s   r/   send_empty_then_yz/check_one_way_stream.<locals>.send_empty_then_yz   sS       +c"""""""""+d###########r1   rj      1   2r   g      ?TrB   r   scoper   c                   K   t                      5                                   d {V  d d d            n# 1 swxY w Y   |                                  d S r*   )r   wait_send_all_might_not_blockcancel)rq   rV   s    r/   *simple_check_wait_send_all_might_not_blockzHcheck_one_way_stream.<locals>.simple_check_wait_send_all_might_not_block   s       $%% 8 8557777777778 8 8 8 8 8 8 8 8 8 8 8 8 8 8LLNNNNNs   9= =c                 |   K   t          t          j                  5  	   d           d {V  # 1 swxY w Y   d S )NTd   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)rL   r   BrokenResourceErrorrk   s   r/   expect_broken_stream_on_sendz:check_one_way_stream.<locals>.expect_broken_stream_on_send   s       9:: 2 22%+j11111111122 2 2 2 2 2 2 2 2 2s   155rw   i   r1   c                 P   K    d           d {V               d {V  d S )Nrj   r?   )rg   rW   rV   s   r/   send_then_closez-check_one_way_stream.<locals>.send_then_close   sO      +d#########)A,,r1   c                    K   t          j                     d {V    d           d {V    d           d {V              d {V  d S )Nrj   r1   )r   wait_all_tasks_blocked)rc   rg   r]   s   r/   receive_send_then_closez5check_one_way_stream.<locals>.receive_send_then_close   s      
 .000000000##D)))))))))##C((((((((()A,,r1   s   123afn"Callable[ArgsT, Awaitable[object]]args
ArgsT.argskwargsArgsT.kwargsc                   K   t          t          j                  5   | |i | d {V  d d d            d S # 1 swxY w Y   d S r*   )rL   r   	Cancelled)r   r   r   s      r/   expect_cancelledz.check_one_way_stream.<locals>.expect_cancelled%  s      
  00 + +c4*6*********+ + + + + + + + + + + + + + + + + +s   8<<c                    K   t          t          j                  5                       d           d {V  d d d            d S # 1 swxY w Y   d S )N
   )rL   r   ClosedResourceErrorr\   r]   s   r/   receive_expecting_closedz6check_one_way_stream.<locals>.receive_expecting_closed;  s       9:: ) )nnR((((((((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s   AA
A
cancel_scopec                  K                        d           t                      5                                   d {V  d d d            n# 1 swxY w Y                        d           |                                  d S )Nwaiter sleepingwaiter wokeup)appendr   rs   rt   )r   recordrV   s    r/   waiterz$check_one_way_stream.<locals>.waiterI  s      /000')) < <99;;;;;;;;;< < < < < < < < < < < < < < <o...##%%%%%s   AAAc                    K   t          j                     d {V                      d           	                      d           d {V  )Nreceiver startingTiA  )r   r}   r   r\   )r]   r   s   r/   receiverz&check_one_way_stream.<locals>.receiverP  si      244444444412220../////////0r1   )r   r   r   c                    K   	 t                      5                                    d {V  d d d            d S # 1 swxY w Y   d S # t          j        $ r Y d S w xY wr*   )r   rs   r   rx   rV   s   r/   senderz$check_one_way_stream.<locals>.sender~  s      +-- @ @==?????????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @0   DDs.   A ;A ?A ?A AAc                 h   K   t          j                     d {V  t                      d {V  d S r*   r   r}   r   r   s   r/   r   z&check_one_way_stream.<locals>.receiver  sN      2444444444'***********r1   rV   r   c                f   K   t          j                     d {V  t          |            d {V  d S r*   r   r   s    r/   
close_soonz(check_one_way_stream.<locals>.close_soon  sM      .000000000#A&&&&&&&&&&&r1   s   xyzzy)rR   rS   r'   r(   r*   )rX   rY   r'   rZ   )r_   r`   r'   r(   )rd   r   r'   r(   r'   r(   )rq   r   r'   r(   )r   r   r   r   r   r   r'   r(   )r   r   r'   r(   )rV   r   r'   r(   )r$   rI   r   r   r   open_nursery
start_soon	bytearray
memoryviewrL   
ValueErrorr\   	TypeErrorBusyResourceErrorr   rx   r   r   rs   r   r   r   rt   rf   r}   rU   )rM   rO   nurseryrl   ru   ry   r{   r~   rq   r   r   r   r   r   r   rc   rg   r^   rW   r]   r   rV   s                  @@@@@@@r/   check_one_way_streamr   L   sN/     , \\^^33333344 | | | | | | |A!Z(((((!]+++++	6 	6 	6 	6 	6 	6	7 	7 	7 	7 	7 	7 	7	8 	8 	8 	8 	8 	8	( 	( 	( 	(
 %'' 	8 	8 	8 	8 	8 	8 	87{D1110$777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8	$ 	$ 	$ 	$ 	$ 	$ %'' 	8 	8 	8 	8 	8 	8 	8701110$777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 %'' 	8 	8 	8 	8 	8 	8 	87{IdOO<<<0$777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 %'' 	8 	8 	8 	8 	8 	8 	87{Jt,<,<===0$777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8
 J'' 	% 	%..$$$$$$$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%J'' 	$ 	$..#########	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$I&& 	& 	&..%%%%%%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& %'' 	3 	3 	3 	3 	3 	3 	37{D111(********d22222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 %'' 	7 	7 	7 	7 	7 	7 	77{D111(........$66666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 E3TBBB 	7 	7)++ 7 7 7 7 7 7 7w""?A666""?A6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7	 	 	 	 	 	 %'' 	3 	3 	3 	3 	3 	3 	37:G<P   222		3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3	2 	2 	2 	2 	2 	2
 %'' 	- 	- 	- 	- 	- 	- 	-7;<<<y!,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-
 E566 	* 	*+j)))))))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* E566 	( 	(!/$'''''''''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( illill ill E566 	* 	*+j)))))))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* E566 	# 	#+c"""""""""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# E566 	8 	8#%% 8 8557777777778 8 8 8 8 8 8 8 8 8 8 8 8 8 8	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8
 illilly| | | | | | | | | | | | | | | | | | | | | | | | | | || \\^^33333344 8 8 8 8 8 8 8A	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 %'' 	8 	8 	8 	8 	8 	8 	87///6777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8!8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8( \\^^33333344 ( ( ( ( ( ( (A"""""""""E566 	. 	..!k*---------.	. 	. 	. 	. 	. 	. 	. 	. E566 	( 	(!/$'''''''''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( \\^^33333344 
) 
) 
) 
) 
) 
) 
)A"""""""""E566 	& 	&+f%%%%%%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& e/00 	) 	)##C(((((((((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) 
) \\^^33333344 ( ( ( ( ( ( (A   	ELLNNN((**	 	 	 	 	 	 	 	 	 	 	 	 	 	 	    	ELLNNN((**	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 E566 	& 	&+f%%%%%%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& E566 	( 	(!/$'''''''''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (0 \\^^33333344 - - - - - - -A	+ 	+ 	+ 	+    	IELLNNN)++ I I I I I I Iw""#3[$GGG""#3_aHHHI I I I I I I I I I I I I I I I I I I I I I I I I I I	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I %'' 	- 	- 	- 	- 	- 	- 	-7y!,,,y!,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-!- - - - - - - - - - - - - - - - - - - - - - - - - - -, \\^^33333344 	' 	' 	' 	' 	' 	' 	'A	) 	) 	) 	) 	) %'' 	' 	' 	' 	' 	' 	' 	'77888.000000000#A&&&&&&&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' '")=)=)?)?#?#?#?#?#?#?@@ 	 	 	 	 	 	 	FQ "F& & & & & & &0 0 0 0 0 0 0 )++ - - - - - - -w""67+?@@@2444444444""8,,,- - - - - - - - - - - - - - - - - - - - - - - - - - -
         -	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	8 #)=)=)?)?#?#?#?#?#?#?@@ 	; 	; 	; 	; 	; 	; 	;FQ 7FFF H H -// H H H H H H H7&&q'FGGG&&q'FGGGH H H H H H H H H H H H H H H H H H H H H H H H H H HH H H H H H H H H H H H H H H   7FFF ; ; -// ; ; ; ; ; ; ;7&&q'FGGG&&qz6:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;  #)=)=)?)?#?#?#?#?#?#?@@ 	; 	; 	; 	; 	; 	; 	;FQ   7FFF ; ; -// ; ; ; ; ; ; ;7&&qz6:::&&qz6:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; #)=)=)?)?#?#?#?#?#?#?@@ 	- 	- 	- 	- 	- 	- 	-FQ     + + + + + + )++ - - - - - - -w""6***""8,,,- - - - - - - - - - - - - - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-$ #)=)=)?)?#?#?#?#?#?#?@@ 	 	 	 	 	 	 	FQ#A&&&&&&&&&')) < <99;;;;;;;;;< < < < < < < < < < < < < < <,   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 		' 	' 	' 	' #)=)=)?)?#?#?#?#?#?#?@@ 	/ 	/ 	/ 	/ 	/ 	/ 	/FQ)++ / / / / / / /w"":q111#E$=>> / /**X........./ / / / / / / / / / / / / / // / / / / / / / / / / / / / / / / / / / / / / / / / /	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ #)=)=)?)?#?#?#?#?#?#?@@ 	< 	< 	< 	< 	< 	< 	<FQ)++ < < < < < < <w"":q111#E$=>> < <99;;;;;;;;;< < < < < < < < < < < < < < << < < < < < < < < < < < < < < < < < < < < < < < < < <	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<{ ('s  A"]-C<]
C	]C	"]>,D<*]<
E	]	E	
]&:F2 ]2
F<	<]?F<	 ]:H(](
H2	2]5H2	6]I5)]5I9	9]<I9	=]J<0]<K 	 ]K 	]L7]L	]
L	]'-M']'
M1	1]4M1	5].O ]
O	]O	 ]>Q4-QQ4
Q!!Q4$Q!%Q4(]4Q8	8];Q8	<"]2S"]"
S,	,]/S,	0"],U>]
U	]U	]:V]V	]V	 ]<W]W	]!W	"A]1Y]Y	]Y	]3Z]Z	]Z	]5\[+\+[//\2[/3\6]\	]	\	
%]
]]5-`"+_`
_)	)`,_)	-`
``62c(a<<b 	 cb 	c b>2c>c	cc	c
c%(c%2f>ef>e#	#f>&e#	'f>f!f>!f%	%f>(f%	)f>>
gg2l>	/i8l>i	l>i	l>"/jl>j!	!l>$j!	%l>kl>k#	#l>&k#	'l>l!l>!l%	%l>(l%	)l>>
mm2r.p;/o<*p<
pp	p
prp	r p	!r=-q<*r<
r	r	r	
r
r),r)"u.5Au9u.
u	u.u	u..
u8;u8%-yA
x.y.
x8	8y;x8	<y
y&)y&//|-	5|>|-
||-||-!/-|1	1/4|1	5/-6~5#5
~??~?/	/	//
9<9@#ACAACA7AB%BACB%
AB/B/ACB2AB/B3ACB6ACCAC	CACC	AC	C
ACC
AC)C,AC)D)AFD<+AE9E'AFE9
AF	FAFFAF	FAFF
AF&F)AF&GAIG*AH+G8AHHAH+HAH#	H#AH+H&AH#	H'AH+H*AIH+AH=H:AIH<AH=H=AII
AIIAIJ
AL?J'0ALKAK?K3ALK?ALLALLALLALL
AL?L
AL&	L&AL?L)AL&	L*AL?L?
AM	MAM	M3AP(N0APO AO'OAPO'AO+O+APO.AO+O/APO2AP(P
AP	PAP(PAP	PAP(P(
AP2P5AP2StreamMaker[Stream, Stream]"StreamMaker[Stream, Stream] | Nonec           
     d   K   t                      d{V  d fd}dfd}nd}t          ||           d{V  t                         d{V           4 d{V \  }t          |t                    sJ t          t                    sJ d}dt	          j        d          }|                    d	|z            }|                    |d
          }dfd}	dfd}
t          j	                    4 d{V }|
                    |	||d           |
                    |	|ddd         d           |
                    |
||ddd         d           |
                    |
|d           ddd          d{V  n# 1 d{V swxY w Y   dfd}t          j	                    4 d{V }|
                    |           |
                    |j                   ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  dS # 1 d{V swxY w Y   dS )u  Perform a number of generic tests on a custom two-way stream
    implementation.

    This is similar to :func:`check_one_way_stream`, except that the maker
    functions are expected to return objects implementing the
    :class:`~trio.abc.Stream` interface.

    This function tests a *superset* of what :func:`check_one_way_stream`
    checks – if you call this, then you don't need to also call
    :func:`check_one_way_stream`.

    Nr'   tuple[Stream, Stream]c                 :   K                  d {V d d d         S Nro   r?   )rM   s   r/   flipped_stream_makerz2check_two_way_stream.<locals>.flipped_stream_maker  s0      "lnn$$$$$$ddd++r1   c                 :   K                  d {V d d d         S r   r?   )rO   s   r/   flipped_clogged_stream_makerz:check_two_way_stream.<locals>.flipped_clogged_stream_maker  s3      ..00000000$$B$77r1   i   i @  r      littlerV   r   rR   rS   seedintr(   c                   K   t          j        |          }t          |          }|rG|                    d          }|                     |d |                    d {V  ||d          }|Ed S d S rb   )randomRandomr   randintrU   )rV   rR   r   r]   m
chunk_sizeCHUNK_SIZE_MAXs         r/   r   z$check_two_way_stream.<locals>.sender  s       d##A4  A #YYq.99
jj;J;000000000jkkN  # # # # #r1   rZ   c                P  K   t          j        |          }t                      }t          |          t          |          k     rX|                     |                    d                     d {V }|sJ ||z  }t          |          t          |          k     X||k    sJ d S rb   )r   r   r   rG   r\   r   )rV   rR   r   r]   gotchunkr   s         r/   r   z&check_two_way_stream.<locals>.receiver  s      d##A++Cc((SYY&&nnQYYq.-I-IJJJJJJJJu c((SYY&& $;;;;;;r1   ro   r   r   r   c                    K                         d           d {V dk    sJ                                   d {V  d S )Nr   r1   )r\   rf   )s2s   r/   expect_receive_some_emptyz7check_two_way_stream.<locals>.expect_receive_some_empty  s\      ,,,,,,,,3333))++r1   )r'   r   )rV   r   rR   rS   r   r   r'   r(   )rV   r   rR   rZ   r   r   r'   r(   r   )r   r$   rI   r   r   r   getrandbitsto_bytesr   r   r   rf   )rM   rO   r   r   s1DUPLEX_TEST_SIZEr]   i	test_datar   r   r   r   r   r   s   ``           @@r/   check_two_way_streamr     sx       |-A
B
BBBBBBBB, , , , , ,
 '	8 	8 	8 	8 	8 	8 	8 (,$
35Q
R
RRRRRRRR\\^^33333344 +* +* +* +* +* +* +*R"f%%%%%"f%%%%% !M!MM!..//JJ/::		# 	# 	# 	# 	# 	#	 	 	 	 	 	 %'' 	; 	; 	; 	; 	; 	; 	;7vr9a888vr9TTrT?A>>>xYttt_a@@@xY:::		; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;	 	 	 	 	 	 %'' 	* 	* 	* 	* 	* 	* 	*78999ry)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*S+* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +*s\   'BHA3F	7H	
F	HF	"H90G;)H;
H	HH		H
H),H)5StreamMaker[HalfCloseableStream, HalfCloseableStream]<StreamMaker[HalfCloseableStream, HalfCloseableStream] | Nonec                  K   t          | |           d{V  t           |              d{V           4 d{V \  }}t          |t                    sJ t          |t                    sJ dd}dd}t	          j                    4 d{V }|                    ||           |                    ||           ddd          d{V  n# 1 d{V swxY w Y   t          t          j                  5  |	                    d	           d{V  ddd           n# 1 swxY w Y   t                      5  |                                 d{V  ddd           n# 1 swxY w Y   t	          j                    4 d{V }|                    ||           |                    ||           ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   |t           |             d{V           4 d{V \  }}t          t          j        d
          5  t	          j                    4 d{V }|                    |j	        d           t	          j                     d{V  |                    |j                   ddd          d{V  n# 1 d{V swxY w Y   ddd           n# 1 swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   t           |             d{V           4 d{V \  }}t          t          j        d
          5  t	          j                    4 d{V }|                    |j                   t	          j                     d{V  |                    |j                   ddd          d{V  n# 1 d{V swxY w Y   ddd           n# 1 swxY w Y   ddd          d{V  dS # 1 d{V swxY w Y   dS dS )u  Perform a number of generic tests on a custom half-closeable stream
    implementation.

    This is similar to :func:`check_two_way_stream`, except that the maker
    functions are expected to return objects that implement the
    :class:`~trio.abc.HalfCloseableStream` interface.

    This function tests a *superset* of what :func:`check_two_way_stream`
    checks – if you call this, then you don't need to also call
    :func:`check_two_way_stream`.

    NrV   r   r'   r(   c                   K   |                      d           d {V  t                      5  |                                  d {V  d d d            d S # 1 swxY w Y   d S )Nrh   )rU   r   send_eofr   s    r/   send_x_then_eofz4check_half_closeable_stream.<locals>.send_x_then_eof  s      **T"""""""""#%% # #jjll"""""""# # # # # # # # # # # # # # # # # #s   AAAr]   c                   K   t          j                     d {V  |                     d           d {V dk    sJ |                     d           d {V dk    sJ d S )Nr   rh   r1   )r   r}   r\   r   s    r/   expect_x_then_eofz6check_half_closeable_stream.<locals>.expect_x_then_eof  s      .000000000++++++++t3333++++++++s222222r1   rj   Trp   rh   )rV   r   r'   r(   )r]   r   r'   r(   )r   r$   rI   r   r   r   r   rL   r   rU   r   r   r   r}   rs   )rM   rO   r   r   r   r   r   s          r/   check_half_closeable_streamr     s       |-A
B
BBBBBBBB\\^^33333344 6 6 6 6 6 6 6R"122222"122222	# 	# 	# 	#
	3 	3 	3 	3
 %'' 	6 	6 	6 	6 	6 	6 	673330"555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6
 E566 	$ 	$++d#########	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$  !! 	  	 ++--	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  %'' 	6 	6 	6 	6 	6 	6 	673330"555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	676 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6> '")=)=)?)?#?#?#?#?#?#?@@ 	4 	4 	4 	4 	4 	4 	4HR 7FFF 4 4 -// 4 4 4 4 4 4 47&&r{D9996888888888&&r{3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 #)=)=)?)?#?#?#?#?#?#?@@ 	4 	4 	4 	4 	4 	4 	4HR   7FFF 4 4 -// 4 4 4 4 4 4 47&&r'GHHH6888888888&&r{3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 ('sX  AG&-C<G&
C	G&C	G&8D G& D$	$G&'D$	(G&9E G& E$	$G&'E$	(G&-G1G&
G	G&G	G&&
G03G0K1<KAJ7%K7
KKKKK1K	K1K	K11
K;>K;%O9OAN>,O>
OOOOO9O	O9"O	#O99
PP)F)r@   rA   rB   rC   r'   rD   )rM   rN   rO   rP   r'   r(   )rM   r   rO   r   r'   r(   )rM   r   rO   r   r'   r(   ).
__future__r   r   sys
contextlibr   r   typingr   r   r   r	   r
   r   r    r   r   _abcr   r   r   r   r   _highlevel_genericr   _checkpointsr   typesr   typing_extensionsr   r   r   version_infoexceptiongroupr   r   r!   r"   __annotations__r$   rL   r   r   r   r?   r1   r/   <module>r      sn   " " " " " " "  



 / / / / / / / /                  " ! ! ! ! ! ! ! X X X X X X X X X X X X X X 2 2 2 2 2 2 , , , , , , ######66666666IgEg111111wv]+++wv]+++!"idDj0A&B"BC C C C C2 2 2 2 2gdDj) 2 2 2* 7<D D D D D"Z< Z< Z< Z<z
K* K* K* K*\A4 A4 A4 A4 A4 A4r1   