o
    JXîh’  ã                   @   sÆ   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ zddlZW n ey?   dZY nw ddlZddlmZ dd„ ZG dd	„ d	ejƒZed
krae ¡  dS dS )zTests for streams.py.é    N)Úmock)Úsocket_helper)Úutilsc                   C   s   t  d ¡ d S ©N)ÚasyncioZset_event_loop_policy© r   r   úH/opt/python-3.10.19/usr/lib/python3.10/test/test_asyncio/test_streams.pyÚtearDownModule   s   r	   c                       s†  e Zd ZdZ‡ fdd„Z‡ fdd„Zdd„ Zdd	„ Zej	d
d„ ƒZ
dd„ Ze edu d¡dd„ ƒZej	e edu d¡dd„ ƒƒZdd„ Zdd„ Zej	dd„ ƒZdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Z d4d5„ Z!d6d7„ Z"d8d9„ Z#d:d;„ Z$d<d=„ Z%d>d?„ Z&d@dA„ Z'dBdC„ Z(dDdE„ Z)dFdG„ Z*dHdI„ Z+dJdK„ Z,dLdM„ Z-dNdO„ Z.dPdQ„ Z/dRdS„ Z0dTdU„ Z1dVdW„ Z2dXdY„ Z3dZd[„ Z4ej	d\d]„ ƒZ5e e6j7d^kd_¡d`da„ ƒZ8dbdc„ Z9ddde„ Z:dfdg„ Z;dhdi„ Z<djdk„ Z=dldm„ Z>dndo„ Z?dpdq„ Z@drds„ ZAdtdu„ ZBdvdw„ ZCdxdy„ ZDdzd{„ ZEd|d}„ ZFd~d„ ZGd€d„ ZHd‚dƒ„ ZId„d…„ ZJd†d‡„ ZKdˆd‰„ ZLdŠd‹„ ZMdŒd„ ZN‡  ZOS )ŽÚStreamTestss   line1
line2
line3
c                    s$   t ƒ  ¡  t ¡ | _|  | j¡ d S r   )ÚsuperÚsetUpr   Znew_event_loopÚloopÚset_event_loop©Úself©Ú	__class__r   r   r      s   

zStreamTests.setUpc                    s,   t  | j¡ | j ¡  t ¡  tƒ  ¡  d S r   )Ú
test_utilsÚrun_brieflyr   ÚcloseÚgcZcollectr   ÚtearDownr   r   r   r   r   #   s   
zStreamTests.tearDownc                    sŽ   g ‰ | j  ‡ fdd„¡ | j  |¡\}}| d¡ | ¡ }| j  |¡}|  |d¡ | ¡ }| j  |¡}|  | d¡¡ | 	¡  |  ˆ g ¡ d S )Nc                    ó
   ˆ   |¡S r   ©Úappend©r   Úctx©Úmessagesr   r   Ú<lambda>-   ó   
 z7StreamTests._basetest_open_connection.<locals>.<lambda>ó   GET / HTTP/1.0

ó   HTTP/1.0 200 OK
ó   

Test message)
r   Úset_exception_handlerÚrun_until_completeÚwriteÚreadlineÚassertEqualÚreadÚ
assertTrueÚendswithr   ©r   Úopen_connection_futÚreaderÚwriterÚfÚdatar   r   r   Ú_basetest_open_connection+   s   
z%StreamTests._basetest_open_connectionc                 C   óD   t  ¡ }tj|jŽ }|  |¡ W d   ƒ d S 1 sw   Y  d S r   )r   Úrun_test_serverr   Úopen_connectionÚaddressr2   ©r   ÚhttpdZconn_futr   r   r   Útest_open_connection9   ó   
"þz StreamTests.test_open_connectionc                 C   óD   t  ¡ }t |j¡}|  |¡ W d   ƒ d S 1 sw   Y  d S r   )r   Úrun_test_unix_serverr   Úopen_unix_connectionr6   r2   r7   r   r   r   Útest_open_unix_connection>   ó   
"þz%StreamTests.test_open_unix_connectionc              	      sŠ   g ‰ | j  ‡ fdd„¡ z| j  |¡\}}W t d ¡ nt d ¡ w | d¡ | ¡ }| j  |¡}|  | d¡¡ | 	¡  |  
ˆ g ¡ d S )Nc                    r   r   r   r   r   r   r   r   F   r    zCStreamTests._basetest_open_connection_no_loop_ssl.<locals>.<lambda>r!   r#   )r   r$   r%   r   r   r&   r)   r*   r+   r   r(   r,   r   r   r   Ú%_basetest_open_connection_no_loop_sslD   s   
z1StreamTests._basetest_open_connection_no_loop_sslNzNo ssl modulec                 C   sR   t jdd}tj|jdt  ¡ iŽ}|  |¡ W d   ƒ d S 1 s"w   Y  d S )NT©Zuse_sslÚssl)r   r4   r   r5   r6   Údummy_ssl_contextr@   r7   r   r   r   Ú test_open_connection_no_loop_sslS   s   ÿþ"ûz,StreamTests.test_open_connection_no_loop_sslc                 C   sR   t jdd}tj|jt  ¡ dd}|  |¡ W d   ƒ d S 1 s"w   Y  d S )NTrA   Ú )rB   Zserver_hostname)r   r<   r   r=   r6   rC   r@   r7   r   r   r   Ú%test_open_unix_connection_no_loop_ssl\   s   ý"ùz1StreamTests.test_open_unix_connection_no_loop_sslc                    s˜   g ‰ | j  ‡ fdd„¡ | j  |¡\}}|j tƒ ¡ | ¡ }|  t¡ | j  |¡ W d   ƒ n1 s5w   Y  | ¡  t	 
| j ¡ |  ˆ g ¡ d S )Nc                    r   r   r   r   r   r   r   r   j   r    z=StreamTests._basetest_open_connection_error.<locals>.<lambda>)r   r$   r%   Z	_protocolZconnection_lostÚZeroDivisionErrorr)   ÚassertRaisesr   r   r   r(   )r   r-   r.   r/   r0   r   r   r   Ú_basetest_open_connection_errorh   s   ÿz+StreamTests._basetest_open_connection_errorc                 C   r3   r   )r   r4   r   r5   r6   rI   r7   r   r   r   Útest_open_connection_errort   r:   z&StreamTests.test_open_connection_errorc                 C   r;   r   )r   r<   r   r=   r6   rI   r7   r   r   r   Útest_open_unix_connection_errory   r?   z+StreamTests.test_open_unix_connection_errorc                 C   s*   t j| jd}| d¡ |  d|j¡ d S ©N©r   ó    )r   ÚStreamReaderr   Ú	feed_datar(   Ú_buffer©r   Ústreamr   r   r   Útest_feed_empty_data   s   
z StreamTests.test_feed_empty_datac                 C   s.   t j| jd}| | j¡ |  | j|j¡ d S ©NrM   )r   rO   r   rP   ÚDATAr(   rQ   rR   r   r   r   Útest_feed_nonempty_data…   s   z#StreamTests.test_feed_nonempty_datac                 C   sL   t j| jd}| | j¡ | j | d¡¡}|  d|¡ |  | j|j¡ d S )NrM   r   rN   )	r   rO   r   rP   rV   r%   r)   r(   rQ   ©r   rS   r1   r   r   r   Útest_read_zero‹   s
   zStreamTests.test_read_zeroc                    sf   t jˆ jd‰ˆ j ˆ d¡¡}‡ ‡fdd„}ˆ j |¡ ˆ j |¡}ˆ  ˆ j|¡ ˆ  dˆj	¡ d S )NrM   é   c                      s   ˆ  ˆ j¡ d S r   ©rP   rV   r   rR   r   r   Úcb™   s   z!StreamTests.test_read.<locals>.cbrN   )
r   rO   r   Úcreate_taskr)   Ú	call_soonr%   r(   rV   rQ   ©r   Ú	read_taskr\   r1   r   rR   r   Ú	test_read”   s   zStreamTests.test_readc                 C   sR   t j| jd}| d¡ | d¡ | j | d¡¡}|  d|¡ |  d|j¡ d S )NrM   s   line1s   line2é   ©r   rO   r   rP   r%   r)   r(   rQ   rX   r   r   r   Útest_read_line_breaks¡   s   

z!StreamTests.test_read_line_breaksc                    sb   t j| jd‰ | j ˆ  d¡¡}‡ fdd„}| j |¡ | j |¡}|  d|¡ |  dˆ j¡ d S )NrM   i   c                      s   ˆ   ¡  d S r   )Úfeed_eofr   ©rS   r   r   r\   ±   s   z%StreamTests.test_read_eof.<locals>.cbrN   ©	r   rO   r   r]   r)   r^   r%   r(   rQ   r_   r   rf   r   Útest_read_eof¬   s   zStreamTests.test_read_eofc                    sb   t j| jd‰ | j ˆ  d¡¡}‡ fdd„}| j |¡ | j |¡}|  d|¡ |  dˆ j¡ d S )NrM   éÿÿÿÿc                      s    ˆ   d¡ ˆ   d¡ ˆ  ¡  d S )Ns   chunk1
ó   chunk2©rP   re   r   rf   r   r   r\   ¾   s   

z+StreamTests.test_read_until_eof.<locals>.cbs   chunk1
chunk2rN   rg   r_   r   rf   r   Útest_read_until_eof¹   s   zStreamTests.test_read_until_eofc                 C   ó^   t j| jd}| d¡ | j | d¡¡}|  d|¡ | tƒ ¡ |  	t| jj| d¡¡ d S ©NrM   ó   line
é   ó   li)
r   rO   r   rP   r%   r)   r(   Úset_exceptionÚ
ValueErrorrH   rX   r   r   r   Útest_read_exceptionÉ   ó   
ÿzStreamTests.test_read_exceptionc                 C   s~   |   td¡ tjd| jd W d   ƒ n1 sw   Y  |   td¡ tjd| jd W d   ƒ d S 1 s8w   Y  d S )NZimitr   ©Úlimitr   ri   )ÚassertRaisesRegexrs   r   rO   r   r   r   r   r   Útest_invalid_limitÔ   s   ÿ"ÿzStreamTests.test_invalid_limitc                 C   óJ   t jd| jd}| d¡ | j | d¡¡}|  d|¡ |  d|j¡ d S ©Né   rv   s   chunkrb   rN   rc   rX   r   r   r   Útest_read_limitÛ   ó
   
zStreamTests.test_read_limitc                    sj   t j| jd‰ ˆ  d¡ | j ˆ  ¡ ¡}‡ fdd„}| j |¡ | j |¡}|  d|¡ |  dˆ j	¡ d S )NrM   s   chunk1 c                      s"   ˆ   d¡ ˆ   d¡ ˆ   d¡ d S )Ns   chunk2 s   chunk3 s   
 chunk4)rP   r   rf   r   r   r\   é   s   

z%StreamTests.test_readline.<locals>.cbs   chunk1 chunk2 chunk3 
s    chunk4)
r   rO   r   rP   r]   r'   r^   r%   r(   rQ   )r   r`   r\   Úliner   rf   r   Útest_readlineâ   s   
zStreamTests.test_readlinec                 C   sž   t jd| jd}| d¡ | d¡ |  t| jj| ¡ ¡ |  d|j	¡ t jd| jd}| d¡ | d¡ | d¡ |  t| jj| ¡ ¡ |  d|j	¡ d S )Nr|   rv   rq   s
   ne1
line2
s   line2
s   ne1rN   )
r   rO   r   rP   rH   rs   r%   r'   r(   rQ   rR   r   r   r   Ú&test_readline_limit_with_existing_dataó   s   

ÿ


ÿz2StreamTests.test_readline_limit_with_existing_datac                 C   s†   t j| jd}|  | ¡ ¡ | d¡ |  | ¡ ¡ | j | ¡ ¡ |  | ¡ ¡ | d¡ | ¡  | j | ¡ ¡ |  	| ¡ ¡ d S )NrM   s
   some data
)
r   rO   r   ÚassertFalseÚat_eofrP   r%   r'   re   r*   rR   r   r   r   Útest_at_eof  s   

zStreamTests.test_at_eofc                    s„  t jd| jd‰ ‡ fdd„}| j |¡ |  t| jjˆ  ¡ ¡ |  dˆ j	¡ t jd| jd‰ ‡ fdd„}| j |¡ |  t| jjˆ  ¡ ¡ |  dˆ j	¡ t jd| jd‰ ˆ  
d¡ | j ˆ  ¡ ¡}|  d|¡ |  dˆ j	¡ ˆ  
d	¡ |  t¡}| j ˆ  ¡ ¡ W d   ƒ n1 s‹w   Y  |  dˆ j	¡ ˆ  
d
¡ |  t¡}| j ˆ  ¡ ¡ W d   ƒ n1 s´w   Y  |  dˆ j	¡ d S )Né   rv   c                      ó*   ˆ   d¡ ˆ   d¡ ˆ   d¡ ˆ  ¡  d S )Nó   chunk1rj   ó   chunk3
rk   r   rf   r   r   r\   "  ó   


z+StreamTests.test_readline_limit.<locals>.cbrN   c                      r†   )Nr‡   s   chunk2
rˆ   rk   r   rf   r   r   r\   0  r‰   rˆ   s   1234567
s	   12345678
s   12345678)r   rO   r   r^   rH   rs   r%   r'   r(   rQ   rP   )r   r\   r   Úcmr   rf   r   Útest_readline_limit  s:   ÿÿ

ÿ
ÿzStreamTests.test_readline_limitc                 C   sd   t j| jd}| | jd d… ¡ | | jdd … ¡ | j | ¡ ¡}|  d|¡ |  d|j¡ d S )NrM   é   s   line1
s   line2
line3
)	r   rO   r   rP   rV   r%   r'   r(   rQ   ©r   rS   r   r   r   r   Útest_readline_nolimit_nowaitL  s   z(StreamTests.test_readline_nolimit_nowaitc                 C   s@   t j| jd}| d¡ | ¡  | j | ¡ ¡}|  d|¡ d S )NrM   s	   some data)r   rO   r   rP   re   r%   r'   r(   r   r   r   r   Útest_readline_eofX  s
   
zStreamTests.test_readline_eofc                 C   s6   t j| jd}| ¡  | j | ¡ ¡}|  d|¡ d S rL   )r   rO   r   re   r%   r'   r(   r   r   r   r   Útest_readline_empty_eof`  s   z#StreamTests.test_readline_empty_eofc                 C   sZ   t j| jd}| | j¡ | j | ¡ ¡ | j | d¡¡}|  d|¡ |  d|j	¡ d S )NrM   r…   s   line2
ls   ine3
)
r   rO   r   rP   rV   r%   r'   r)   r(   rQ   rX   r   r   r   Útest_readline_read_byte_countg  s   z)StreamTests.test_readline_read_byte_countc                 C   sh   t j| jd}| d¡ | j | ¡ ¡}|  d|¡ | tƒ ¡ |  	t| jj| ¡ ¡ |  d|j
¡ d S )NrM   ro   rN   )r   rO   r   rP   r%   r'   r(   rr   rs   rH   rQ   rX   r   r   r   Útest_readline_exceptionr  s   
ÿz#StreamTests.test_readline_exceptionc                 C   sT   t j| jd}|  td¡ | j |jdd¡ W d   ƒ d S 1 s#w   Y  d S )NrM   zSeparator should berN   ©Ú	separator)r   rO   r   rx   rs   r%   Ú	readuntilrR   r   r   r   Útest_readuntil_separator~  s   "ÿz$StreamTests.test_readuntil_separatorc                 C   s¶   t j| jd}| d¡ | j |jdd¡}|  d|¡ |  d|j¡ | d¡ | j | d¡¡}|  d|¡ |  d|j¡ | d¡ | j | d¡¡}|  d|¡ |  d|j¡ d S )NrM   s   lineAAAó   AAAr“   rN   s
   lineAAAxxxs   xxx©r   rO   r   rP   r%   r•   r(   rQ   rX   r   r   r   Útest_readuntil_multi_chunksƒ  s   


z'StreamTests.test_readuntil_multi_chunksc                 C   sf  t j| jd}| d¡ | d¡ | d¡ | j | d¡¡}|  d|¡ |  d|j¡ | d¡ | d¡ | d	¡ | j | d¡¡}|  d|¡ |  d|j¡ | d¡ | j | d¡¡}|  d|¡ |  d|j¡ | d
¡ | j | d¡¡}|  d
|¡ |  d|j¡ | d¡ | d¡ | d¡ | d¡ | j | d¡¡}|  d|¡ |  d|j¡ d S )NrM   s   QWEaas   XYaaó   as   aaas
   QWEaaXYaaarN   s   XYas   aas   Xaaas   XXXs   XXXaaar˜   rX   r   r   r   Útest_readuntil_multi_chunks_1•  s8   











z)StreamTests.test_readuntil_multi_chunks_1c                 C   s”   t j| jd}d}| |¡ | ¡  |  t jd¡}| j | d¡¡ W d   ƒ n1 s-w   Y  |  	|j
j|¡ |  |j
j¡ |  	d|j¡ d S )NrM   ó   some dataAAzundefined expected bytesr—   rN   )r   rO   r   rP   re   rx   ÚIncompleteReadErrorr%   r•   r(   Ú	exceptionÚpartialÚassertIsNoneÚexpectedrQ   )r   rS   r1   rŠ   r   r   r   Útest_readuntil_eof¸  s   
ÿþzStreamTests.test_readuntil_eofc                 C   sÄ   t j| jdd}| d¡ |  t jd¡}| j | d¡¡ W d   ƒ n1 s(w   Y  |  d|j	¡ | d¡ |  t jd¡}| j | d¡¡ W d   ƒ n1 sTw   Y  |  d|j	¡ d S )	Nr|   ©r   rw   rœ   z	not foundr—   ó   Azis founds   some dataAAA)
r   rO   r   rP   rx   ÚLimitOverrunErrorr%   r•   r(   rQ   )r   rS   rŠ   r   r   r   Útest_readuntil_limit_found_sepÅ  s"   
ÿþ
ÿþz*StreamTests.test_readuntil_limit_found_sepc                 C   sš   t j| jd}| | j¡ | j | d¡¡}|  d|¡ |  | j|j¡ |  	t
d¡ | j | d¡¡ W d   ƒ n1 s>w   Y  |  | j|j¡ d S )NrM   r   rN   zless than zerori   )r   rO   r   rP   rV   r%   Úreadexactlyr(   rQ   rx   rs   rX   r   r   r   Útest_readexactly_zero_or_lessÕ  s   ÿz)StreamTests.test_readexactly_zero_or_lessc                    s|   t jˆ jd‰dtˆ jƒ }ˆ j ˆ |¡¡}‡ ‡fdd„}ˆ j |¡ ˆ j |¡}ˆ  	ˆ jˆ j |¡ ˆ  	ˆ jˆj
¡ d S )NrM   rp   c                      s(   ˆ  ˆ j¡ ˆ  ˆ j¡ ˆ  ˆ j¡ d S r   r[   r   rR   r   r   r\   é  s   z(StreamTests.test_readexactly.<locals>.cb)r   rO   r   ÚlenrV   r]   r§   r^   r%   r(   rQ   )r   Únr`   r\   r1   r   rR   r   Útest_readexactlyâ  s   zStreamTests.test_readexactlyc                 C   rz   r{   )r   rO   r   rP   r%   r§   r(   rQ   rX   r   r   r   Útest_readexactly_limitó  r~   z"StreamTests.test_readexactly_limitc                    sÆ   t jˆ jd‰dtˆ jƒ }ˆ j ˆ |¡¡}‡ ‡fdd„}ˆ j |¡ ˆ  t j	¡}ˆ j 
|¡ W d   ƒ n1 s;w   Y  ˆ  |jjˆ j¡ ˆ  |jj|¡ ˆ  t|jƒd¡ ˆ  dˆj¡ d S )NrM   rp   c                      s   ˆ  ˆ j¡ ˆ ¡  d S r   )rP   rV   re   r   rR   r   r   r\      s   z,StreamTests.test_readexactly_eof.<locals>.cbz-18 bytes read on a total of 36 expected bytesrN   )r   rO   r   r©   rV   r]   r§   r^   rH   r   r%   r(   rž   rŸ   r¡   ÚstrrQ   )r   rª   r`   r\   rŠ   r   rR   r   Útest_readexactly_eofú  s   ÿÿz StreamTests.test_readexactly_eofc                 C   rm   rn   )
r   rO   r   rP   r%   r§   r(   rr   rs   rH   rX   r   r   r   Útest_readexactly_exception  ru   z&StreamTests.test_readexactly_exceptionc                 C   s@   t j| jd}|  | ¡ ¡ tƒ }| |¡ |  | ¡ |¡ d S rU   )r   rO   r   r    rž   rs   rr   ÚassertIs©r   rS   Úexcr   r   r   Útest_exception  s
   
zStreamTests.test_exceptionc                    s`   t j| jd‰ ‡ fdd„}| j ˆ  ¡ ¡}| j |ƒ ¡}| j t  ||g¡¡ |  t|j	¡ d S )NrM   c                   “   s   ˆ   tƒ ¡ d S r   )rr   rs   r   rf   r   r   Úset_err#  s   €z2StreamTests.test_exception_waiter.<locals>.set_err)
r   rO   r   r]   r'   r%   ÚwaitrH   rs   Úresult)r   r´   Út1Út2r   rf   r   Útest_exception_waiter   s   z!StreamTests.test_exception_waiterc                 C   sj   t j| jd}| j | ¡ ¡}t | j¡ | ¡  t | j¡ | t	dƒ¡ t | j¡ |  
|jd ¡ d S )NrM   Úmessage)r   rO   r   r]   r'   r   r   Úcancelrr   ÚRuntimeErrorr°   Ú_waiter)r   rS   Útr   r   r   Útest_exception_cancel-  s   z!StreamTests.test_exception_cancelc                    sº   G dd„ dƒ}dd„ }g ‰ | j  ‡ fdd„¡ || j ƒ}| ¡ }| j  | j  ||ƒ¡¡}| ¡  |  |d¡ || j ƒ}| ¡ }| j  | j  ||ƒ¡¡}| ¡  |  |d¡ |  ˆ g ¡ d S )Nc                   @   ó<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )z/StreamTests.test_start_server.<locals>.MyServerc                 S   s   d | _ || _d S r   )Úserverr   )r   r   r   r   r   Ú__init__=  s   
z8StreamTests.test_start_server.<locals>.MyServer.__init__c                 Ó   óB   |  ¡ I d H }| |¡ | ¡ I d H  | ¡  | ¡ I d H  d S r   ©r'   r&   Údrainr   Úwait_closed©r   Úclient_readerÚclient_writerr1   r   r   r   Úhandle_clientA  ó   €
z=StreamTests.test_start_server.<locals>.MyServer.handle_clientc                 S   s,   t  d¡}| j tj| j|d¡| _| ¡ S )N©z	127.0.0.1r   )Úsock)	ÚsocketÚcreate_serverr   r%   r   Ústart_serverrÊ   rÁ   Úgetsockname)r   rÍ   r   r   r   ÚstartH  s   
ÿÿz5StreamTests.test_start_server.<locals>.MyServer.startc                 S   ó   | j  |  ||¡¡ d S r   ©r   r]   rÊ   ©r   rÈ   rÉ   r   r   r   Úhandle_client_callbackO  ó   
ÿzFStreamTests.test_start_server.<locals>.MyServer.handle_client_callbackc                 S   sB   t  d¡}| ¡ }| ¡  | j tj| j|d |d d¡| _	|S )NrÌ   r   é   )ÚhostÚport)
rÎ   rÏ   rÑ   r   r   r%   r   rÐ   rÖ   rÁ   )r   rÍ   Úaddrr   r   r   Ústart_callbackS  s   
ÿÿz>StreamTests.test_start_server.<locals>.MyServer.start_callbackc                 S   ó4   | j d ur| j  ¡  | j | j  ¡ ¡ d | _ d S d S r   ©rÁ   r   r   r%   rÆ   r   r   r   r   Ústop\  ó
   


ýz4StreamTests.test_start_server.<locals>.MyServer.stopN©	Ú__name__Ú
__module__Ú__qualname__rÂ   rÊ   rÒ   rÖ   rÜ   rß   r   r   r   r   ÚMyServer;  s    	rå   c                 Ó   sH   t j| Ž I d H \}}| d¡ | ¡ I d H }| ¡  | ¡ I d H  |S ©Nó   hello world!
)r   r5   r&   r'   r   rÆ   )rÛ   r.   r/   Úmsgbackr   r   r   Úclientb  ó   €
z-StreamTests.test_start_server.<locals>.clientc                    r   r   r   r   r   r   r   r   m  r    z/StreamTests.test_start_server.<locals>.<lambda>rç   )r   r$   rÒ   r%   r]   rß   r(   rÜ   )r   rå   ré   rÁ   rÛ   Úmsgr   r   r   Útest_start_server9  s   '


zStreamTests.test_start_serverc                    s  G dd„ dƒ}dd„ }g ‰ | j  ‡ fdd„¡ t ¡ (}|| j |ƒ}| ¡  | j  | j  ||ƒ¡¡}| ¡  |  |d¡ W d   ƒ n1 sFw   Y  t ¡ (}|| j |ƒ}| 	¡  | j  | j  ||ƒ¡¡}| ¡  |  |d¡ W d   ƒ n1 szw   Y  |  ˆ g ¡ d S )Nc                   @   rÀ   )z4StreamTests.test_start_unix_server.<locals>.MyServerc                 S   s   d | _ || _|| _d S r   )rÁ   r   Úpath)r   r   rí   r   r   r   rÂ   „  s   
z=StreamTests.test_start_unix_server.<locals>.MyServer.__init__c                 Ó   rÃ   r   rÄ   rÇ   r   r   r   rÊ   ‰  rË   zBStreamTests.test_start_unix_server.<locals>.MyServer.handle_clientc                 S   s    | j  tj| j| jd¡| _d S ©N)rí   )r   r%   r   Ústart_unix_serverrÊ   rí   rÁ   r   r   r   r   rÒ     s
   ÿ
ÿz:StreamTests.test_start_unix_server.<locals>.MyServer.startc                 S   rÓ   r   rÔ   rÕ   r   r   r   rÖ   •  r×   zKStreamTests.test_start_unix_server.<locals>.MyServer.handle_client_callbackc                 S   s$   t j| j| jd}| j |¡| _d S rî   )r   rï   rÖ   rí   r   r%   rÁ   )r   rÒ   r   r   r   rÜ   ™  s   ÿzCStreamTests.test_start_unix_server.<locals>.MyServer.start_callbackc                 S   rÝ   r   rÞ   r   r   r   r   rß   ž  rà   z9StreamTests.test_start_unix_server.<locals>.MyServer.stopNrá   r   r   r   r   rå   ‚  s    rå   c                 Ó   sH   t  | ¡I d H \}}| d¡ | ¡ I d H }| ¡  | ¡ I d H  |S ræ   )r   r=   r&   r'   r   rÆ   )rí   r.   r/   rè   r   r   r   ré   ¤  rê   z2StreamTests.test_start_unix_server.<locals>.clientc                    r   r   r   r   r   r   r   r   ¯  r    z4StreamTests.test_start_unix_server.<locals>.<lambda>rç   )
r   r$   r   Zunix_socket_pathrÒ   r%   r]   rß   r(   rÜ   )r   rå   ré   rí   rÁ   rë   r   r   r   Útest_start_unix_server  s.   "

ÿú
	ÿúz"StreamTests.test_start_unix_serverÚwin32zDon't have pipesc              	      s  d}t  ¡ \}}tjd|t|ƒg}t|ddƒ}tj| jdd}tj	|| jd‰ | j 
| j ‡ fdd	„|¡¡\}}t ¡ }	|	 | j¡ z#t |	¡ tj|d
|hiŽ}
| j 
|
¡}| j 
| ¡ ¡ W t d ¡ nt d ¡ w t  |¡ | j 
| d¡¡}|  |d¡ d S )NzHimport os, sys
fd = int(sys.argv[1])
os.write(fd, b'data')
os.close(fd)
z-cÚrbr   rØ   r£   rM   c                      s   ˆ S r   r   r   ©Úprotocolr   r   r   Ú  s    z<StreamTests.test_read_all_from_pipe_reader.<locals>.<lambda>Úpass_fdsri   ó   data)ÚosÚpipeÚsysÚ
executabler­   Úopenr   rO   r   ÚStreamReaderProtocolr%   Zconnect_read_pipeZSafeChildWatcherZattach_loopZset_child_watcherZcreate_subprocess_execrµ   r   r)   r(   )r   ÚcodeZrfdZwfdÚargsrø   r.   Z	transportÚ_ZwatcherZcreateÚprocr1   r   ró   r   Útest_read_all_from_pipe_readerÅ  s0   ÿ
ÿþ
z*StreamTests.test_read_all_from_pipe_readerc                 C   s:   |   td¡ t ¡  W d   ƒ d S 1 sw   Y  d S ©Nzno current event loop)rx   r¼   r   rO   r   r   r   r   Ú*test_streamreader_constructor_without_loopí  s   
"ÿz6StreamTests.test_streamreader_constructor_without_loopc                 C   s*   dd„ }| j  |ƒ ¡}|  |j| j ¡ d S )Nc                   Ó   s
   t  ¡ S r   )r   rO   r   r   r   r   Útestô  s   €zHStreamTests.test_streamreader_constructor_use_running_loop.<locals>.test)r   r%   r°   Ú_loop)r   r  r.   r   r   r   Ú.test_streamreader_constructor_use_running_loopñ  s   z:StreamTests.test_streamreader_constructor_use_running_loopc                 C   s6   |   tjd ¡ t | j¡ t ¡ }|  |j| j¡ d S r   )Ú
addCleanupr   r   r   rO   r°   r  ©r   r.   r   r   r   Ú-test_streamreader_constructor_use_global_loopú  s   z9StreamTests.test_streamreader_constructor_use_global_loopc                 C   sD   t  ¡ }|  td¡ t |¡ W d   ƒ d S 1 sw   Y  d S r  )r   ÚMockrx   r¼   r   rü   r  r   r   r   Ú2test_streamreaderprotocol_constructor_without_loop  s   "ÿz>StreamTests.test_streamreaderprotocol_constructor_without_loopc                    s6   t  ¡ ‰ ‡ fdd„}| j |ƒ ¡}|  |j| j¡ d S )Nc                   “   s   t  ˆ ¡S r   )r   rü   r   ©r.   r   r   r    s   €
zPStreamTests.test_streamreaderprotocol_constructor_use_running_loop.<locals>.test)r   r
  r   r%   r°   r  )r   r  rô   r   r  r   Ú6test_streamreaderprotocol_constructor_use_running_loop	  s   zBStreamTests.test_streamreaderprotocol_constructor_use_running_loopc                 C   s@   |   tjd ¡ t | j¡ t ¡ }t |¡}|  |j| j¡ d S r   )	r  r   r   r   r   r
  rü   r°   r  )r   r.   rô   r   r   r   Ú5test_streamreaderprotocol_constructor_use_global_loop  s
   
zAStreamTests.test_streamreaderprotocol_constructor_use_global_loopc                    s2   d‰ ‡ fdd„‰‡ ‡‡fdd„}ˆj  |ƒ ¡ d S )Nr   c                 “   s   |   ¡ I d H  ˆ d7 ‰ d S )NrØ   )Z_drain_helperrf   )Údrainedr   r   Údrainer   s   €z0StreamTests.test_multiple_drain.<locals>.drainerc                  “   s`   t  ¡ } t j | ¡‰ ˆ  ¡  |  dˆ j¡ t j‡‡ fdd„tdƒD ƒŽ I d H  ˆ 	ˆd¡ d S )Ngš™™™™™¹?c                    s   g | ]}ˆ ˆƒ‘qS r   r   )Ú.0rÿ   )r  rS   r   r   Ú
<listcomp>*  s    zAStreamTests.test_multiple_drain.<locals>.main.<locals>.<listcomp>é
   )
r   Zget_running_loopZstreamsZFlowControlMixinZpause_writingZ
call_laterZresume_writingZgatherÚranger(   rM   ©r  r  r   rf   r   Úmain%  s   €$z-StreamTests.test_multiple_drain.<locals>.main)r   r%   )r   r  r   r  r   Útest_multiple_drain  s   zStreamTests.test_multiple_drainc                    s®   g ‰ | j  ‡ fdd„¡ t ¡ ‰‡fdd„}dd„ }tj|d}d|_| ¡  ˆ ¡ }|  	t
ttf¡ | j  ||Ž ¡ W d   ƒ n1 sFw   Y  | ¡  |  g ˆ ¡ d S )	Nc                    r   r   r   r   r   r   r   r   8  r    z/StreamTests.test_drain_raises.<locals>.<lambda>c                     sV   t  d¡} |  ¡ }ˆ  |¡ |  ¡ \}}| ¡  W d   ƒ d S 1 s$w   Y  d S )N)Ú	localhostr   )rÎ   rÏ   rÑ   ÚputÚacceptr   )rÍ   rÛ   Zcltrÿ   )Úqr   r   rÁ   ;  s   

"üz-StreamTests.test_drain_raises.<locals>.serverc                 Ó   s4   t  | |¡I d H \}}	 | d¡ | ¡ I d H  q)NTs   foo
)r   r5   r&   rÅ   )rÙ   rÚ   r.   r/   r   r   r   ré   C  s   €
þz-StreamTests.test_drain_raises.<locals>.client)ÚtargetT)r   r$   ÚqueueÚQueueÚ	threadingÚThreadÚdaemonrÒ   ÚgetrH   ÚConnectionResetErrorÚConnectionAbortedErrorÚBrokenPipeErrorr%   Újoinr(   )r   rÁ   ré   ÚthreadrÛ   r   )r   r  r   Útest_drain_raises/  s    ÿþzStreamTests.test_drain_raisesc                 C   s"   t j| jd}|  dt|ƒ¡ d S )NrM   ú<StreamReader>©r   rO   r   r(   ÚreprrR   r   r   r   Útest___repr__Z  s   zStreamTests.test___repr__c                 C   s$   t j| jdd}|  dt|ƒ¡ d S )Né{   r£   z<StreamReader limit=123>r*  rR   r   r   r   Útest___repr__nondefault_limit^  s   z)StreamTests.test___repr__nondefault_limitc                 C   s*   t j| jd}| ¡  |  dt|ƒ¡ d S )NrM   z<StreamReader eof>)r   rO   r   re   r(   r+  rR   r   r   r   Útest___repr__eofb  s   zStreamTests.test___repr__eofc                 C   s,   t j| jd}| d¡ |  dt|ƒ¡ d S )NrM   rö   z<StreamReader 4 bytes>)r   rO   r   rP   r(   r+  rR   r   r   r   Útest___repr__datag  s   
zStreamTests.test___repr__datac                 C   s2   t j| jd}tƒ }| |¡ |  dt|ƒ¡ d S )NrM   z'<StreamReader exception=RuntimeError()>)r   rO   r   r¼   rr   r(   r+  r±   r   r   r   Útest___repr__exceptionl  s   
ÿz"StreamTests.test___repr__exceptionc                 C   sb   t j| jd}t j| jd|_|  t|ƒd¡ |j d ¡ | j |j¡ d |_|  	dt|ƒ¡ d S )NrM   z,<StreamReader waiter=<Future pending[\S ]*>>r)  )
r   rO   r   ÚFuturer½   ZassertRegexr+  Ú
set_resultr%   r(   rR   r   r   r   Útest___repr__waiters  s   þzStreamTests.test___repr__waiterc                 C   sB   t j| jd}t ¡ |_t ¡ |j_d|jj_|  dt	|ƒ¡ d S )NrM   z<Transport>z$<StreamReader transport=<Transport>>)
r   rO   r   r   r
  Z
_transportÚ__repr__Zreturn_valuer(   r+  rR   r   r   r   Útest___repr__transport~  s
   

z"StreamTests.test___repr__transportc              	   C   s˜   t  dd¡}ttjd ƒD ]<}| j|d, t tj||d¡}|  t	|ƒt	|ƒ¡ |  |j
|j
¡ |  |j|j¡ W d   ƒ n1 sDw   Y  qd S )Ns   abcr  rØ   ©Zpickle_protocolró   )r   r   r  ÚpickleÚHIGHEST_PROTOCOLÚsubTestÚloadsÚdumpsr(   r­   rŸ   r¡   ©r   ÚeÚprotoÚe2r   r   r   Ú#test_IncompleteReadError_pickleable…  s   ü€ÿz/StreamTests.test_IncompleteReadError_pickleablec              	   C   sˆ   t  dd¡}ttjd ƒD ]4}| j|d$ t tj||d¡}|  t	|ƒt	|ƒ¡ |  |j
|j
¡ W d   ƒ n1 s<w   Y  qd S )Nrº   r  rØ   r7  ró   )r   r¥   r  r8  r9  r:  r;  r<  r(   r­   Úconsumedr=  r   r   r   Ú!test_LimitOverrunError_pickleableŽ  s   ý€ÿz-StreamTests.test_LimitOverrunError_pickleablec                 C   sÈ   t  ¡ V}| j tj|jŽ ¡\}}| d¡ | ¡ }| j |¡}|  	|d¡ | 
¡ }| j |¡}|  | d¡¡ |  | ¡ ¡ | ¡  |  | ¡ ¡ | j | ¡ ¡ W d   ƒ d S 1 s]w   Y  d S ©Nr!   r"   r#   )r   r4   r   r%   r   r5   r6   r&   r'   r(   r)   r*   r+   r‚   Z
is_closingr   rÆ   ©r   r8   ÚrdÚwrr0   r1   r   r   r   Útest_wait_closed_on_close–  s    

ÿ
"òz%StreamTests.test_wait_closed_on_closec                 C   sˆ   t  ¡ 6}| j tj|jŽ ¡\}}| d¡ | ¡ }| j |¡}|  	|d¡ | 
¡  | j | ¡ ¡ W d   ƒ d S 1 s=w   Y  d S )Nr!   r"   )r   r4   r   r%   r   r5   r6   r&   r'   r(   r   rÆ   rE  r   r   r   Ú*test_wait_closed_on_close_with_unread_data§  s   

ÿ
"÷z6StreamTests.test_wait_closed_on_close_with_unread_datac                    ól   ‡fdd„}g ‰ ˆj  ‡ fdd„¡ t ¡ }ˆj  ||ƒ¡ W d   ƒ n1 s)w   Y  ˆ ˆ g ¡ d S )Nc                 “   st   t j| jŽ I d H \}}| d¡ | ¡ I d H }ˆ  |d¡ | ¡ I d H }ˆ  | d¡¡ | 	¡  | 
¡ I d H  d S rD  )r   r5   r6   r&   r'   r(   r)   r*   r+   r   rÆ   ©r8   rF  rG  r1   r   r   r   Úinner´  s   €
z0StreamTests.test_async_writer_api.<locals>.innerc                    r   r   r   r   r   r   r   r   À  r    z3StreamTests.test_async_writer_api.<locals>.<lambda>©r   r$   r   r4   r%   r(   ©r   rL  r8   r   ©r   r   r   Útest_async_writer_api³  s   
ÿz!StreamTests.test_async_writer_apic                    rJ  )Nc                 “   sª   t j| jŽ I d H \}}| d¡ | ¡ I d H }ˆ  |d¡ | ¡ I d H }ˆ  | d¡¡ | 	¡  ˆ  
t¡ | d¡ | ¡ I d H  W d   ƒ d S 1 sNw   Y  d S )Nr!   r"   r#   rö   )r   r5   r6   r&   r'   r(   r)   r*   r+   r   rH   r#  rÅ   rK  r   r   r   rL  È  s   €

"þzFStreamTests.test_async_writer_api_exception_after_close.<locals>.innerc                    r   r   r   r   r   r   r   r   Ö  r    zIStreamTests.test_async_writer_api_exception_after_close.<locals>.<lambda>rM  rN  r   rO  r   Ú+test_async_writer_api_exception_after_closeÇ  s   
ÿz7StreamTests.test_async_writer_api_exception_after_closec                    s²   g ‰ | j  ‡ fdd„¡ t ¡ 9}| j  tj|jŽ ¡\}}| ¡  | 	¡ }| j  |¡ |  
| ¡ ¡ | ¡ }| j  |¡}|  |d¡ W d   ƒ n1 sLw   Y  |  ˆ g ¡ d S )Nc                    r   r   r   r   r   r   r   r   à  r    z?StreamTests.test_eof_feed_when_closing_writer.<locals>.<lambda>rN   )r   r$   r   r4   r%   r   r5   r6   r   rÆ   r*   rƒ   r)   r(   rE  r   r   r   Ú!test_eof_feed_when_closing_writerÝ  s   

ÿöz-StreamTests.test_eof_feed_when_closing_writer)Prâ   rã   rä   rV   r   r   r2   r9   r   Zskip_unless_bind_unix_socketr>   r@   ÚunittestZskipIfrB   rD   rF   rI   rJ   rK   rT   rW   rY   ra   rd   rh   rl   rt   ry   r}   r€   r   r„   r‹   rŽ   r   r   r‘   r’   r–   r™   r›   r¢   r¦   r¨   r«   r¬   r®   r¯   r³   r¹   r¿   rì   rð   rù   Úplatformr  r  r  r	  r  r  r  r  r(  r,  r.  r/  r0  r1  r4  r6  rA  rC  rH  rI  rP  rQ  rR  Ú__classcell__r   r   r   r   r
      sš    



	/#F
E
'	
	
+	r
   Ú__main__)Ú__doc__r   r÷   r  r8  rÎ   rù   r  rS  r   Ztest.supportr   rB   ÚImportErrorr   Ztest.test_asyncior   r   r	   ZTestCaser
   râ   r  r   r   r   r   Ú<module>   s<    ÿ       ^ÿ