a
    (ñ»jˆT  ã                   @  s$  d dl mZ d dlZd dlmZmZ d dlZd dlZd dlmZm	Z	m
Z
 ddlmZmZmZmZ ejdk rvd dlmZ er†d d	lmZ d
dœdd„Zdd
dœdd„Zd
dœdd„Zd
dœdd„Zd
dœdd„Zd
dœdd„Zd
dœdd„Zd
dœdd„Zd
dœdd„Zd
dœd d!„Zd
dœd"d#„Zd
dœd$d%„Z d
dœd&d'„Z!d
dœd(d)„Z"d
dœd*d+„Z#d
dœd,d-„Z$d
dœd.d/„Z%d0d
dœd1d2„Z&d
dœd3d4„Z'd
dœd5d6„Z(d
dœd7d8„Z)d
dœd9d:„Z*d
dœd;d<„Z+d
dœd=d>„Z,d
dœd?d@„Z-d
dœdAdB„Z.d
dœdCdD„Z/d
dœdEdF„Z0d
dœdGdH„Z1dS )Ié    )ÚannotationsN)ÚTYPE_CHECKINGÚUnion)ÚEndOfChannelÚas_safe_channelÚopen_memory_channelé   )ÚMatcherÚRaisesGroupÚassert_checkpointsÚwait_all_tasks_blocked)é   é   )ÚExceptionGroup)ÚAsyncGeneratorÚNone©Úreturnc                  Ã  s@  t  t¡� tdƒ W d   ƒ n1 s(0    Y  t jtdd�� tdƒ W d   ƒ n1 s^0    Y  ttttd f  dƒ\} }t| ƒ t|ƒ |  	d¡ t
ƒ �  |  d¡I d H  W d   ƒ n1 sÈ0    Y  t  tj¡� |  	d ¡ W d   ƒ n1 sþ0    Y  t
ƒ �( | ¡ I d H dk�s(J ‚W d   ƒ n1 �s>0    Y  | ¡ dk�sZJ ‚t  tj¡� | ¡  W d   ƒ n1 �s†0    Y  |  	d¡ |  ¡ I d H  t  tj¡�  |  d¡I d H  W d   ƒ n1 �sÜ0    Y  t  tj¡� |  	d¡ W d   ƒ n1 �s0    Y  t  tj¡� |  ¡  W d   ƒ n1 �sJ0    Y  |  ¡ I d H  | ¡ dk�stJ ‚t  t¡� | ¡ I d H  W d   ƒ n1 �s¤0    Y  | ¡ I d H  t  tj¡� | ¡ I d H  W d   ƒ n1 �sî0    Y  t  tj¡� | ¡  W d   ƒ n1 �s$0    Y  | ¡ I d H  d S )	Ng      ð?z^max_buffer_size must be >= 0$©Úmatchéÿÿÿÿr   é   Úlastztoo late)ÚpytestÚraisesÚ	TypeErrorr   Ú
ValueErrorr   ÚintÚstrÚreprÚsend_nowaitr   ÚsendÚtrioÚ
WouldBlockÚreceiveÚreceive_nowaitÚacloseÚClosedResourceErrorÚcloner   )ÚsÚr© r+   ú>E:\soccer\ml_env\Lib\site-packages\trio/_tests/test_channel.pyÚtest_channel   sF    &&
.(8(
0*(..(r-   ztrio.abc.Clock)Úautojump_clockr   c                 Ã  sf   t t dƒ\}}t d¡�}| ¡ I d H  W d   ƒ n1 s>0    Y  |jsRJ ‚| d¡I d H  d S )Nr   é
   zTest for PR #553)r   r   r"   Úmove_on_afterr$   Zcancelled_caughtr!   )r.   r)   r*   Ztimeout_scoper+   r+   r,   Útest_553?   s
    ,
r1   c               
   Ã  sê   ddddœdd„} t t dƒ\}}t ¡ 4 I d H šž}|4 I d H š6 tdƒD ]}| | | ¡ |¡ qJW d   ƒI d H  qŒ1 I d H s‚0    Y  d	d
„ |2 ƒI d H }| ¡  |ttdƒƒks¼J ‚W d   ƒI d H  qæ1 I d H sÜ0    Y  d S )Nútrio.MemorySendChannel[int]r   r   )Úsend_channelÚir   c              	   Ó  sh   | 4 I d H šB t d| d|d  ƒD ]}|  |¡I d H  q$W d   ƒI d H  qd1 I d H sZ0    Y  d S )Nr   r   )Úranger!   )r3   r4   Újr+   r+   r,   ÚproducerH   s    z1test_channel_multiple_producers.<locals>.producerr   r/   c                 Ó  s   g | z3 d H W }|‘q6 S ©Nr+   )Ú.0Úvaluer+   r+   r,   Ú
<listcomp>V   ó    z3test_channel_multiple_producers.<locals>.<listcomp>é   )	r   r   r"   Úopen_nurseryr5   Ú
start_soonr(   ÚsortÚlist)r7   r3   Úreceive_channelÚnurseryr4   Úgotr+   r+   r,   Útest_channel_multiple_producersG   s    >rE   c               
   ƒ  s4  t ƒ ‰g ‰ ddddœ‡ ‡fdd„} t ¡ 4 I d H š¦}tjt dƒ\}}|4 I d H š\ tdƒD ]}| | ||¡ q\tƒ I d H  td	ƒD ]}| |¡I d H  q„W d   ƒI d H  qÄ1 I d H sº0    Y  W d   ƒI d H  qî1 I d H sä0    Y  ˆt tdƒƒk�sJ ‚t	ˆ ƒd	k�sJ ‚t ˆ ƒt td	ƒƒk�s0J ‚d S )
Nútrio.MemoryReceiveChannel[int]r   r   )rB   r4   r   c                 “  s,   | 2 z 3 d H W }ˆ  |¡ ˆ  |¡ q6 d S r8   )ÚaddÚappend)rB   r4   r:   ©ZreceivedZsuccessful_receiversr+   r,   Úconsumer`   s    
z1test_channel_multiple_consumers.<locals>.consumerr   é   r/   )
Úsetr"   r>   r   r   r5   r?   r   r!   Úlen)rJ   rC   r3   rB   r4   r+   rI   r,   Útest_channel_multiple_consumers\   s    frN   c               	   Ã  sT  ddddœdd„} t d  dƒ\}}t ¡ 4 I d H š@}| | |tj¡ tƒ I d H  | ¡ I d H  W d   ƒI d H  qˆ1 I d H s~0    Y  t tj¡� | 	d ¡ W d   ƒ n1 s´0    Y  t tj¡�  | 
d ¡I d H  W d   ƒ n1 sð0    Y  t t¡� | ¡  W d   ƒ n1 �s$0    Y  t t¡� | ¡ I d H  W d   ƒ n1 �s^0    Y  t d  dƒ\}}t ¡ 4 I d H šB}| | |tj¡ tƒ I d H  | ¡ I d H  W d   ƒI d H  �qâ1 I d H �sØ0    Y  t tj¡� | 	d ¡ W d   ƒ n1 �s0    Y  t tj¡�  | 
d ¡I d H  W d   ƒ n1 �sN0    Y  ddd	œd
d„}t t dƒ\}}t ¡ 4 I d H š>}| ||¡ tƒ I d H  | ¡ I d H  W d   ƒI d H  �qÞ1 I d H �sÔ0    Y  t tj¡� | ¡  W d   ƒ n1 �s
0    Y  t tj¡� | ¡ I d H  W d   ƒ n1 �sF0    Y  d S )Nútrio.MemorySendChannel[None]útype[BaseException]r   ©r)   Úexpectr   c                 Ó  s>   t  |¡�  |  d ¡I d H  W d   ƒ n1 s00    Y  d S r8   ©r   r   r!   ©r)   rR   r+   r+   r,   Ú
send_blockt   s    z%test_close_basics.<locals>.send_blockr   rF   ©r*   r   c                 Ó  s>   t  tj¡� |  ¡ I d H  W d   ƒ n1 s00    Y  d S r8   ©r   r   r"   r'   r$   ©r*   r+   r+   r,   Úreceive_blockœ   s    z(test_close_basics.<locals>.receive_block)r   r"   r>   r?   r'   r   r&   r   r   r    r!   r   r%   r$   ÚBrokenResourceErrorr   )rU   r)   r*   rC   rY   Z_s2Úr2r+   r+   r,   Útest_close_basicss   sB    8(.(.<*0<(r\   c               	   Ã  sB  ddddœdd„} t d  dƒ\}}t ¡ 4 I d H š:}| | |tj¡ tƒ I d H  | ¡  W d   ƒI d H  q‚1 I d H sx0    Y  t tj¡� | 	d ¡ W d   ƒ n1 s®0    Y  t tj¡�  | 
d ¡I d H  W d   ƒ n1 sê0    Y  t t¡� | ¡  W d   ƒ n1 �s0    Y  t t¡� | ¡ I d H  W d   ƒ n1 �sX0    Y  t d  dƒ\}}t ¡ 4 I d H š<}| | |tj¡ tƒ I d H  | ¡  W d   ƒI d H  �qÖ1 I d H �sÌ0    Y  t tj¡� | 	d ¡ W d   ƒ n1 �s0    Y  t tj¡�  | 
d ¡I d H  W d   ƒ n1 �sB0    Y  ddd	œd
d„}t d  dƒ\}}t ¡ 4 I d H š8}| ||¡ tƒ I d H  | ¡  W d   ƒI d H  �qÌ1 I d H �sÂ0    Y  t tj¡� | ¡  W d   ƒ n1 �sø0    Y  t tj¡� | ¡ I d H  W d   ƒ n1 �s40    Y  d S )NrO   rP   r   rQ   c                 Ó  s>   t  |¡�  |  d ¡I d H  W d   ƒ n1 s00    Y  d S r8   rS   rT   r+   r+   r,   rU   ®   s    z#test_close_sync.<locals>.send_blockr   ztrio.MemoryReceiveChannel[None]rV   c                 Ó  s>   t  tj¡� |  ¡ I d H  W d   ƒ n1 s00    Y  d S r8   rW   rX   r+   r+   r,   rY   Ö   s    z&test_close_sync.<locals>.receive_block)r   r"   r>   r?   r'   r   Úcloser   r   r    r!   r   r%   r$   rZ   )rU   r)   r*   rC   rY   r+   r+   r,   Útest_close_sync­   sB    2(.(.6*06(r^   c                  Ã  s  t d  dƒ\} }| ¡ }| ¡ }|  d ¡ | ¡ I d H  |� W d   ƒ n1 sR0    Y  t tj¡� | ¡  W d   ƒ n1 s†0    Y  t tj¡� | ¡  W d   ƒ n1 sº0    Y  |  d ¡ | ¡ I d H  t tj¡� |  d ¡ W d   ƒ n1 �s
0    Y  d S )Nr/   )	r   r(   r    r&   r   r   r"   r'   rZ   )r)   r*   r[   Zr3r+   r+   r,   Ú$test_receive_channel_clone_and_closeç   s    
&&
r_   c               	   ƒ  sÀ   t t dƒ\‰ } ˆ  ¡ ‰ddœ‡ fdd„}ddœ‡fdd„}t ¡ 4 I d H šZ}| |¡ | |¡ tƒ I d H  ˆ  ¡ I d H  |  ¡ I d H dks’J ‚W d   ƒI d H  q¼1 I d H s²0    Y  d S )	Nr   r   r   c                   “  s@   t  tj¡�  ˆ  d¡I d H  W d   ƒ n1 s20    Y  d S )NZnope)r   r   r"   r'   r!   r+   )Ús1r+   r,   Úsend_will_close  s    z9test_close_multiple_send_handles.<locals>.send_will_closec                   “  s   ˆ   d¡I d H  d S ©NÚok)r!   r+   )Ús2r+   r,   Úsend_will_succeed  s    z;test_close_multiple_send_handles.<locals>.send_will_succeedrc   )	r   r   r(   r"   r>   r?   r   r&   r$   )r*   ra   re   rC   r+   )r`   rd   r,   Ú test_close_multiple_send_handles  s    

rf   c               	   ƒ  sº   t t dƒ\} ‰ ˆ  ¡ ‰ddœ‡ fdd„}ddœ‡fdd„}t ¡ 4 I d H šT}| |¡ | |¡ tƒ I d H  ˆ  ¡ I d H  |  d¡I d H  W d   ƒI d H  q¶1 I d H s¬0    Y  d S )	Nr   r   r   c                   “  s>   t  tj¡� ˆ  ¡ I d H  W d   ƒ n1 s00    Y  d S r8   rW   r+   )Úr1r+   r,   Úreceive_will_close  s    z?test_close_multiple_receive_handles.<locals>.receive_will_closec                   “  s   ˆ   ¡ I d H dksJ ‚d S rb   ©r$   r+   )r[   r+   r,   Úreceive_will_succeed!  s    zAtest_close_multiple_receive_handles.<locals>.receive_will_succeedrc   )	r   r   r(   r"   r>   r?   r   r&   r!   )r)   rh   rj   rC   r+   )rg   r[   r,   Ú#test_close_multiple_receive_handles  s    

rk   c                  Ã  s|   t t tdƒƒ\} }| �( tdƒD ]}|  |¡ q"W d   ƒ n1 sF0    Y  dd„ |2 ƒI d H }|ttdƒƒksxJ ‚d S )NÚinfr/   c                 Ó  s   g | z3 d H W }|‘q6 S r8   r+   )r9   r4   r+   r+   r,   r;   4  r<   z%test_inf_capacity.<locals>.<listcomp>)r   r   Úfloatr5   r    rA   )r!   r$   r4   rD   r+   r+   r,   Útest_inf_capacity,  s    *rn   c               	   Ã  s€  t d  dƒ\} }|  ¡ | ¡ ks$J ‚|  ¡ }|jdks:J ‚|jdksHJ ‚|jdksVJ ‚|jdksdJ ‚|jdksrJ ‚|jdks€J ‚|  d ¡ |  ¡ jdksœJ ‚|  	¡ }|  ¡ jdks¶J ‚|  
¡ I d H  | ¡ jdksÖJ ‚| 	¡ }| ¡ jdksðJ ‚| 
¡ I d H  | ¡ jdk�sJ ‚t ¡ 4 I d H š|}| d ¡ |  ¡ jdk�sBJ ‚| |jd ¡ | |jd ¡ tƒ I d H  |  ¡ jdk�s~J ‚|j ¡  W d   ƒI d H  �q¶1 I d H �s¬0    Y  |  ¡ jdk�sÊJ ‚z| ¡  �qÌW n tj�yð   Y n0 t ¡ 4 I d H šN}| |j¡ tƒ I d H  |  ¡ jdk�s0J ‚|j ¡  W d   ƒI d H  �qh1 I d H �s^0    Y  |  ¡ jdk�s|J ‚d S )Nr   r   r   )r   Ú
statisticsZcurrent_buffer_usedÚmax_buffer_sizeZopen_send_channelsZopen_receive_channelsZtasks_waiting_sendZtasks_waiting_receiver    r(   r&   r"   r>   r?   r!   r   Zcancel_scopeÚcancelr%   r#   r$   )r)   r*   Ústatsrd   r[   rC   r+   r+   r,   Útest_statistics8  sL    

88rs   c               	   ƒ  s  t ttd f  dƒ\} }|  d¡ | ¡ dks2J ‚|  d¡ | ¡ dksLJ ‚d ‰ dddœ‡ fdd„}t ¡ 4 I d H šl}| ||¡ tƒ I d H  |  d¡ t	 
tj¡� | ¡  W d   ƒ n1 sÂ0    Y  W d   ƒI d H  qö1 I d H sì0    Y  ˆ dk�sJ ‚t ttd f  dƒ\} }|  d¡ t	 
tj¡� |  d ¡ W d   ƒ n1 �sT0    Y  t ¡ 4 I d H š”}| | jd¡ tƒ I d H  | ¡ dk�sœJ ‚t	 
tj¡� |  d¡ W d   ƒ n1 �sÊ0    Y  | ¡ I d H dk�sìJ ‚W d   ƒI d H  �q1 I d H �s0    Y  d S )	Nr   r   z%trio.MemoryReceiveChannel[int | None]r   rV   c                 “  s   |   ¡ I d H ‰ d S r8   ri   rX   ©Úresultr+   r,   Ú
do_receivex  s    z)test_channel_fairness.<locals>.do_receiver   )r   r   r   r    r%   r"   r>   r?   r   r   r   r#   r!   r$   )r)   r*   rv   rC   r+   rt   r,   Útest_channel_fairnessj  s2    


P
**rw   c               	   Ã  sP  t t dƒ\} }t tj¡� | ¡  W d   ƒ n1 s:0    Y  t tj¡� |  d¡ W d   ƒ n1 sp0    Y  ddddœdd„}t ¡ 4 I d H šb}| 	|| d¡ t
ƒ �& | ¡ I d H dksÊJ ‚W d   ƒ n1 sÞ0    Y  W d   ƒI d H  �q1 I d H �s0    Y  t tj¡� | ¡  W d   ƒ n1 �sB0    Y  d S )	Nr   r   r2   r   r   )r)   Úvr   c                 Ó  s:   t ƒ �  |  |¡I d H  W d   ƒ n1 s,0    Y  d S r8   )r   r!   )r)   rx   r+   r+   r,   Údo_send›  s    z test_unbuffered.<locals>.do_send)r   r   r   r   r"   r#   r%   r    r>   r?   r   r$   )r)   r*   ry   rC   r+   r+   r,   Útest_unbuffered”  s    &(brz   c               	   Ã  sp   t ddœdd„ƒ} | ƒ 4 I d H š6}|2 z3 d H W }|dks&J ‚q&6 W d   ƒI d H  ql1 I d H sb0    Y  d S )NúAsyncGenerator[int]r   c                   S s
   dV  d S ©Nr   r+   r+   r+   r+   r,   Úagen¨  s    z*test_as_safe_channel_exhaust.<locals>.agenr   ©r   ©r}   Ú	recv_chanÚxr+   r+   r,   Útest_as_safe_channel_exhaust§  s
    r‚   c               	   Ã  s®   t ddœdd„ƒ} | ƒ 4 I d H št}| ¡ I d H dks8J ‚| ¡ I d H  t tj¡� | ¡ I d H  W d   ƒ n1 sv0    Y  W d   ƒI d H  qª1 I d H s 0    Y  d S )Nr{   r   c                   S s   dV  dV  d S )Nr   r   r+   r+   r+   r+   r,   r}   ²  s    z2test_as_safe_channel_broken_resource.<locals>.agenr   )r   Ú	__anext__r&   r   r   r"   r'   ©r}   r€   r+   r+   r,   Ú$test_as_safe_channel_broken_resource±  s    r…   c               
   Ã  s€   t  ¡ �d} tddœdd„ƒ}|ƒ 4 I d H š |  ¡  W d   ƒI d H  q^1 I d H sT0    Y  W d   ƒ n1 sr0    Y  d S )NúAsyncGenerator[None]r   c                   S s   t dƒ‚d V  d S )Nz@cancel before consumption means generator should not be iterated©ÚAssertionErrorr+   r+   r+   r,   r}   Ç  s    ÿz,test_as_safe_channel_cancelled.<locals>.agen)r"   ÚCancelScoper   rq   )Úcsr}   r+   r+   r,   Útest_as_safe_channel_cancelledÄ  s
    
r‹   c               
   Ã  sž   t ddœdd„ƒ} tjtdd��j | ƒ 4 I d H š6}|2 z3 d H W }|dks6J ‚q66 W d   ƒI d H  q|1 I d H sr0    Y  W d   ƒ n1 s�0    Y  d S )Nr{   r   c                   S s   dV  t dƒ‚d S )Nr   Zoae)r   r+   r+   r+   r,   r}   Õ  s    z*test_as_safe_channel_no_race.<locals>.agenz^oae$r   r   )r   r   r   r   r   r+   r+   r,   Útest_as_safe_channel_no_raceÒ  s    rŒ   ztrio.testing.MockClockc              
   Ã  s¨   t ddœdd„ƒ}t d¡�x |ƒ 4 I d H šD}|2 z&3 d H W }|dksJJ ‚t ¡ I d H  q26 W d   ƒI d H  q†1 I d H s|0    Y  W d   ƒ n1 sš0    Y  d S )Nr{   r   c                   S s   dV  t dƒ‚d S )Nr   z;buffer size 0 means we shouldn't be asked for another valuer‡   r+   r+   r+   r,   r}   ã  s    ÿz8test_as_safe_channel_buffer_size_too_small.<locals>.agenrK   r   )r   r"   r0   Úsleep_forever)r.   r}   r€   r�   r+   r+   r,   Ú*test_as_safe_channel_buffer_size_too_smallà  s    rŽ   c               	   Ã  sv   t ddœdd„ƒ} | ƒ 4 I d H š<}| ¡ I d H dks8J ‚tj ¡ I d H  W d   ƒI d H  qr1 I d H sh0    Y  d S )Nr{   r   c                   S s   dV  t ‚d S r|   r‡   r+   r+   r+   r,   r}   ò  s    z0test_as_safe_channel_no_interleave.<locals>.agenr   )r   rƒ   r"   ÚlowlevelÚ
checkpointr„   r+   r+   r,   Ú"test_as_safe_channel_no_interleaveñ  s
    r‘   c               
   Ã  sÒ   t dddœdd„ƒ} g }ttttdd�ttdd�ƒd	d��t | |ƒ4 I d H š>}|2 z 3 d H W }|d
ksjJ ‚tdƒ‚qR6 W d   ƒI d H  q 1 I d H s–0    Y  W d   ƒ n1 s´0    Y  |ddgksÎJ ‚d S )Nú	list[str]r{   ©Úeventsr   c              
   S sp   zVz
dV  W n4 t y@ } z|  t|ƒ¡ ‚ W Y d }~n
d }~0 0 W |  d¡ tdƒ‚n|  d¡ tdƒ‚0 d S )Nr   Úfinallyr}   )ÚBaseExceptionrH   r   r   )r”   Úer+   r+   r,   r}   ý  s    


ÿ
z2test_as_safe_channel_genexit_finally.<locals>.agenz^agen$r   z
^iterator$z^Encountered exception during cleanup of generator object, as well as exception in the contextmanager body - unable to unwrap.$r   ÚiteratorzGeneratorExit()r•   )r   r
   r	   r   r   )r}   r”   r€   r4   r+   r+   r,   Ú$test_as_safe_channel_genexit_finallyü  s    


þûTr™   c                  Ã  sÞ   t ddœdd„ƒ} d}| ƒ 4 I d H š }|2 z‚3 d H W }| ƒ 4 I d H šJ}d}|2 z(3 d H W }||f||fksnJ ‚|d7 }qN6 W d   ƒI d H  q¤1 I d H sš0    Y  |d7 }q*6 W d   ƒI d H  qÚ1 I d H sÐ0    Y  d S )Nr{   r   c                  S s   t dƒD ]
} | V  qd S )Nr   )r5   )r4   r+   r+   r,   r}     s    z.test_as_safe_channel_nested_loop.<locals>.agenr   r   r~   )r}   ÚiiZ
recv_chan1r4   r€   Zjjr6   r+   r+   r,   Ú test_as_safe_channel_nested_loop  s    6r›   c               
   Ã  s–   t ddœdd„ƒ} t t¡�f | ƒ 4 I d H š*}|2 z3 d H W }q26 W d   ƒI d H  ql1 I d H sb0    Y  tdƒ‚W d   ƒ n1 sˆ0    Y  d S )Nr†   r   c                  S s:   t  ¡ �} |  ¡  d V  W d   ƒ n1 s,0    Y  d S r8   )r"   r‰   rq   )Zcscoper+   r+   r,   r}   *  s    
z;test_as_safe_channel_doesnt_leak_cancellation.<locals>.agenzshould be reachable)r   r   r   rˆ   )r}   r€   Ú_r+   r+   r,   Ú-test_as_safe_channel_doesnt_leak_cancellation)  s    .r�   c               
   Ã  s”   t ddœdd„ƒ} tttdd�dd��Z | ƒ 4 I d H š&}tdtdƒgƒ‚W d   ƒI d H  qr1 I d H sh0    Y  W d   ƒ n1 s†0    Y  d S )Nr†   r   c                   S s   t dƒ‚d V  d S )Nznot entered)ÚNotImplementedErrorr+   r+   r+   r,   r}   8  s    zBtest_as_safe_channel_dont_unwrap_user_exceptiongroup.<locals>.agenÚbarr   Zfoo)r   r
   r	   r   r   )r}   rœ   r+   r+   r,   Ú4test_as_safe_channel_dont_unwrap_user_exceptiongroup7  s
    r    c               
   ƒ  sÜ   t  ¡ ‰ tddœ‡ fdd„ƒ} ddddd	œd
d„}| ƒ 4 I d H š‚}t  ¡ 4 I d H šF}| ||d¡I d H  | ||d¡I d H  ˆ  ¡  W d   ƒI d H  q®1 I d H s¤0    Y  W d   ƒI d H  qØ1 I d H sÎ0    Y  d S )Nr{   r   c                    s   ˆ   ¡ I d H  dV  dV  d S )Nr   r   )Úwaitr+   ©Úeventr+   r,   r}   E  s    z4test_as_safe_channel_multiple_receiver.<locals>.agenztrio.abc.ReceiveChannel[int]r   ztrio.TaskStatusr   )r€   r:   Útask_statusr   c                 Ó  s"   |  ¡  |  ¡ I d H |ksJ ‚d S r8   )Ústartedr$   )r€   r:   r¤   r+   r+   r,   Úhandle_valueK  s    z<test_as_safe_channel_multiple_receiver.<locals>.handle_valuer   r   )r"   ÚEventr   r>   ÚstartrL   )r}   r¦   r€   rC   r+   r¢   r,   Ú&test_as_safe_channel_multiple_receiverB  s    r©   c                  Ã  s  t dddœdd„ƒ} g }t ¡ �Ê}t tj¡�ž | |ƒ4 I d H šh}|2 zJ3 d H W }| ¡  ztj ¡ I d H  W qF tjyŽ   | 	d¡ ‚ Y qF0 qF6 W d   ƒI d H  q¾1 I d H s´0    Y  W d   ƒ n1 sÒ0    Y  W d   ƒ n1 sð0    Y  |ddgk�sJ ‚d S )Nr’   r†   r“   c                 S s~   z@d V  W zt j ¡ I d H  W qz t jy>   |  d¡ ‚ Y qz0 n8zt j ¡ I d H  W n  t jyv   |  d¡ ‚ Y n0 0 d S )Núagen cancel)r"   r�   r�   Ú	CancelledrH   )r”   r+   r+   r,   r}   [  s    

ü
z/test_as_safe_channel_multi_cancel.<locals>.agenzbody cancelrª   )
r   r"   r‰   r   r   r«   rq   r�   r�   rH   )r}   r”   rŠ   r€   rœ   r+   r+   r,   Ú!test_as_safe_channel_multi_cancelZ  s    

rr¬   c               	   Ã  sh   t ddœdd„ƒ} | ƒ 4 I d H š.}|2 z3 d H W } q:q&6 W d   ƒI d H  qd1 I d H sZ0    Y  d S )Nr†   r   c               
   S s†   zFt  ¡ 4 I d H š d V  W d   ƒI d H  qD1 I d H s:0    Y  W n: ty€ }  z"t t¡ | ¡sjJ ‚‚ W Y d } ~ n
d } ~ 0 0 d S r8   )r"   r>   r–   r   r
   ÚGeneratorExitÚmatches)r—   r+   r+   r,   r}   w  s    4z:test_as_safe_channel_genexit_exception_group.<locals>.agenr~   ©r}   Úgrœ   r+   r+   r,   Ú,test_as_safe_channel_genexit_exception_groupv  s
    r±   c                  Ã  sÈ   t ddœdd„ƒ} t t¡�˜ | ƒ 4 I d H šd}t ¡ 4 I d H š( | ¡ I d H  t‚W d   ƒI d H  q|1 I d H sr0    Y  W d   ƒI d H  q¦1 I d H sœ0    Y  W d   ƒ n1 sº0    Y  d S )Nr†   r   c                   S s
   d V  d S r8   r+   r+   r+   r+   r,   r}   †  s    zCtest_as_safe_channel_does_not_suppress_nested_genexit.<locals>.agen)r   r   r
   r­   r"   r>   r$   )r}   r°   r+   r+   r,   Ú5test_as_safe_channel_does_not_suppress_nested_genexit…  s    "r²   c               
   ƒ  s¤   ddœdd„‰ t ddœ‡ fdd„ƒ} t t¡�b | ƒ 4 I d H š.}|2 z3 d H W } qXqD6 W d   ƒI d H  q‚1 I d H sx0    Y  W d   ƒ n1 s–0    Y  d S )Nr   r   c                   Ó  s2   zt  ¡ I d H  W n t jy,   td ‚Y n0 d S r8   )r"   r�   r«   r   r+   r+   r+   r,   Úwait_then_raise‘  s    z<test_as_safe_channel_genexit_filter.<locals>.wait_then_raiser†   c               	    sP   t  ¡ 4 I d H š&} |  ˆ ¡ d V  W d   ƒI d H  qL1 I d H sB0    Y  d S r8   )r"   r>   r?   )rC   ©r³   r+   r,   r}   —  s    
z1test_as_safe_channel_genexit_filter.<locals>.agen)r   r   r
   r   r¯   r+   r´   r,   Ú#test_as_safe_channel_genexit_filter�  s    rµ   c               
   ƒ  s0  dddœdd„‰ t dddœ‡ fdd„ƒ} t t¡�d | tƒ4 I d H š.}|2 z3 d H W } q^qJ6 W d   ƒI d H  qˆ1 I d H s~0    Y  W d   ƒ n1 sœ0    Y  t tt¡�h | tƒ4 I d H š0}|2 z3 d H W } qÞqÊ6 W d   ƒI d H  �q1 I d H �s0    Y  W d   ƒ n1 �s"0    Y  d S )	NrP   r   )Úexr   c                 Ó  s2   zt  ¡ I d H  W n t jy,   | d ‚Y n0 d S r8   )r"   r�   r«   )r¶   r+   r+   r,   r³   ¤  s    zItest_as_safe_channel_swallowing_extra_exceptions.<locals>.wait_then_raiser†   c              	    s^   t  ¡ 4 I d H š4}| ˆ | ¡ | ˆ t¡ d V  W d   ƒI d H  qZ1 I d H sP0    Y  d S r8   )r"   r>   r?   r­   )r¶   rC   r´   r+   r,   r}   ª  s    z>test_as_safe_channel_swallowing_extra_exceptions.<locals>.agen)r   r   r
   rˆ   r­   r   r¯   r+   r´   r,   Ú0test_as_safe_channel_swallowing_extra_exceptions£  s    Pr·   )2Ú
__future__r   ÚsysÚtypingr   r   r   r"   r   r   r   Ztestingr	   r
   r   r   Úversion_infoZexceptiongroupr   Úcollections.abcr   r-   r1   rE   rN   r\   r^   r_   rf   rk   rn   rs   rw   rz   r‚   r…   r‹   rŒ   rŽ   r‘   r™   r›   r�   r    r©   r¬   r±   r²   rµ   r·   r+   r+   r+   r,   Ú<module>   sN   
+::2*
