a
    	¼3j   ã                   @   s  d 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ZddlmZ ddlm	Z	 ddlm
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ dd„ Zdd„ ZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZe ejdkd¡G dd„ dejƒƒZedkre ¡  dS )zTests for proactor_events.pyé    N)Úmock)ÚBaseProactorEventLoop)Ú_ProactorSocketTransport)Ú_ProactorWritePipeTransport)Ú_ProactorDuplexPipeTransport)Ú_ProactorDatagramTransport)Úsupport)Úsocket_helper)Úutilsc                   C   s   t  d ¡ d S ©N)ÚasyncioZset_event_loop_policy© r   r   úb/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_asyncio/test_proactor_events.pyÚtearDownModule   s    r   c                 C   s"   | j d u rd S | j  ¡  d | _ d S r   )Ú_sockÚclose)Ú	transportr   r   r   Úclose_transport   s    

r   c                       sr  e Zd Z‡ fdd„ZdSdd„Zdd„ Zdd	„ Zd
d„ Ze 	e
jjd¡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e d!¡d"d#„ ƒZd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Ze d0¡d1d2„ ƒZ d3d4„ Z!d5d6„ Z"d7d8„ Z#d9d:„ Z$d;d<„ Z%d=d>„ Z&d?d@„ Z'dAdB„ Z(dCdD„ Z)dEdF„ Z*dGdH„ Z+dIdJ„ Z,dKdL„ Z-dMdN„ Z.dOdP„ Z/dQdR„ Z0‡  Z1S )TÚProactorSocketTransportTestsc                    sV   t ƒ  ¡  |  ¡ | _|  | jj¡ t ¡ | _| j| j_	t
 tj¡| _t tj¡| _d S r   )ÚsuperÚsetUpÚnew_test_loopÚloopÚ
addCleanupr   r   ÚMockÚproactorÚ	_proactorÚ
test_utilsÚmake_test_protocolr   ÚProtocolÚprotocolÚsocketÚsock©Úself©Ú	__class__r   r   r   #   s    



z"ProactorSocketTransportTests.setUpNc                 C   s&   t | j| j| j|d}|  t|¡ |S )N©Úwaiter)r   r   r"   r    r   r   )r$   r(   r   r   r   r   Úsocket_transport,   s
    
ÿz-ProactorSocketTransportTests.socket_transportc                 C   sR   | j  ¡ }| j|d}t | j ¡ |  | ¡ ¡ | j |¡ | j	j
 | jd¡ d S )Nr'   é €  )r   Úcreate_futurer)   r   Úrun_brieflyÚassertIsNoneÚresultr    Úconnection_mader   ÚrecvÚassert_called_withr"   ©r$   ÚfutÚtrr   r   r   Ú	test_ctor2   s    
z&ProactorSocketTransportTests.test_ctorc                 C   sH   |   ¡ }| ¡  | jjj | jd¡ |  | jj	j
¡ |  | jjj
¡ d S )Nr*   )r)   Ú_loop_readingr   r   r0   r1   r"   ÚassertFalser    Údata_receivedÚcalledÚeof_received©r$   r4   r   r   r   Útest_loop_reading:   s
    z.ProactorSocketTransportTests.test_loop_readingc                 C   sR   | j  ¡ }| d¡ |  ¡ }||_| |¡ | j jj | j	d¡ | j
j d¡ d S )Nó   datar*   )r   r+   Ú
set_resultr)   Ú	_read_futr6   r   r0   r1   r"   r    r8   ©r$   Úresr4   r   r   r   Útest_loop_reading_dataA   s    


z3ProactorSocketTransportTests.test_loop_reading_dataú)Assertions are disabled in optimized modec                 C   sz   | j  ¡ }| d¡ |  ¡ }|  t|j|¡ t ¡ |_	||_
| |¡ |  | j jjj¡ |  | jjj¡ |  |j	j¡ d S ©Nó    )r   r+   r>   r)   ÚassertRaisesÚAssertionErrorr6   r   r   r   r?   r7   r   r0   r9   Ú
assertTruer    r:   r@   r   r   r   Útest_loop_reading_no_dataK   s    



z6ProactorSocketTransportTests.test_loop_reading_no_datac                 C   s>   t ƒ  }| jjj_|  ¡ }t ¡ |_| 	¡  |j 
|d¡ d S ©Nz"Fatal read error on pipe transport)ÚConnectionAbortedErrorr   r   r0   Úside_effectr)   r   r   Ú_fatal_errorr6   r1   ©r$   Úerrr4   r   r   r   Útest_loop_reading_abortedZ   s    
þz6ProactorSocketTransportTests.test_loop_reading_abortedc                 C   s@   t ƒ | jjj_|  ¡ }d|_t ¡ |_	| 
¡  |  |j	j¡ d S ©NT)rK   r   r   r0   rL   r)   Ú_closingr   r   rM   r6   r7   r9   r;   r   r   r   Ú!test_loop_reading_aborted_closingd   s    
z>ProactorSocketTransportTests.test_loop_reading_aborted_closingc                 C   s@   t ƒ | jjj_|  ¡ }d|_t ¡ |_	| 
¡  |  |j	j¡ d S ©NF)rK   r   r   r0   rL   r)   rR   r   r   rM   r6   rH   r9   r;   r   r   r   Ú"test_loop_reading_aborted_is_fatalm   s    
z?ProactorSocketTransportTests.test_loop_reading_aborted_is_fatalc                 C   sZ   t ƒ  }| jjj_|  ¡ }d|_t ¡ |_	t ¡ |_
| ¡  |  |j	j¡ |j
 |¡ d S rT   )ÚConnectionResetErrorr   r   r0   rL   r)   rR   r   r   rM   Ú_force_closer6   r7   r9   r1   rN   r   r   r   Ú!test_loop_reading_conn_reset_lostu   s    

z>ProactorSocketTransportTests.test_loop_reading_conn_reset_lostc                 C   s>   t ƒ  }| jjj_|  ¡ }t ¡ |_| 	¡  |j 
|d¡ d S rJ   )ÚOSErrorr   r   r0   rL   r)   r   r   rM   r6   r1   rN   r   r   r   Útest_loop_reading_exception€   s    
þz8ProactorSocketTransportTests.test_loop_reading_exceptionc                 C   s<   |   ¡ }t ¡ |_| d¡ |  |jd ¡ |jjdd d S )Nr=   )Údata)r)   r   r   Ú_loop_writingÚwriteÚassertEqualÚ_bufferr1   r;   r   r   r   Ú
test_writeŠ   s
    

z'ProactorSocketTransportTests.test_writec                 C   s"   |   ¡ }| d¡ |  |j¡ d S rD   )r)   r]   r7   r_   r;   r   r   r   Útest_write_no_data‘   s    
z/ProactorSocketTransportTests.test_write_no_datac                 C   sF   |   ¡ }t ¡ |_t ¡ |_| d¡ |  |jd¡ |  |jj	¡ d S ©Nr=   )
r)   r   r   Ú
_write_futr\   r]   r^   r_   r7   r9   r;   r   r   r   Útest_write_more–   s    


z,ProactorSocketTransportTests.test_write_morec                 C   sH   |   ¡ }tdƒ|_| ¡  | jjj | jd¡ | jjjj	j
 |j¡ d S rb   )r)   Ú	bytearrayr_   r\   r   r   Úsendr1   r"   Úreturn_valueÚadd_done_callbackr;   r   r   r   Útest_loop_writingž   s    
ÿz.ProactorSocketTransportTests.test_loop_writingúasyncio.proactor_events.loggerc                 C   sš   t ƒ  }| jjj_|  ¡ }t ¡ |_ddg|_	| 
¡  |j |d¡ d|_| d¡ | d¡ | d¡ | d¡ | d¡ |  |j	d ¡ |j d¡ d S )Ns   das   taz#Fatal write error on pipe transporté   r=   zsocket.send() raised exception.)rY   r   r   rf   rL   r)   r   r   rM   r_   r\   r1   Ú
_conn_lostr]   r^   Úwarning)r$   Úm_logrO   r4   r   r   r   Útest_loop_writing_err¦   s"    

þ




z2ProactorSocketTransportTests.test_loop_writing_errc                 C   s<   | j  ¡ }| d¡ |  ¡ }||_| |¡ |  |j¡ d S rb   )r   r+   r>   r)   rc   r\   r-   r2   r   r   r   Útest_loop_writing_stopº   s    


z3ProactorSocketTransportTests.test_loop_writing_stopc                 C   s^   | j  ¡ }| d¡ |  ¡ }||_| ¡  | |¡ |  |j¡ t 	| j ¡ | j
j d ¡ d S ©Nrk   )r   r+   r>   r)   rc   r   r\   r-   r   r,   r    Úconnection_lostr1   r2   r   r   r   Útest_loop_writing_closingÃ   s    


z6ProactorSocketTransportTests.test_loop_writing_closingc                 C   s*   |   ¡ }t ¡ |_| ¡  |j d ¡ d S r   )r)   r   r   rW   Úabortr1   r;   r   r   r   Ú
test_abortÏ   s    
z'ProactorSocketTransportTests.test_abortc                 C   sz   |   ¡ }| ¡  t | j¡ | jj d ¡ |  | 	¡ ¡ |  
|jd¡ | jj ¡  | ¡  t | j¡ |  | jjj¡ d S rq   )r)   r   r   r,   r   r    rr   r1   rH   Ú
is_closingr^   rl   Ú
reset_mockr7   r9   r;   r   r   r   Ú
test_closeÕ   s    z'ProactorSocketTransportTests.test_closec                 C   s:   |   ¡ }t ¡ |_| ¡  t | j¡ |  | j	j
j¡ d S r   )r)   r   r   rc   r   r   r,   r   r7   r    rr   r9   r;   r   r   r   Útest_close_write_futâ   s
    
z1ProactorSocketTransportTests.test_close_write_futc                 C   s8   |   ¡ }dg|_| ¡  t | j¡ |  | jjj	¡ d S rb   )
r)   r_   r   r   r,   r   r7   r    rr   r9   r;   r   r   r   Útest_close_bufferé   s
    z.ProactorSocketTransportTests.test_close_bufferúasyncio.base_events.loggerc                 C   s<   |   ¡ }t ¡ |_| d ¡ |  |jj¡ |  |jj¡ d S r   )r)   r   r   rW   rM   rH   r9   Úerror)r$   Z	m_loggingr4   r   r   r   Útest_fatal_errorð   s
    

z-ProactorSocketTransportTests.test_fatal_errorc                 C   s„   |   ¡ }dg|_t ¡  }|_t ¡  }|_| d ¡ |j ¡  |j ¡  t	 
| j¡ | jj d ¡ |  d |j¡ |  |jd¡ d S )Nr=   rk   )r)   r_   r   r   r?   rc   rW   Úcancelr1   r   r,   r   r    rr   r^   rl   )r$   r4   Zread_futZ	write_futr   r   r   Útest_force_closeø   s    


z-ProactorSocketTransportTests.test_force_closec                 C   sf   t  ¡ }| j |¡ | j ¡ }| d¡ || jj_|  	¡ }| 
d¡ | d ¡ t | j¡ | ¡  d S )Nrk   r=   )r   r   r   Zset_exception_handlerr+   r>   r   rf   rg   r)   r]   rW   r   r,   Úassert_not_called)r$   Zexc_handlerr3   r4   r   r   r   Útest_loop_writing_force_close  s    




z:ProactorSocketTransportTests.test_loop_writing_force_closec                 C   s8   |   ¡ }d|_| d ¡ t | j¡ |  | jjj	¡ d S rQ   )
r)   rR   rW   r   r,   r   r7   r    rr   r9   r;   r   r   r   Útest_force_close_idempotent  s
    
z8ProactorSocketTransportTests.test_force_close_idempotentc                 C   sF   |   ¡ }dg|_| d ¡ t | j¡ | jj d ¡ |  	d |j¡ d S rb   )
r)   r_   rW   r   r,   r   r    rr   r1   r^   r;   r   r   r   Útest_fatal_error_2  s    
z/ProactorSocketTransportTests.test_fatal_error_2c                 C   s6   |   ¡ }| d ¡ |  | jjj¡ |  | jjj¡ d S r   )r)   Z_call_connection_lostrH   r    rr   r9   r"   r   r;   r   r   r   Útest_call_connection_lost#  s    
z6ProactorSocketTransportTests.test_call_connection_lostc                 C   sT   |   ¡ }|  | ¡ ¡ | ¡  | jj tj¡ | ¡  |  	| jjj
d¡ | ¡  d S rq   )r)   rH   Úcan_write_eofÚ	write_eofr"   Úshutdownr1   r!   ÚSHUT_WRr^   Z
call_countr   r;   r   r   r   Útest_write_eof)  s    z+ProactorSocketTransportTests.test_write_eofc                 C   s   |   ¡ }| j ¡ }||jjj_| d¡ | ¡  |  	|j
¡ |  | jjj¡ |jjj | jd¡ | d¡ | j ¡  | jj tj¡ | ¡  d S ©Nr=   é   )r)   r   r+   Ú_loopr   rf   rg   r]   r†   rH   Z_eof_writtenr7   r"   r‡   r9   r1   r>   Ú	_run_oncer!   rˆ   r   ©r$   r4   Úfr   r   r   Útest_write_eof_buffer2  s    



z2ProactorSocketTransportTests.test_write_eof_bufferc                 C   s\   t | j| j| jƒ}|  | ¡ ¡ | ¡  |  | ¡ ¡ | j ¡  |  | jj	j
¡ | 	¡  d S r   )r   r   r"   r    rH   r…   r†   rv   r   r   r9   r;   r   r   r   Útest_write_eof_write_pipe@  s    ÿ
z6ProactorSocketTransportTests.test_write_eof_write_pipec                 C   s¦   t | j| j| jƒ}| j ¡ }||jjj_| 	d¡ | 
¡  |  | ¡ ¡ |  | jjj¡ |jjj | jd¡ | d¡ | j ¡  | j ¡  |  | jjj¡ | ¡  d S rŠ   )r   r   r"   r    r+   rŒ   r   rf   rg   r]   r†   rH   rv   r7   r‡   r9   r1   r>   r   r   rŽ   r   r   r   Ú test_write_eof_buffer_write_pipeJ  s    




z=ProactorSocketTransportTests.test_write_eof_buffer_write_pipec                 C   s^   t | j| j| jƒ}|  | ¡ ¡ |  t¡ | ¡  W d   ƒ n1 sH0    Y  t	|ƒ d S r   )
r   r   r"   r    r7   r…   rF   ÚNotImplementedErrorr†   r   r;   r   r   r   Útest_write_eof_duplex_pipeY  s    ÿ&z7ProactorSocketTransportTests.test_write_eof_duplex_pipec                 C   s˜  |   ¡ }g }dD ]"}| j ¡ }| |¡ | |¡ q|| jjj_| j ¡  |  	|j
¡ |  | ¡ ¡ | j ¡  | jj d¡ | j ¡  | jj d¡ | ¡  | ¡  |  |j
¡ |  	| ¡ ¡ tdƒD ]}| j ¡  qÆ| jj d¡ | ¡  | ¡  |  	|j
¡ |  | ¡ ¡ | j ¡  | jj d¡ | j ¡  | jj d¡ | ¡  | ¡  t ¡ | j_| j ¡  | jj ¡  | jj d¡ | ¡  |  	| ¡ ¡ d S )N)ó   data1ó   data2ó   data3ó   data4ó   data5rE   r•   r–   é
   r—   r˜   r™   )r)   r   r+   r>   Úappendr   r0   rL   r   r7   Z_pausedrH   Z
is_readingr    r8   r1   Zpause_readingÚrangeZresume_readingr   r   Úcall_exception_handlerr€   r   )r$   r4   ÚfuturesÚmsgr   Úir   r   r   Útest_pause_resume_readinga  sJ    







z6ProactorSocketTransportTests.test_pause_resume_readingc                 C   sH   |   ¡ }|j|d |  | ¡ d¡ |  | jjj¡ |  | jjj¡ |S )N©Úhighr   )	r)   Zset_write_buffer_limitsr^   Úget_write_buffer_sizer7   r    Úpause_writingr9   Úresume_writing)r$   r£   r4   r   r   r   Úpause_writing_transportŽ  s    z4ProactorSocketTransportTests.pause_writing_transportc                 C   s~   | j dd}| j ¡ }|| jjj_| d¡ | j ¡  |  | j	j
j¡ | d ¡ | j ¡  |  | ¡ d¡ |  | j	jj¡ d S )Nr‹   r¢   s
   large datar   )r§   r   r+   r   rf   rg   r]   r   rH   r    r¥   r9   r>   r^   r¤   r¦   ©r$   r4   r3   r   r   r   Útest_pause_resume_writing—  s    




z6ProactorSocketTransportTests.test_pause_resume_writingc                 C   sŽ   | j dd}| j ¡ }|| jjj_| d¡ | j ¡  |  | 	¡ d¡ |  
| jjj¡ | d¡ | j ¡  |  | 	¡ d¡ |  | jjj¡ d S )Nr‹   r¢   s   123é   ó   abcé   ©r§   r   r+   r   rf   rg   r]   r   r^   r¤   r7   r    r¥   r9   rH   )r$   r4   Zfut1r   r   r   Útest_pause_writing_2write§  s    




z6ProactorSocketTransportTests.test_pause_writing_2writec                 C   sÂ   | j dd}| j ¡ }|| jjj_| d¡ | j ¡  |  | 	¡ d¡ |  
| jjj¡ | d¡ | j ¡  |  | 	¡ d¡ |  
| jjj¡ | d¡ | j ¡  |  | 	¡ d¡ |  | jjj¡ d S )	Nr‹   r¢   ó   1rk   s   23rª   r«   r¬   r­   r¨   r   r   r   Útest_pause_writing_3write¸  s    






z6ProactorSocketTransportTests.test_pause_writing_3writec                 C   sd   | j dd}| j ¡ }| d ¡ || jjj_| d¡ | j ¡  |  	| 
¡ d¡ |  | jjj¡ d S )Nr‹   r¢   s   very large datar   )r§   r   r+   r>   r   rf   rg   r]   r   r^   r¤   r7   r    r¥   r9   r¨   r   r   r   Útest_dont_pause_writingÏ  s    



z4ProactorSocketTransportTests.test_dont_pause_writing)N)2Ú__name__Ú
__module__Ú__qualname__r   r)   r5   r<   rB   ÚunittestÚskipIfÚsysÚflagsÚoptimizerI   rP   rS   rU   rX   rZ   r`   ra   rd   ri   r   Úpatchro   rp   rs   ru   rx   ry   rz   r}   r   r   r‚   rƒ   r„   r‰   r   r‘   r’   r”   r¡   r§   r©   r®   r°   r±   Ú__classcell__r   r   r%   r   r   !   sT   	



	

	
		
-	r   c                       sÊ   e Zd Z‡ fdd„Zd,dd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Ze d¡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e d)¡d*d+„ ƒZ‡  ZS )-ÚProactorDatagramTransportTestsc                    sT   t ƒ  ¡  |  ¡ | _t ¡ | _| j| j_t 	t
j¡| _tjtjd| _d| jj_d S )N)Zspec_seté   )r   r   r   r   r   r   r   r   r   r   r   ÚDatagramProtocolr    r!   r"   Úfilenorg   r#   r%   r   r   r   ß  s    



z$ProactorDatagramTransportTests.setUpNc                 C   s8   |rd nt | jj_t| j| j| j|d}|  t|¡ |S )N©Úaddress)	rY   r"   ÚgetpeernamerL   r   r   r    r   r   )r$   rÁ   r   r   r   r   Údatagram_transportè  s    
þz1ProactorDatagramTransportTests.datagram_transportc                 C   sB   d}|   ¡ }| |d¡ |  | jjj¡ | jjj| j|dd d S ©Nr=   )ú0.0.0.0iÒ  ©Úaddr)rÃ   ÚsendtorH   r   r9   r1   r"   ©r$   r[   r   r   r   r   Útest_sendtoð  s    ÿz*ProactorDatagramTransportTests.test_sendtoc                 C   sF   t dƒ}|  ¡ }| |d¡ |  | jjj¡ | jjj| jddd d S rÄ   )re   rÃ   rÈ   rH   r   r9   r1   r"   rÉ   r   r   r   Útest_sendto_bytearrayø  s    ÿz4ProactorDatagramTransportTests.test_sendto_bytearrayc                 C   sF   t dƒ}|  ¡ }| |d¡ |  | jjj¡ | jjj| jddd d S rÄ   )Ú
memoryviewrÃ   rÈ   rH   r   r9   r1   r"   rÉ   r   r   r   Útest_sendto_memoryview   s    ÿz5ProactorDatagramTransportTests.test_sendto_memoryviewc                 C   sH   |   ¡ }|j d¡ | dd¡ |  | jjj¡ |  dgt|jƒ¡ d S )N)r=   ©rÅ   i90  rE   r   )	rÃ   r_   r›   rÈ   r7   r"   r9   r^   Úlist©r$   r   r   r   r   Útest_sendto_no_data  s    ÿz2ProactorDatagramTransportTests.test_sendto_no_datac                 C   sR   |   ¡ }|j d¡ tƒ |_| dd¡ |  | jjj¡ |  	ddgt
|jƒ¡ d S )N©r•   rÎ   r–   rÎ   ©r–   rÎ   )rÃ   r_   r›   Úobjectrc   rÈ   r7   r   r9   r^   rÏ   rÐ   r   r   r   Útest_sendto_buffer  s    ÿýz1ProactorDatagramTransportTests.test_sendto_bufferc                 C   sp   t dƒ}|  ¡ }|j d¡ tƒ |_| |d¡ |  | jjj	¡ |  
ddgt|jƒ¡ |  |jd d t¡ d S ©Nr–   rÒ   rÎ   rÓ   rk   r   )re   rÃ   r_   r›   rÔ   rc   rÈ   r7   r   r9   r^   rÏ   ÚassertIsInstanceÚbytes©r$   Zdata2r   r   r   r   Útest_sendto_buffer_bytearray  s    ÿýz;ProactorDatagramTransportTests.test_sendto_buffer_bytearrayc                 C   sp   t dƒ}|  ¡ }|j d¡ tƒ |_| |d¡ |  | jjj	¡ |  
ddgt|jƒ¡ |  |jd d t¡ d S rÖ   )rÌ   rÃ   r_   r›   rÔ   rc   rÈ   r7   r   r9   r^   rÏ   r×   rØ   rÙ   r   r   r   Útest_sendto_buffer_memoryview(  s    ÿýz<ProactorDatagramTransportTests.test_sendto_buffer_memoryviewrj   c                 C   sœ   d}t ƒ  }| jj_|  ¡ }t ¡ |_| |d¡ |  |jj	¡ |j 
|d¡ d|_d|_| |¡ | |¡ | |¡ | |¡ | |¡ |j 
d¡ d S )Nr=   r   ú'Fatal write error on datagram transportrk   )Z123z!socket.sendto() raised exception.)ÚRuntimeErrorr   rÈ   rL   rÃ   r   r   rM   rH   r9   r1   rl   Ú_addressrm   )r$   rn   r[   rO   r   r   r   r   Útest_sendto_exception5  s$    
þ




z4ProactorDatagramTransportTests.test_sendto_exceptionc                 C   sL   d}t | jj_|  ¡ }t ¡ |_| |d¡ |  |j	d¡ |  
|jj¡ d S )Nr=   r   r   )ÚConnectionRefusedErrorr"   rÈ   rL   rÃ   r   r   rM   r^   rl   r7   r9   rÉ   r   r   r   Útest_sendto_error_receivedL  s    

z9ProactorDatagramTransportTests.test_sendto_error_receivedc                 C   sP   d}t | jj_| jdd}t ¡ |_| |¡ |  	|jj
¡ |  | jjj
¡ d S )Nr=   ©rÅ   rk   rÀ   )rà   r   rf   rL   rÃ   r   r   rM   rÈ   r7   r9   rH   r    Úerror_receivedrÉ   r   r   r   Ú$test_sendto_error_received_connectedX  s    


zCProactorDatagramTransportTests.test_sendto_error_received_connectedc                 C   s   |   ¡ }|  t|jdd¡ d S )NÚstrr   )rÃ   rF   Ú	TypeErrorrÈ   rÐ   r   r   r   Útest_sendto_strd  s    z.ProactorDatagramTransportTests.test_sendto_strc                 C   s"   | j dd}|  t|jdd¡ d S )Nrâ   rÀ   s   str)rÅ   é   )rÃ   rF   Ú
ValueErrorrÈ   rÐ   r   r   r   Útest_sendto_connected_addrh  s    
ÿz9ProactorDatagramTransportTests.test_sendto_connected_addrc                 C   s@   | j dd}| ¡  |  |jd¡ | dd¡ |  |jd¡ d S )N)rk   rÀ   rk   r=   rè   )rÃ   r   r^   rl   rÈ   rÐ   r   r   r   Útest_sendto_closingm  s
    z2ProactorDatagramTransportTests.test_sendto_closingc                 C   sL   |   ¡ }d|_| ¡  |  |j¡ t | j¡ | jj	 
¡  | jj 
d ¡ d S rQ   )rÃ   rR   r\   r-   rc   r   r,   r   r"   r   r1   r    rr   rÐ   r   r   r   Útest__loop_writing_closingt  s    z9ProactorDatagramTransportTests.test__loop_writing_closingc                 C   sH   t ƒ  }| jj_|  ¡ }t ¡ |_|j 	d¡ | 
¡  |j |d¡ d S )N©r=   r   rÜ   )rÝ   r   rÈ   rL   rÃ   r   r   rM   r_   r›   r\   r1   )r$   rO   r   r   r   r   Útest__loop_writing_exception}  s    
þz;ProactorDatagramTransportTests.test__loop_writing_exceptionc                 C   sB   t | jj_|  ¡ }t ¡ |_|j 	d¡ | 
¡  |  |jj¡ d S )Nrí   )rà   r   rÈ   rL   rÃ   r   r   rM   r_   r›   r\   r7   r9   rÐ   r   r   r   Ú!test__loop_writing_error_received‰  s    

z@ProactorDatagramTransportTests.test__loop_writing_error_receivedc                 C   sV   t | jj_| jdd}t ¡ |_|j 	d¡ | 
¡  |  |jj¡ |  | jjj¡ d S )Nrâ   rÀ   rí   )rà   r   rf   rL   rÃ   r   r   rM   r_   r›   r\   r7   r9   rH   r    rã   rÐ   r   r   r   Ú,test__loop_writing_error_received_connection“  s    

zKProactorDatagramTransportTests.test__loop_writing_error_received_connectionz asyncio.base_events.logger.errorc                 C   s8   | j dd}tƒ }| |¡ |  | jjj¡ | ¡  d S )Nrâ   rÀ   )rÃ   rà   rM   r7   r    rã   r9   r€   )r$   Zm_excr   rO   r   r   r   Útest_fatal_error_connectedž  s
    
z9ProactorDatagramTransportTests.test_fatal_error_connected)N)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»   r   r   r%   r   r¼   Ý  s,   	

	
r¼   c                       sà   e Zd Z‡ fdd„Ze d¡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e d¡dd„ ƒZdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Ze ejjd'¡d(d)„ ƒZd*d+„ Zd,d-„ Z‡  ZS ).ÚBaseProactorEventLoopTestsc              	      s°   t ƒ  ¡  t ¡ | _t ¡ | _t ¡ t ¡  | _| _	tj
d| j| j	fdF t 
d¡ t| jƒ| _W d   ƒ n1 sx0    Y  W d   ƒ n1 s–0    Y  |  | j¡ d S )Nú)asyncio.proactor_events.socket.socketpair)rg   úsignal.set_wakeup_fd)r   r   r   Zmock_nonblocking_socketr"   r   r   r   ÚssockÚcsockrº   r   r   Úset_event_loopr#   r%   r   r   r   ©  s    



ÿHz BaseProactorEventLoopTests.setUpró   c                 C   s„   t  ¡ t  ¡ f \}}|_t  d¡ t| jƒ}W d   ƒ n1 sD0    Y  |  |j|¡ |  |j|¡ |  	|j
d¡ | ¡  d S )Nrô   rk   )r   r   rg   rº   r   r   ZassertIsÚ_ssockÚ_csockr^   Ú_internal_fdsr   )r$   Ú
socketpairrõ   rö   r   r   r   r   r5   ·  s    ÿ(z$BaseProactorEventLoopTests.test_ctorc                 C   sb   | j  ¡  |  | j jd¡ |  | jjj¡ |  | jjj¡ |  	| j j
¡ |  	| j j¡ d| j _d S )Nr   T)r   Ú_close_self_piper^   rú   rH   rõ   r   r9   rö   r-   rø   rù   Ú_closedr#   r   r   r   Útest_close_self_pipeÂ  s    
z/BaseProactorEventLoopTests.test_close_self_pipec                 C   sn   t  ¡ | j_| j ¡  |  | jjj¡ |  | jjj¡ |  | jj	¡ | jj 
¡  | j ¡  |  | jjj¡ d S r   )r   r   r   rü   r   rH   r9   r   r-   r   rw   r7   r#   r   r   r   rx   Í  s    

z%BaseProactorEventLoopTests.test_closec                 C   s,   | j  | jt ¡ ¡}|  |t¡ t|ƒ d S r   )r   Ú_make_socket_transportr"   r   r   r×   r   r   r;   r   r   r   Útest_make_socket_transportØ  s    z5BaseProactorEventLoopTests.test_make_socket_transportc                 C   s6   | j  ¡  | jj | jd¡ | jjjj | j j¡ d S ©Ni   )r   Ú_loop_self_readingr   r0   r1   rõ   rg   rh   r#   r   r   r   Útest_loop_self_readingÝ  s
    
ÿz1BaseProactorEventLoopTests.test_loop_self_readingc                 C   sV   t  ¡ }|| j_| j |¡ |  |jj¡ | jj	 
| jd¡ | jj	jj 
| jj¡ d S r  )r   r   r   Z_self_reading_futurer  rH   r.   r9   r   r0   r1   rõ   rg   rh   )r$   r3   r   r   r   Útest_loop_self_reading_futã  s    ÿz5BaseProactorEventLoopTests.test_loop_self_reading_futc                 C   s6   t  ¡ | j_tƒ | jj_| j ¡  |  	| jjj
¡ d S r   )r   r   r   r   rY   r   r0   rL   r  rH   r9   r#   r   r   r   Ú test_loop_self_reading_exceptionì  s    
z;BaseProactorEventLoopTests.test_loop_self_reading_exceptionc                 C   s   | j  ¡  | jj d¡ d S )Nó    )r   Z_write_to_selfrö   rf   r1   r#   r   r   r   Útest_write_to_selfò  s    
z-BaseProactorEventLoopTests.test_write_to_selfc                 C   s   | j  g ¡ d S r   )r   Z_process_eventsr#   r   r   r   Útest_process_eventsö  s    z.BaseProactorEventLoopTests.test_process_eventsr{   c                 C   sÚ   t  ¡ }t  ¡  }| j_| j || j¡ |  |j¡ |jd d }|ƒ  | j	j
 | j¡ t  ¡ }t  ¡ t  ¡ f|j_t  ¡  }| j_||ƒ |  |jj¡ |  |j¡ tƒ |j_||ƒ |  | jjj¡ |  |jj¡ d S ©Nr   )r   r   r   Ú	call_soonÚ_start_servingr"   rH   r9   Ú	call_argsr   Úacceptr1   r.   rg   rÿ   rY   rL   r   r|   )r$   rn   Úpfr
  r   r3   Zmake_trr   r   r   Útest_create_serverù  s"    
z-BaseProactorEventLoopTests.test_create_serverc                 C   sd   t  ¡ }t  ¡  }| j_| j || j¡ |jd d }| j ¡ }| ¡  ||ƒ |  	| jj
j¡ d S r	  )r   r   r   r
  r  r"   r  r+   r~   rH   r   r9   )r$   r  r
  r   r3   r   r   r   Útest_create_server_cancel  s    
z4BaseProactorEventLoopTests.test_create_server_cancelc                 C   sŽ   t  ¡ }t  ¡ }t  ¡ }t  ¡ }| ¡ || ¡ |i| j_| j |¡ |  |jj¡ |  |j	j¡ | j
j |¡ |  |jj¡ |  |j	j¡ d S r   )r   r   r¿   r   Z_accept_futuresZ_stop_servingrH   r   r9   r~   r   r1   r7   )r$   Zsock1Zfuture1Zsock2Zfuture2r   r   r   Útest_stop_serving"  s    þz,BaseProactorEventLoopTests.test_stop_servingc                 C   s    t  tj¡| _| j | j| j¡S r   )r   r   r   r¾   r    r   Z_make_datagram_transportr"   r#   r   r   r   rÃ   3  s    z-BaseProactorEventLoopTests.datagram_transportc                 C   s    |   ¡ }|  |t¡ t|ƒ d S r   )rÃ   r×   r   r   r;   r   r   r   Útest_make_datagram_transport7  s    z7BaseProactorEventLoopTests.test_make_datagram_transportc                 C   sV   |   ¡ }|j d¡ | ¡  | jjjj| jddd | jjjj	j
 |j¡ t|ƒ d S )N©r=   ©ú	127.0.0.1i$/  r=   r  rÆ   )rÃ   r_   Ú
appendleftr\   r   r   rÈ   r1   r"   rg   rh   r   r;   r   r   r   Útest_datagram_loop_writing<  s    ÿz5BaseProactorEventLoopTests.test_datagram_loop_writingc                 C   sP   |   ¡ }| ¡  | jjj | jd¡ |  | jj	j
¡ |  | jjj
¡ t|ƒ d S )Né   )rÃ   r6   r   r   Úrecvfromr1   r"   r7   r    Údatagram_receivedr9   rã   r   r;   r   r   r   Útest_datagram_loop_readingF  s    z5BaseProactorEventLoopTests.test_datagram_loop_readingc                 C   s\   | j  ¡ }| d¡ |  ¡ }||_| |¡ | j jj | j	d¡ | j
j dd¡ t|ƒ d S )Nr  r  r=   r  )r   r+   r>   rÃ   r?   r6   r   r  r1   r"   r    r  r   r@   r   r   r   Útest_datagram_loop_reading_dataN  s    


z:BaseProactorEventLoopTests.test_datagram_loop_reading_datarC   c                 C   s‚   | j  ¡ }| d¡ |  ¡ }|  t|j|¡ t ¡ |_	||_
| |¡ |  | j jjj¡ |  | jjj¡ |  |j	j¡ t|ƒ d S )N)rE   r  )r   r+   r>   rÃ   rF   rG   r6   r   r   r   r?   rH   r   r  r9   r7   r    rã   r   r@   r   r   r   Ú"test_datagram_loop_reading_no_dataY  s    



z=BaseProactorEventLoopTests.test_datagram_loop_reading_no_datac                 C   sR   t ƒ  }| jjj_|  ¡ }t ¡ |_t ¡ |j	_
| ¡  |j	j
 |¡ t|ƒ d S r   )rK   r   r   r  rL   rÃ   r   r   rM   Ú	_protocolrã   r6   r1   r   rN   r   r   r   Ú"test_datagram_loop_reading_abortedi  s    
z=BaseProactorEventLoopTests.test_datagram_loop_reading_abortedc                 C   s^   t ƒ  }| jjj_|  ¡ }t ¡ |_t ¡ |j	_
|j d¡ | ¡  |j	j
 |¡ t|ƒ d S )N)s   Hellor  )rK   r   r   rÈ   rL   rÃ   r   r   rM   r  rã   r_   r  r\   r1   r   rN   r   r   r   Ú"test_datagram_loop_writing_aborteds  s    
z=BaseProactorEventLoopTests.test_datagram_loop_writing_aborted) r²   r³   r´   r   r   rº   r5   rþ   rx   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%   r   rò   §  s0   

	



rò   Úwin32z%Proactor is supported on Windows onlyc                       sˆ   e Zd Zdd ZG dd„ dejƒZe‡ fdd„ƒZe‡ fdd„ƒZ	‡ fd	d
„Z
ddd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )Ú&ProactorEventLoopUnixSockSendfileTestss    12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcdeé   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )z.ProactorEventLoopUnixSockSendfileTests.MyProtoc                 C   s(   d| _ d| _tƒ | _| ¡ | _d | _d S rT   )ÚstartedÚclosedre   r[   r+   r3   r   )r$   r   r   r   r   Ú__init__†  s
    
z7ProactorEventLoopUnixSockSendfileTests.MyProto.__init__c                 C   s   d| _ || _d S rQ   )r$  r   rÐ   r   r   r   r/     s    z>ProactorEventLoopUnixSockSendfileTests.MyProto.connection_madec                 C   s   | j  |¡ d S r   )r[   Úextend)r$   r[   r   r   r   r8   ‘  s    z<ProactorEventLoopUnixSockSendfileTests.MyProto.data_receivedc                 C   s   d| _ | j d ¡ d S rQ   )r%  r3   r>   )r$   Úexcr   r   r   rr   ”  s    z>ProactorEventLoopUnixSockSendfileTests.MyProto.connection_lostc                 Ã   s   | j I d H  d S r   )r3   r#   r   r   r   Úwait_closed˜  s    z:ProactorEventLoopUnixSockSendfileTests.MyProto.wait_closedN)r²   r³   r´   r&  r/   r8   rr   r)  r   r   r   r   ÚMyProto„  s
   r*  c                    sF   t tjdƒ}| | j¡ W d   ƒ n1 s.0    Y  tƒ  ¡  d S )NÚwb)Úopenr   ÚTESTFNr]   ÚDATAr   Ú
setUpClass)ÚclsÚfpr%   r   r   r/  ›  s    *z1ProactorEventLoopUnixSockSendfileTests.setUpClassc                    s   t  t j¡ tƒ  ¡  d S r   )r   Úunlinkr-  r   ÚtearDownClass)r0  r%   r   r   r3  ¡  s    z4ProactorEventLoopUnixSockSendfileTests.tearDownClassc                    sN   t  ¡ | _|  | j¡ |  | jj¡ ttjdƒ| _	|  | j	j¡ t
ƒ  ¡  d S )NÚrb)r   ZProactorEventLoopr   r÷   r   r   r,  r   r-  Úfiler   r   r#   r%   r   r   r   ¦  s    
z,ProactorEventLoopUnixSockSendfileTests.setUpTc                 C   sR   t   t jt j¡}| d¡ | t jt jd¡ | t jt jd¡ |rN|  |j	¡ |S )NFr#  )
r!   ÚAF_INETÚSOCK_STREAMÚsetblockingÚ
setsockoptÚ
SOL_SOCKETÚ	SO_SNDBUFÚ	SO_RCVBUFr   r   )r$   Úcleanupr"   r   r   r   Úmake_socket®  s    
z2ProactorEventLoopUnixSockSendfileTests.make_socketc                 C   s   | j  |¡S r   )r   Zrun_until_complete)r$   Úcoror   r   r   Úrun_loop·  s    z/ProactorEventLoopUnixSockSendfileTests.run_loopc                    sŽ   ˆ  ¡ }ˆ ˆj¡‰ t ¡ }ˆj dd}| d|f¡ ˆ ˆjj‡ fdd„|d¡‰ˆ ˆj || 	¡ ¡¡ ‡ ‡‡fdd„}ˆ 
|¡ |ˆ fS )	NF)r=  r  c                      s   ˆ S r   r   r   )Úprotor   r   Ú<lambda>Á  rE   z@ProactorEventLoopUnixSockSendfileTests.prepare.<locals>.<lambda>)r"   c                      s<   ˆ j d ur"ˆ j  ¡  ˆ ˆ  ¡ ¡ ˆ ¡  ˆ ˆ ¡ ¡ d S r   )r   r   r@  r)  r   ©rA  r$   Zserverr   r   r=  Ä  s
    

z?ProactorEventLoopUnixSockSendfileTests.prepare.<locals>.cleanup)r>  r*  r   r	   Zfind_unused_portÚbindr@  Úcreate_serverZsock_connectÚgetsocknamer   )r$   r"   ÚportZsrv_sockr=  r   rC  r   Úprepareº  s    
ÿ

z.ProactorEventLoopUnixSockSendfileTests.preparec              	   C   sn   |   ¡ \}}tƒ }|  tjd¡( |  | j ||dd ¡¡ W d   ƒ n1 sN0    Y  |  | j	 
¡ d¡ d S ©Núnot a regular filer   )rH  rÔ   ÚassertRaisesRegexr   ÚSendfileNotAvailableErrorr@  r   Ú_sock_sendfile_nativer^   r5  Útell©r$   r"   rA  r   r   r   r   Útest_sock_sendfile_not_a_fileÒ  s    ÿÿ$zDProactorEventLoopUnixSockSendfileTests.test_sock_sendfile_not_a_filec              	   C   sp   |   ¡ \}}t ¡ }|  tjd¡( |  | j ||dd ¡¡ W d   ƒ n1 sP0    Y  |  	| j
 ¡ d¡ d S rI  )rH  ÚioÚBytesIOrK  r   rL  r@  r   rM  r^   r5  rN  rO  r   r   r   Útest_sock_sendfile_iobufferÛ  s    ÿÿ$zBProactorEventLoopUnixSockSendfileTests.test_sock_sendfile_iobufferc              	   C   sx   |   ¡ \}}t ¡ }d|j_|  tjd¡( |  | j	 
||dd ¡¡ W d   ƒ n1 sX0    Y  |  | j ¡ d¡ d S )NéÿÿÿÿrJ  r   )rH  r   r   r¿   rg   rK  r   rL  r@  r   rM  r^   r5  rN  rO  r   r   r   Ú#test_sock_sendfile_not_regular_fileä  s    ÿÿ$zJProactorEventLoopUnixSockSendfileTests.test_sock_sendfile_not_regular_file)T)r²   r³   r´   r.  r   r   r*  Úclassmethodr/  r3  r   r>  r@  rH  rP  rS  rU  r»   r   r   r%   r   r"    s   
			r"  Ú__main__)Ú__doc__rQ  r!   rµ   r·   r   r   Zasyncio.proactor_eventsr   r   r   r   r   Útestr   Ztest.supportr	   Ztest.test_asyncior
   r   r   r   ZTestCaser   r¼   rò   r¶   Úplatformr"  r²   Úmainr   r   r   r   Ú<module>   s<   	   ? K Yÿn
