
    Eg~V                       U d dl m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 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 d dlmZm Z   ed          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            Z'd(d Z(d)d#Z)d*d&Z*dS )+    )annotationsN)contextmanagersuppress)TYPE_CHECKING	AwaitableCallableGenericTupleTypeVar   )CancelScope_core)AsyncResourceHalfCloseableStreamReceiveStream
SendStreamStream)aclose_forcefully   )assert_checkpoints)	Generator)TracebackType)	ParamSpec	TypeAliasArgsT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     P/var/www/sysmax/venv/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((r.   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+   r1   r3   r5   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#   )r1   r2   r3   r4   r5   r6   r$   r%   )__name__
__module____qualname__r-   r0   r8    r.   r,   r!   r!      sP        ) ) ) )) ) ) )	2 	2 	2 	2 	2 	2r.   r!   exctype[BaseException]r$   Generator[None, None, None]c              #  P   K   d}	 d V  t          d|            # | $ r Y d S w xY w)NTzexpected exception: )AssertionError)r=   __tracebackhide__s     r,   _assert_raisesrC   /   sW      ; 9C99:::    s    %%stream_maker&StreamMaker[SendStream, ReceiveStream]clogged_stream_maker-StreamMaker[SendStream, ReceiveStream] | Noner%   c                j(  K   t           |              d{V           4 d{V \  t          t                    sJ t          t                    sJ d7fdd8d9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                  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d/}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 d0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                  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                  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                  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d1}d<fd2}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   d@d5}t           |             d{V           4 d{V \  t	          j                    4 d{V }|                    |           t          t          j                  5                      d6           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 )Aa  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)rI   ss    r,   do_send_allz)check_one_way_stream.<locals>.do_send_allT   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)rO   rs    r,   do_receive_somez-check_one_way_stream.<locals>.do_receive_someX   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<   )rV   rU   s    r,   checked_receive_1z/check_one_way_stream.<locals>.checked_receive_1\   s:      (++++++++x777777r.   resourcer   c                   K   t                      5  |                                  d {V  d d d            d S # 1 swxY w Y   d S r'   )r   aclose)r[   s    r,   	do_aclosez'check_one_way_stream.<locals>.do_aclose_   s      #%% ( (oo'''''''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   9= =   xc                 P   K     d           d {V    d           d {V  d S )Nr.      yr<   rN   s   r,   send_empty_then_yz/check_one_way_stream.<locals>.send_empty_then_yh   sS       +c"""""""""+d###########r.   ra      1   2r   g      ?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)rg   rM   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)rC   r   BrokenResourceErrorrb   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rm   i   r.   c                 P   K    d           d {V               d {V  d S )Nra   r<   )r^   rN   rM   s   r,   send_then_closez-check_one_way_stream.<locals>.send_then_close   sO      +d#########)A,,r.   c                    K   t          j                     d {V    d           d {V    d           d {V              d {V  d S )Nra   r.   )r   wait_all_tasks_blocked)rZ   r^   rT   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,,r.   Ts   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'   )rC   r   	Cancelled)ru   rw   ry   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
   )rC   r   ClosedResourceErrorrS   rT   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   ri   rj   )r   recordrM   s    r,   waiterz$check_one_way_stream.<locals>.waiter7  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   rs   r   rS   )rT   r   s   r,   receiverz&check_one_way_stream.<locals>.receiver>  si      244444444412220../////////0r.   )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   ri   r   rn   rM   s   r,   senderz$check_one_way_stream.<locals>.senderl  s      +-- @ @==?????????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @0   DDs.   A ;A ?A ?A AAc                 h   K   t          j                     d {V  t                      d {V  d S r'   r   rs   r   r   s   r,   r   z&check_one_way_stream.<locals>.receivers  sN      2444444444'***********r.   rM   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&&&&&&&&&&&r.   s   xyzzy)rI   rJ   r$   r%   r'   )rO   rP   r$   rQ   )rV   rW   r$   r%   )r[   r   r$   r%   r$   r%   )rg   r   r$   r%   )ru   rv   rw   rx   ry   rz   r$   r%   )r   r   r$   r%   )rM   r   r$   r%   )r!   
isinstancer   r   r   open_nursery
start_soon	bytearray
memoryviewrC   
ValueErrorrS   	TypeErrorBusyResourceErrorr   rn   r   r   ri   r   r   r   rj   r]   rs   rL   )rD   rF   nurseryrc   rk   ro   rq   rt   rg   r}   r   r   r   r   r   rZ   r^   rU   rN   rT   r   rM   s                  @@@@@@@r,   check_one_way_streamr   :   s:/     , \\^^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344 	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88 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88 ; ; -// ; ; ; ; ; ; ;7&&q'FGGG&&qz6:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;  #)=)=)?)?#?#?#?#?#?#?@@ 	; 	; 	; 	; 	; 	; 	;FQ   788 ; ; -// ; ; ; ; ; ; ;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	 \?<Q2-QQ2
QQ2"Q#Q2&\?2Q6	6\?9Q6	:"\?2S \? 
S*	*\?-S*	."\?,U<\?
U	\?U	\?8V
\?V	\?V	\?:W\?W	\?W	 A\?/Y\?Y	\?Y	\?1Z\?Z	\?Z	\?3\ [)\ )[--\ 0[-1\ 4\? \	\?\	%\??
]	]	3-`  +_` 
_'	'` *_'	+`  
`
`
42c&a::a>	>ca>	cb<0c<c 	 cc 	c
c#&c#2f<?ef<e!	!f<$e!	%f<ff<f#	#f<&f#	'f<<
g	g0l</i6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0r.p9/o:(p:
pppprp	rp	r;-q:(r:
r	rr	r
r'*r'"u,3Au	7u,	
u	u,u	u,,
u69u6#-yA
x,y,
x6	6y9x6	:y
y$'y$)+|)5|:|)
||)||)))|-	-)0|-	1)'6~//
~99<~9= )	)	))
363@AC@:AB:A7ABBAB:B
AB'B'AB:B*AB'B+AB:B.ACB:AB>	B>ACCAB>	CACC
AC!C$AC!D)AFD4+AE1EAFE1
AE;	E;AFE>AE;	E?AFF
AFF!AFGAI
G"AH#G0AHHAH#HAH	HAH#HAH	HAH#H"AI
H#AH5H2AI
H4AH5H5AI
I

AIIAIJAL7J0ALKAK7K+ALK7AK;K;ALK>AK;K?ALLAL7L
AL	LAL7L!AL	L"AL7L7
AMMAMM+AP N0AO<N8AOOAO<OAO#O#AO<O&AO#O'AO<O*AP O<
AP	PAP P	AP	P
AP P 
AP*P-AP*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 Nrf   r<   )rD   s   r,   flipped_stream_makerz2check_two_way_stream.<locals>.flipped_stream_maker  s0      "lnn$$$$$$ddd++r.   c                 :   K                  d {V d d d         S r   r<   )rF   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7r.   i   i @  r      littlerM   r   rI   rJ   seedintr%   c                   K   t          j        |          }t          |          }|rG|                    d          }|                     |d |                    d {V  ||d          }|Ed S d S rY   )randomRandomr   randintrL   )rM   rI   r   rT   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  # # # # #r.   rQ   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 rY   )r   r   r   lenrS   r   )rM   rI   r   rT   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&& $;;;;;;r.   rf   r   r      c                    K                         d           d {V dk    sJ                                   d {V  d S )Nr   r.   )rS   r]   )s2s   r,   expect_receive_some_emptyz7check_two_way_stream.<locals>.expect_receive_some_empty  s\      ,,,,,,,,3333))++r.   )r$   r   )rM   r   rI   rJ   r   r   r$   r%   )rM   r   rI   rQ   r   r   r$   r%   r   )r   r!   r   r   r   r   getrandbitsto_bytesr   r   r   r]   )rD   rF   r   r   s1DUPLEX_TEST_SIZErT   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                  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                  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`.

    NrM   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 )Nr_   )rL   r   send_eofr   s    r,   send_x_then_eofz4check_half_closeable_stream.<locals>.send_x_then_eof  s      **T"""""""""#%% # #jjll"""""""# # # # # # # # # # # # # # # # # #s   AAArT   c                   K   t          j                     d {V  |                     d           d {V dk    sJ |                     d           d {V dk    sJ d S )Nr   r_   r.   )r   rs   rS   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2r.   ra   r_   )rM   r   r$   r%   )rT   r   r$   r%   )r   r!   r   r   r   r   r   rC   r   rL   r   r   r   rs   ri   )rD   rF   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88 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88 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K/:KAJ5#K5
J??KJ?KK/K	K/K	K//
K9<K9#O5 OAN:(O:
OOOOO5O	O5O	O55
O?O?)r=   r>   r$   r?   )rD   rE   rF   rG   r$   r%   )rD   r   rF   r   r$   r%   )rD   r   rF   r   r$   r%   )+
__future__r   r   
contextlibr   r   typingr   r   r   r	   r
   r    r   r   _abcr   r   r   r   r   _highlevel_genericr   _checkpointsr   collections.abcr   typesr   typing_extensionsr   r   r   r   r   r   __annotations__r!   rC   r   r   r   r<   r.   r,   <module>r      s   " " " " " " "  / / / / / / / / N N N N N N N N N N N N N N N N ! ! ! ! ! ! ! ! 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wv]+++wv]+++!"idDj0A&B"BC C C C C2 2 2 2 2gdDj) 2 2 2* ; ; ; ;Z< Z< Z< Z<z
K* K* K* K*\A4 A4 A4 A4 A4 A4r.   