
    dafv                        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 Zd Z G d dej*                        Z G d dej*                        Z G d dej*                        Z ej2                  ej4                  dk7  d       G d dej*                               Zedk(  r ej:                          yy)zTests for proactor_events.py    N)mock)BaseProactorEventLoop)_ProactorSocketTransport)_ProactorWritePipeTransport)_ProactorDuplexPipeTransport)_ProactorDatagramTransport)	os_helper)socket_helper)utilsc                  .    t        j                  d        y N)asyncioset_event_loop_policy     A/root/Python-3.12.4/Lib/test/test_asyncio/test_proactor_events.pytearDownModuler      s    !!$'r   c                 `    | j                   y | j                   j                          d | _         y r   )_sockclose)	transports    r   close_transportr      s(     OOIOr   c                       e Zd Z fdZd/dZd Zd Zd Z ej                  e
j                  j                  d      d        Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Z ej0                  d      d        Zd Zd Zd Zd Zd Zd Zd Z  ej0                  d      d        Z!d Z"d Z#d Z$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,d' Z-d( Z.d) Z/d* Z0d+ Z1d, Z2d- Z3d. Z4 xZ5S )0ProactorSocketTransportTestsc                    t         |           | j                         | _        | j	                  | j                  j
                         t        j                         | _        | j                  | j                  _	        t        j                  t        j                        | _        t        j                  t        j                        | _        d| _        y )Ni   )supersetUpnew_test_looploop
addCleanupr   r   Mockproactor	_proactor
test_utilsmake_test_protocolr   Protocolprotocolsocketsockbuffer_sizeself	__class__s    r   r   z"ProactorSocketTransportTests.setUp#   s    &&(			(		"mm		"55g6F6FGIIfmm,	 r   c                     t        | j                  | j                  | j                  |      }| j	                  t
        |       |S N)waiter)r   r   r)   r'   r    r   )r,   r0   r   s      r   socket_transportz-ProactorSocketTransportTests.socket_transport-   s6    ,TYY		-1]]6K	3r   c                    | j                   j                         }| j                  |      }t        j                  | j                          | j                  |j                                | j                  j                  |       | j                  j                  j                  | j                  t        | j                               y r/   )r   create_futurer1   r$   run_brieflyassertIsNoneresultr'   connection_mader"   	recv_intoassert_called_withr)   	bytearrayr*   r,   futtrs      r   	test_ctorz&ProactorSocketTransportTests.test_ctor3   s    ii%%'""#".tyy)#**,'%%b)22499iHXHX>YZr   c                    | j                         }|j                          | j                  j                  j                  j                  | j                  t        | j                               | j                  | j                  j                  j                         | j                  | j                  j                  j                         y r   )r1   _loop_readingr   r#   r8   r9   r)   r:   r*   assertFalser'   data_receivedcalledeof_receivedr,   r=   s     r   test_loop_readingz.ProactorSocketTransportTests.test_loop_reading;   s    ""$
		%%88IdN^N^D_`44;;<33::;r   c                 v   d}| j                   j                         }|j                  t        |             | j	                         }||_        ||j                  d t        |       |j                  |       t        | j                        }||d t        |       | j                   j                  j                  j                  | j                  |       | j                  j                  j                  |       | j!                  | j                  j                  j"                  j$                  d   t&               y )N   datar   )r   r3   
set_resultlenr1   	_read_fut_datar@   r:   r*   r#   r8   r9   r)   r'   rB   assertIsInstance	call_argsargsbytes)r,   bufresr=   
called_bufs        r   test_loop_reading_dataz3ProactorSocketTransportTests.test_loop_reading_dataB   s    ii%%'s3x ""$!#c(
t//0
 #
9CH		%%88JO##66s; 	dmm99CCHHKUSr   )Assertions are disabled in optimized modec                 8   | j                   j                         }|j                  d       | j                         }| j	                  t
        |j                  |       t        j                         |_	        ||_
        |j                  |       | j                  | j                   j                  j                  j                         | j                  | j                   j"                  j                         | j                  |j                  j                         y Nr   )r   r3   rI   r1   assertRaisesAssertionErrorr@   r   r!   r   rK   rA   r#   r8   rC   
assertTruer'   rD   r,   rR   r=   s      r   test_loop_reading_no_dataz6ProactorSocketTransportTests.test_loop_reading_no_dataS   s    ii%%'q""$."*:*:C@99;
,,66==>2299:(r   c                    t               x}| j                  j                  j                  _        | j                         }t        j                         |_        |j                          |j                  j                  |d       y Nz"Fatal read error on pipe transport)ConnectionAbortedErrorr   r#   r8   side_effectr1   r   r!   _fatal_errorr@   r9   r,   errr=   s      r   test_loop_reading_abortedz6ProactorSocketTransportTests.test_loop_reading_abortedb   sb    :P:RRdii!!++7""$))+

**@	Br   c                 (   t               | j                  j                  j                  _        | j                         }d|_        t        j                         |_	        |j                          | j                  |j                  j                         y NT)r_   r   r#   r8   r`   r1   _closingr   r!   ra   r@   rA   rC   rE   s     r   !test_loop_reading_aborted_closingz>ProactorSocketTransportTests.test_loop_reading_aborted_closingl   sc    4J4L		%%1""$))+
//0r   c                 (   t               | j                  j                  j                  _        | j                         }d|_        t        j                         |_	        |j                          | j                  |j                  j                         y NF)r_   r   r#   r8   r`   r1   rg   r   r!   ra   r@   rZ   rC   rE   s     r   "test_loop_reading_aborted_is_fatalz?ProactorSocketTransportTests.test_loop_reading_aborted_is_fatalu   sa    4J4L		%%1""$))+
../r   c                    t               x}| j                  j                  j                  _        | j                         }d|_        t        j                         |_	        t        j                         |_
        |j                          | j                  |j                  j                         |j                  j                  |       y rj   )ConnectionResetErrorr   r#   r8   r`   r1   rg   r   r!   ra   _force_closer@   rA   rC   r9   rb   s      r   !test_loop_reading_conn_reset_lostz>ProactorSocketTransportTests.test_loop_reading_conn_reset_lost}   s    :N:PPdii!!++7""$))+))+
//0
**3/r   c                    t               x}| j                  j                  j                  _        | j                         }t        j                         |_        |j                          |j                  j                  |d       y r^   )OSErrorr   r#   r8   r`   r1   r   r!   ra   r@   r9   rb   s      r   test_loop_reading_exceptionz8ProactorSocketTransportTests.test_loop_reading_exception   sa    ;B9Edii!!++7""$))+

**@	Br   c                     | j                         }t        j                         |_        |j	                  d       | j                  |j                  d        |j                  j                  d       y )NrH   )data)r1   r   r!   _loop_writingwriteassertEqual_bufferr9   rE   s     r   
test_writez'ProactorSocketTransportTests.test_write   sU    ""$99;
T*
+++9r   c                 |    | j                         }|j                  d       | j                  |j                         y )Nr   )r1   rv   rA   rx   rE   s     r   test_write_no_dataz/ProactorSocketTransportTests.test_write_no_data   s-    ""$
$r   c                 ,   | j                         }t        j                         |_        t        j                         |_        |j                  d       | j                  |j                  d       | j                  |j                  j                         y NrH   )
r1   r   r!   
_write_futru   rv   rw   rx   rA   rC   rE   s     r   test_write_morez,ProactorSocketTransportTests.test_write_more   se    ""$		99;
W-))001r   c                 r   | j                         }t        d      |_        |j                          | j                  j
                  j                  j                  | j                  d       | j                  j
                  j                  j                  j                  j                  |j                         y r}   )r1   r:   rx   ru   r   r#   sendr9   r)   return_valueadd_done_callbackrE   s     r   test_loop_writingz.ProactorSocketTransportTests.test_loop_writing   s|    ""$w'

		  33DIIwG		  --??r//0r   asyncio.proactor_events.loggerc                 D   t               x}| j                  j                  j                  _        | j                         }t        j                         |_        ddg|_	        |j                          |j                  j                  |d       d|_        |j                  d       |j                  d       |j                  d       |j                  d       |j                  d       | j                  |j                  d        |j                  j                  d       y )Ns   das   taz#Fatal write error on pipe transport   rH   zsocket.send() raised exception.)rq   r   r#   r   r`   r1   r   r!   ra   rx   ru   r9   
_conn_lostrv   rw   warning)r,   m_logrc   r=   s       r   test_loop_writing_errz2ProactorSocketTransportTests.test_loop_writing_err   s    5<Y>dii!!&&2""$))+U^


**A	C 




T*(()JKr   c                     | j                   j                         }|j                  d       | j                         }||_        |j                  |       | j                  |j                         y r}   )r   r3   rI   r1   r~   ru   r5   r;   s      r   test_loop_writing_stopz3ProactorSocketTransportTests.test_loop_writing_stop   sU    ii%%'w""$
"--(r   c                    | j                   j                         }|j                  d       | j                         }||_        |j                          |j                  |       | j                  |j                         t        j                  | j                          | j                  j                  j                  d        y Nr   )r   r3   rI   r1   r~   r   ru   r5   r$   r4   r'   connection_lostr9   r;   s      r   test_loop_writing_closingz6ProactorSocketTransportTests.test_loop_writing_closing   s    ii%%'q""$


"--(tyy)%%88>r   c                     | j                         }t        j                         |_        |j	                          |j                  j                  d        y r   )r1   r   r!   rn   abortr9   rE   s     r   
test_abortz'ProactorSocketTransportTests.test_abort   s8    ""$))+


**40r   c                 F   | j                         }|j                          t        j                  | j                         | j
                  j                  j                  d        | j                  |j                                | j                  |j                  d       | j
                  j                  j                          |j                          t        j                  | j                         | j                  | j
                  j                  j                         y r   )r1   r   r$   r4   r   r'   r   r9   rZ   
is_closingrw   r   
reset_mockrA   rC   rE   s     r   
test_closez'ProactorSocketTransportTests.test_close   s    ""$

tyy)%%88>(*%%002

tyy)66==>r   c                    | j                         }t        j                         |_        |j	                          t        j                  | j                         | j                  | j                  j                  j                         y r   )r1   r   r!   r~   r   r$   r4   r   rA   r'   r   rC   rE   s     r   test_close_write_futz1ProactorSocketTransportTests.test_close_write_fut   sV    ""$		

tyy)66==>r   c                     | j                         }dg|_        |j                          t        j                  | j
                         | j                  | j                  j                  j                         y r}   )
r1   rx   r   r$   r4   r   rA   r'   r   rC   rE   s     r   test_close_bufferz.ProactorSocketTransportTests.test_close_buffer   sR    ""$Y


tyy)66==>r   c                 `   | j                         }d| j                  j                  _        |j	                          t        j                  | j                         | j                  j                  j                  d        | j                  | j                  j                  j                         y )N)r1   r)   filenor   r   r$   r4   r   r'   r   r9   rA   shutdownrC   rE   s     r   test_close_invalid_sockobjz7ProactorSocketTransportTests.test_close_invalid_sockobj   ss    ""$(*		%

tyy)%%88>++223r   asyncio.base_events.loggerc                    | j                         }t        j                         |_        |j	                  d        | j                  |j                  j                         | j                  |j                  j                         y r   )r1   r   r!   rn   ra   rZ   rC   error)r,   	m_loggingr=   s      r   test_fatal_errorz-ProactorSocketTransportTests.test_fatal_error   sU    ""$))+
../	../r   c                 "   | j                         }dg|_        t        j                         x}|_        t        j                         x}|_        |j                  d        |j                  j                          |j                  j                          t        j                  | j                         | j                  j                  j                  d        | j                  d |j                         | j                  |j                  d       y )NrH   r   )r1   rx   r   r!   rK   r~   rn   cancelr9   r$   r4   r   r'   r   rw   r   )r,   r=   read_fut	write_futs       r   test_force_closez-ProactorSocketTransportTests.test_force_close  s    ""$Y
"&))+-2<$(IIK/	BM
**,++-tyy)%%88>rzz**r   c                    t        j                         }| j                  j                  |       | j                  j	                         }|j                  d       || j                  j                  _        | j                         }|j                  d       |j                  d        t        j                  | j                         |j                          y )Nr   rH   )r   r!   r   set_exception_handlerr3   rI   r"   r   r   r1   rv   rn   r$   r4   assert_not_called)r,   exc_handlerr<   r=   s       r   test_loop_writing_force_closez:ProactorSocketTransportTests.test_loop_writing_force_close  s    iik		''4ii%%'q*-'""$

tyy)%%'r   c                     | j                         }d|_        |j                  d        t        j                  | j
                         | j                  | j                  j                  j                         y rf   )
r1   rg   rn   r$   r4   r   rZ   r'   r   rC   rE   s     r   test_force_close_idempotentz8ProactorSocketTransportTests.test_force_close_idempotent#  sS    ""$
tyy) 	55<<=r   c                 r   | j                         }| j                  | j                  j                  j                         d|_        |j                  d        |j                  d        t        j                  | j                         | j                  d| j                  j                  j                         y )NTr   )r1   rA   r'   r   rC   rg   rn   r$   r4   r   rw   
call_countrE   s     r   .test_force_close_protocol_connection_lost_oncezKProactorSocketTransportTests.test_force_close_protocol_connection_lost_once/  s    ""$66==> 	
tyy)DMM99DDEr   c                 `   | j                         }| j                  | j                  j                  j                         |j                          |j                          t        j                  | j                         | j                  d| j                  j                  j                         y r   )r1   rA   r'   r   rC   r   r$   r4   r   rw   r   rE   s     r   (test_close_protocol_connection_lost_oncezEProactorSocketTransportTests.test_close_protocol_connection_lost_once:  st    ""$66==> 	


tyy)DMM99DDEr   c                    | j                         }dg|_        |j                  d        t        j                  | j
                         | j                  j                  j                  d        | j                  d |j                         y r}   )
r1   rx   rn   r$   r4   r   r'   r   r9   rw   rE   s     r   test_fatal_error_2z/ProactorSocketTransportTests.test_fatal_error_2D  sc    ""$Y

tyy)%%88>rzz*r   c                    | j                         }|j                  d        | j                  | j                  j                  j
                         | j                  | j                  j                  j
                         y r   )r1   _call_connection_lostrZ   r'   r   rC   r)   r   rE   s     r   test_call_connection_lostz6ProactorSocketTransportTests.test_call_connection_lostM  sT    ""$
  &55<<=		../r   c                    | j                         }| j                  |j                                |j                          | j                  j
                  j                  t        j                         |j                          | j                  | j                  j
                  j                  d       |j                          y r   )r1   rZ   can_write_eof	write_eofr)   r   r9   r(   SHUT_WRrw   r   r   rE   s     r   test_write_eofz+ProactorSocketTransportTests.test_write_eofS  s|    ""$((*+
		--fnn=
++66:

r   c                    | j                         }| j                  j                         }||j                  j                  j
                  _        |j                  d       |j                          | j                  |j                         | j                  | j                  j                  j                         |j                  j                  j
                  j                  | j                  d       |j!                  d       | j                  j#                          | j                  j                  j                  t$        j&                         |j)                          y NrH      )r1   r   r3   _loopr#   r   r   rv   r   rZ   _eof_writtenrA   r)   r   rC   r9   rI   	_run_oncer(   r   r   r,   r=   fs      r   test_write_eof_bufferz2ProactorSocketTransportTests.test_write_eof_buffer\  s    ""$II##%/0,

(++223
22499gF	Q				--fnn=

r   c                    t        | j                  | j                  | j                        }| j	                  |j                                |j                          | j	                  |j                                | j                  j                          | j	                  | j                  j                  j                         |j                          y r   )r   r   r)   r'   rZ   r   r   r   r   r   rC   rE   s     r   test_write_eof_write_pipez6ProactorSocketTransportTests.test_write_eof_write_pipej  s    (IItyy$--1((*+
(				../

r   c                 2   t        | j                  | j                  | j                        }| j                  j	                         }||j
                  j                  j                  _        |j                  d       |j                          | j                  |j                                | j                  | j                  j                  j                         |j
                  j                  j                  j!                  | j                  d       |j#                  d       | j                  j%                          | j                  j%                          | j                  | j                  j&                  j                         |j'                          y r   )r   r   r)   r'   r3   r   r#   r   r   rv   r   rZ   r   rA   r   rC   r9   rI   r   r   r   s      r    test_write_eof_buffer_write_pipez=ProactorSocketTransportTests.test_write_eof_buffer_write_pipet  s    (DIIt}}MII##%/0,

(++223
22499gF	Q						../

r   c                 "   t        | j                  | j                  | j                        }| j	                  |j                                | j                  t              5  |j                          d d d        t        |       y # 1 sw Y   xY wr   )
r   r   r)   r'   rA   r   rX   NotImplementedErrorr   r   rE   s     r   test_write_eof_duplex_pipez7ProactorSocketTransportTests.test_write_eof_duplex_pipe  sk    )IItyy$--1))+,23 	LLN		 	s    BBc                      j                         }d}g d}t        t        |             fd}| j                  j                  j
                  _         j                  j                           j                  |j                          j                  |j                                |d d D ]J  } j                  j                           j                  j                  j                  t        |             L |j!                          |j!                           j                  |j                          j                  |j                                t#        d      D ]  } j                  j                            j                  j                  j                  t        |d                |j%                          |j%                           j                  |j                          j                  |j                                |dd D ]J  } j                  j                           j                  j                  j                  t        |             L |j!                          |j%                          t'        j(                          j                  _         j                  j                           j                  j*                  j-                           j                  j                  j                  t        |d                |j/                           j                  |j                                y )Nr   )   data1   data2s   data3s   data4s   data5r   c                     j                   j                         }j                         |j                  fd}||_        |j	                  t                     |S )Nc                  .     d t                       S r   )rJ   )rt   msgr6   s   r   monkeyzYProactorSocketTransportTests.test_pause_resume_reading.<locals>.recv_into.<locals>.monkey  s    "%Yc#hxr   )r   r3   popr6   rI   rJ   )r)   rt   r   r   r   r6   reversed_msgsr,   s    `  @@r   r8   zIProactorSocketTransportTests.test_pause_resume_reading.<locals>.recv_into  sO    		'')A##%CXXF  AHLLS"Hr      
   r   r   )r1   listreversedr   r#   r8   r`   r   rA   _pausedrZ   
is_readingr'   rB   r9   r:   pause_readingrangeresume_readingr   r!   call_exception_handlerr   r   )r,   r=   indexmsgsr8   r   ir   s   `      @r   test_pause_resume_readingz6ProactorSocketTransportTests.test_pause_resume_reading  sP   ""$FXd^,	 5>		%%1		$(8 	KCII!MM''::9S>J	K 	


#)r 	"AII!	"##66ya7IJ

$(!9 	KCII!MM''::9S>J	K 	
+/99;		(				((::<##66ya7IJ

)r   c                    | j                         fd| j                  j                  _        t	        j
                  | j                         | j                  j                                | j                  j                  d       j                          | j                  j                                j                          | j                  j                                y )Nc                 $    j                         S r   )r   )_r=   s    r   <lambda>zQProactorSocketTransportTests.test_pause_reading_connection_made.<locals>.<lambda>  s    b>N>N>P r      )r1   r'   r7   r`   r$   r4   r   rA   r   assert_no_readerr   rZ   r   rE   s    @r   "test_pause_reading_connection_madez?ProactorSocketTransportTests.test_pause_reading_connection_made  s    ""$4P%%1tyy))		""1%
(

)r   c                 F   | j                         }|j                  |       | j                  |j                         d       | j	                  | j
                  j                  j                         | j	                  | j
                  j                  j                         |S )Nhighr   )	r1   set_write_buffer_limitsrw   get_write_buffer_sizerA   r'   pause_writingrC   resume_writing)r,   r   r=   s      r   pause_writing_transportz4ProactorSocketTransportTests.pause_writing_transport  s{    ""$
"""-113Q744;;<55<<=	r   c                 N   | j                  d      }| j                  j                         }|| j                  j                  j                  _        |j                  d       | j                  j                          | j                  | j                  j                  j                         |j                  d        | j                  j                          | j                  |j                         d       | j                  | j                  j                  j                         y )Nr   r   s
   large datar   )r   r   r3   r#   r   r   rv   r   rZ   r'   r   rC   rI   rw   r   r   r,   r=   r<   s      r   test_pause_resume_writingz6ProactorSocketTransportTests.test_pause_resume_writing  s    ))q)1 ii%%'03		  -
		33::; 	t		113Q744;;<r   c                    | j                  d      }| j                  j                         }|| j                  j                  j                  _        |j                  d       | j                  j                          | j                  |j                         d       | j                  | j                  j                  j                         |j                  d       | j                  j                          | j                  |j                         d       | j                  | j                  j                  j                         y )Nr   r   s   123      abc   r   r   r3   r#   r   r   rv   r   rw   r   rA   r'   r   rC   rZ   )r,   r=   fut1s      r   test_pause_writing_2writez6ProactorSocketTransportTests.test_pause_writing_2write  s    ))q)1 yy&&(04		  -
		113Q744;;< 			113Q733::;r   c                    | j                  d      }| j                  j                         }|| j                  j                  j                  _        |j                  d       | j                  j                          | j                  |j                         d       | j                  | j                  j                  j                         |j                  d       | j                  j                          | j                  |j                         d       | j                  | j                  j                  j                         |j                  d       | j                  j                          | j                  |j                         d       | j                  | j                  j                  j                         y )	Nr   r      1r   s   23r   r   r   r   r   s      r   test_pause_writing_3writez6ProactorSocketTransportTests.test_pause_writing_3write  s:   ))q)1 ii%%'03		  -
		113Q744;;< 			113Q744;;< 			113Q733::;r   c                    | j                  d      }| j                  j                         }|j                  d        || j                  j                  j
                  _        |j                  d       | j                  j                          | j                  |j                         d       | j                  | j                  j                  j                         y )Nr   r   s   very large datar   )r   r   r3   rI   r#   r   r   rv   r   rw   r   rA   r'   r   rC   r   s      r   test_dont_pause_writingz4ProactorSocketTransportTests.test_dont_pause_writing  s    ))q)1 ii%%'t03		  -
#$		113Q744;;<r   r   )6__name__
__module____qualname__r   r1   r>   rF   rT   unittestskipIfsysflagsoptimizer\   rd   rh   rk   ro   rr   ry   r{   r   r   r   patchr   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  __classcell__r-   s   @r   r   r   !   sA   ![<T" X__SYY'')TU) V)B10	0B:%
21 TZZ01L 2L&)
?1???4 TZZ,-0 .0+(
>	FF+05*n*= <"<.=r   r   c                        e Zd Z fdZddZd Zd Zd Zd Zd Z	d Z
d	 Z ej                  d
      d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ej                  d      d        Z xZS )ProactorDatagramTransportTestsc                    t         |           | j                         | _        t	        j
                         | _        | j                  | j                  _        t        j                  t        j                        | _        t	        j
                  t        j                        | _        d| j                  j                  _        y )N)spec_setr   )r   r   r   r   r   r!   r"   r#   r$   r%   r   DatagramProtocolr'   r(   r)   r   r   r+   s    r   r   z$ProactorDatagramTransportTests.setUp!  sw    &&(			"mm		"55g6N6NOIIv}}5	()		%r   c                     |rd nt         | j                  j                  _        t	        | j
                  | j                  | j                  |      }| j                  t        |       |S )Naddress)	rq   r)   getpeernamer`   r   r   r'   r    r   )r,   r  r   s      r   datagram_transportz1ProactorDatagramTransportTests.datagram_transport*  sO    4;D		).tyy$))/3}}7>@	 	3r   c                    d}| j                         }|j                  |d       | j                  | j                  j                  j                         | j                  j                  j                  | j                  |d       y NrH   )0.0.0.0i  addr)r  sendtorZ   r"   rC   r9   r)   r,   rt   r   s      r   test_sendtoz*ProactorDatagramTransportTests.test_sendto2  sk    ++-	01,,334//IIt"3 	0 	5r   c                     t        d      }| j                         }|j                  |d       | j                  | j                  j                  j
                         | j                  j                  j                  | j                  dd       y r  )r:   r  r!  rZ   r"   rC   r9   r)   r"  s      r   test_sendto_bytearrayz4ProactorDatagramTransportTests.test_sendto_bytearray:  sp    !++-	01,,334//IIw%6 	0 	8r   c                     t        d      }| j                         }|j                  |d       | j                  | j                  j                  j
                         | j                  j                  j                  | j                  dd       y r  )
memoryviewr  r!  rZ   r"   rC   r9   r)   r"  s      r   test_sendto_memoryviewz5ProactorDatagramTransportTests.test_sendto_memoryviewB  sp    '"++-	01,,334//IIw%6 	0 	8r   c                 (   | j                         }|j                  j                  d       |j                  dd       | j	                  | j
                  j                  j                         | j                  dgt        |j                               y )N)rH   r  i90  r   r   )	r  rx   appendr!  rA   r)   rC   rw   r   r,   r   s     r   test_sendto_no_dataz2ProactorDatagramTransportTests.test_sendto_no_dataJ  su    ++-	  !>?b!))001*+T)2C2C-D	Fr   c                 H   | j                         }|j                  j                  d       t               |_        |j                  dd       | j                  | j                  j
                  j                         | j                  ddgt        |j                               y )Nr   r*  r   r*  r   r*  )r  rx   r+  objectr~   r!  rA   r"   rC   rw   r   r,  s     r   test_sendto_bufferz1ProactorDatagramTransportTests.test_sendto_bufferR  s    ++-	  !?@%x	#56--445++-""#	%r   c                    t        d      }| j                         }|j                  j                  d       t	               |_        |j                  |d       | j                  | j                  j                  j                         | j                  ddgt        |j                               | j                  |j                  d   d   t               y Nr   r/  r*  r0  r   r   )r:   r  rx   r+  r1  r~   r!  rA   r"   rC   rw   r   rM   rP   r,   data2r   s      r   test_sendto_buffer_bytearrayz;ProactorDatagramTransportTests.test_sendto_buffer_bytearray]  s    (#++-	  !?@%x	 23--445++-""#	% 	i//215u=r   c                    t        d      }| j                         }|j                  j                  d       t	               |_        |j                  |d       | j                  | j                  j                  j                         | j                  ddgt        |j                               | j                  |j                  d   d   t               y r4  )r'  r  rx   r+  r1  r~   r!  rA   r"   rC   rw   r   rM   rP   r5  s      r   test_sendto_buffer_memoryviewz<ProactorDatagramTransportTests.test_sendto_buffer_memoryviewj  s    8$++-	  !?@%x	 23--445++-""#	% 	i//215u=r   r   c                 F   d}t               x}| j                  j                  _        | j	                         }t        j                         |_        |j                  |d       | j                  |j                  j                         |j                  j                  |d       d|_        d|_        |j                  |       |j                  |       |j                  |       |j                  |       |j                  |       |j                  j                  d       y )NrH   r   'Fatal write error on datagram transportr   )123z!socket.sendto() raised exception.)RuntimeErrorr"   r!  r`   r  r   r!   ra   rZ   rC   r9   r   _addressr   )r,   r   rt   rc   r   s        r   test_sendto_exceptionz4ProactorDatagramTransportTests.test_sendto_exceptionw  s    1=?dmm"".++-	!%	r"	..55611#&#L	N  !	%	(()LMr   c                 >   d}t         | j                  j                  _        | j	                         }t        j                         |_        |j                  |d       | j                  |j                  d       | j                  |j                  j                         y )NrH   r   r   )ConnectionRefusedErrorr)   r!  r`   r  r   r!   ra   rw   r   rA   rC   r"  s      r   test_sendto_error_receivedz9ProactorDatagramTransportTests.test_sendto_error_received  su    '=		$++-	!%	r"--q1//667r   c                 f   d}t         | j                  j                  _        | j	                  d      }t        j                         |_        |j                  |       | j                  |j                  j                         | j                  | j                  j                  j                         y )NrH   r  r   r  )rA  r"   r   r`   r  r   r!   ra   r!  rA   rC   rZ   r'   error_receivedr"  s      r   $test_sendto_error_received_connectedzCProactorDatagramTransportTests.test_sendto_error_received_connected  s~    )?&++N+C	!%	//66744;;<r   c                 h    | j                         }| j                  t        |j                  dd       y )Nstrr   )r  rX   	TypeErrorr!  r,  s     r   test_sendto_strz.ProactorDatagramTransportTests.test_sendto_str  s*    ++-	)Y%5%5ubAr   c                 l    | j                  d      }| j                  t        |j                  dd       y )NrD  r  s   str)r  r   )r  rX   
ValueErrorr!  r,  s     r   test_sendto_connected_addrz9ProactorDatagramTransportTests.test_sendto_connected_addr  s3    ++N+C		((&.	Br   c                     | j                  d      }|j                          | j                  |j                  d       |j	                  dd       | j                  |j                  d       y )N)r   r  r   rH   r   )r  r   rw   r   r!  r,  s     r   test_sendto_closingz2ProactorDatagramTransportTests.test_sendto_closing  s[    ++D+9	--q1$'--q1r   c                 X   | j                         }d|_        |j                          | j                  |j                         t        j                  | j                         | j                  j                  j                          | j                  j                  j                  d        y rf   )r  rg   ru   r5   r~   r$   r4   r   r)   r   r9   r'   r   r,  s     r   test__loop_writing_closingz9ProactorDatagramTransportTests.test__loop_writing_closing  sv    ++-	!	!)../tyy)		**,%%88>r   c                 .   t               x}| j                  j                  _        | j	                         }t        j                         |_        |j                  j                  d       |j                          |j                  j                  |d       y )NrH   r   r;  )r=  r"   r!  r`   r  r   r!   ra   rx   r+  ru   r9   )r,   rc   r   s      r   test__loop_writing_exceptionz;ProactorDatagramTransportTests.test__loop_writing_exception  sr    1=?dmm"".++-	!%	  /!11#&#L	Nr   c                 4   t         | j                  j                  _        | j	                         }t        j                         |_        |j                  j                  d       |j                          | j                  |j                  j                         y )NrS  )rA  r"   r!  r`   r  r   r!   ra   rx   r+  ru   rA   rC   r,  s     r   !test__loop_writing_error_receivedz@ProactorDatagramTransportTests.test__loop_writing_error_received  sj    +A(++-	!%	  /!//667r   c                    t         | j                  j                  _        | j	                  d      }t        j                         |_        |j                  j                  d       |j                          | j                  |j                  j                         | j                  | j                  j                  j                         y )NrD  r  rS  )rA  r"   r   r`   r  r   r!   ra   rx   r+  ru   rA   rC   rZ   r'   rE  r,  s     r   ,test__loop_writing_error_received_connectionzKProactorDatagramTransportTests.test__loop_writing_error_received_connection  s    )?&++N+C	!%	  /!//66744;;<r   z asyncio.base_events.logger.errorc                     | j                  d      }t               }|j                  |       | j                  | j                  j
                  j                         |j                          y )NrD  r  )r  rA  ra   rA   r'   rE  rC   r   )r,   m_excr   rc   s       r   test_fatal_error_connectedz9ProactorDatagramTransportTests.test_fatal_error_connected  sU    ++N+C	$&s#55<<=!r   r   )r  r  r	  r   r  r#  r%  r(  r-  r2  r7  r9  r   r  r?  rB  rF  rJ  rM  rO  rQ  rT  rV  rX  r[  r  r  s   @r   r  r    s    *588F	%>> TZZ01N 2N,
8
=BB
2?
N8	= TZZ23" 4"r   r  c                   >    e Zd Z fdZ ej
                  d      d        Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Z ej
                  d      d        Zd Zd Zd Zd Zd Zd Zd Z ej0                  ej4                  j6                  d      d        Zd Zd Z xZS )BaseProactorEventLoopTestsc                 .   t         |           t        j                         | _        t        j                         | _        t        j                         t        j                         c| _        | _	        t        j                  d| j                  | j                  f      5  t        j                  d      5  t        | j                        | _        d d d        d d d        | j                  | j                         y # 1 sw Y   -xY w# 1 sw Y   1xY w)N)asyncio.proactor_events.socket.socketpair)r   signal.set_wakeup_fd)r   r   r$   mock_nonblocking_socketr)   r   r!   r"   ssockcsockr  r   r   set_event_loopr+   s    r   r   z BaseProactorEventLoopTests.setUp  s    668			!%diik
DJZZC&*jj$**%=? 	A23 A1$--@	A	A 	DII&A A	A 	As$   "D8C?D?D	DDr_  c                    t        j                         t        j                         fx\  }}|_        t        j                  d      5  t	        | j
                        }d d d        | j                  j                  |       | j                  |j                  |       | j                  |j                  d       |j                          y # 1 sw Y   nxY w)Nr`  r   )r   r!   r   r  r   r"   assertIs_ssock_csockrw   _internal_fdsr   )r,   
socketpairrb  rc  r   s        r   r>   z$BaseProactorEventLoopTests.test_ctor  s     IIK2& 	&uz.ZZ./ 	8(7D	8dkk5)dkk5)++Q/

	8 	8s   CCc                    | j                   j                          | j                  | j                   j                  d       | j	                  | j
                  j                  j                         | j	                  | j                  j                  j                         | j                  | j                   j                         | j                  | j                   j                         d| j                   _        y )Nr   T)r   _close_self_piperw   ri  rZ   rb  r   rC   rc  r5   rg  rh  _closedr,   s    r   test_close_self_pipez/BaseProactorEventLoopTests.test_close_self_pipe  s    		""$00!4

((//0

((//0$))**+$))**+ !		r   c                 ^   t        j                         | j                  _        | j                  j	                          | j                  | j                  j                  j                         | j                  | j                  j                  j                         | j                  | j                  j                         | j                  j                  j                          | j                  j	                          | j                  | j                  j                  j                         y r   )r   r!   r   rl  r   rZ   rC   r"   r5   r#   r   rA   rn  s    r   r   z%BaseProactorEventLoopTests.test_close  s    %)YY[		"				2299:++223$))--.		""--/		33::;r   c                     | j                   j                  | j                  t        j                               }| j                  |t               t        |       y r   )r   _make_socket_transportr)   r   r&   rM   r   r   rE   s     r   test_make_socket_transportz5BaseProactorEventLoopTests.test_make_socket_transport  s>    YY--dii9I9I9KLb":;r   c                 2   | j                   j                          | j                  j                  j	                  | j
                  d       | j                  j                  j                  j                  j	                  | j                   j                         y Ni   )r   _loop_self_readingr"   recvr9   rb  r   r   rn  s    r   test_loop_self_readingz1BaseProactorEventLoopTests.test_loop_self_reading  sa    		$$&--djj$?''99LLII((	*r   c                    t        j                         }|| j                  _        | j                  j	                  |       | j                  |j                  j                         | j                  j                  j                  | j                  d       | j                  j                  j                  j                  j                  | j                  j                         y ru  )r   r!   r   _self_reading_futurerv  rZ   r6   rC   r"   rw  r9   rb  r   r   )r,   r<   s     r   test_loop_self_reading_futz5BaseProactorEventLoopTests.test_loop_self_reading_fut%  s    iik),		&		$$S)

))*--djj$?''99LLII((	*r   c                 "   t        j                         | j                  _        t	               | j
                  j                  _        | j                  j                          | j                  | j                  j                  j                         y r   )r   r!   r   r   rq   r"   rw  r`   rv  rZ   rC   rn  s    r    test_loop_self_reading_exceptionz;BaseProactorEventLoopTests.test_loop_self_reading_exception.  sT    +/99;		()0&		$$&		88??@r   c                     | j                   j                          | j                  j                  j	                  d       y )N    )r   _write_to_selfrc  r   r9   rn  s    r   test_write_to_selfz-BaseProactorEventLoopTests.test_write_to_self4  s(    		  "

**51r   c                 :    | j                   j                  g        y r   )r   _process_eventsrn  s    r   test_process_eventsz.BaseProactorEventLoopTests.test_process_events8  s    		!!"%r   r   c                    t        j                         }t        j                         x}| j                  _        | j                  j	                  || j
                         | j                  |j                         |j                  d   d   } |        | j                  j                  j                  | j
                         t        j                         }t        j                         t        j                         f|j                  _        t        j                         x}| j                  _         ||       | j                  |j                  j                         | j                  |j                         t               |j                  _         ||       | j                  | j
                  j"                  j                         | j                  |j$                  j                         y rW   )r   r!   r   	call_soon_start_servingr)   rZ   rC   rN   r"   acceptr9   r6   r   rr  rq   r`   r   r   )r,   r   pfr  r   r<   make_trs          r   test_create_serverz-BaseProactorEventLoopTests.test_create_server;  s;   YY[*.))+5	DII'		  TYY/	(() ""1%a(//		: iik#'99;		"<

59YY[@$))2S	

))*' ")

S			../**+r   c                    t        j                         }t        j                         x}| j                  _        | j                  j	                  || j
                         |j                  d   d   }| j                  j                         }|j                           ||       | j                  | j
                  j                  j                         y rW   )r   r!   r   r  r  r)   rN   r3   r   rZ   r   rC   )r,   r  r  r   r<   s        r   test_create_server_cancelz4BaseProactorEventLoopTests.test_create_server_cancelW  s    YY[*.))+5	DII'		  TYY/""1%a( ii%%'

S			../r   c                    t        j                         }t        j                         }t        j                         }t        j                         }|j                         ||j                         |i| j                  _        | j                  j                  |       | j                  |j                  j                         | j                  |j                  j                         | j                  j
                  j                  |       | j                  |j                  j                         | j                  |j                  j                         y r   )r   r!   r   r   _accept_futures_stop_servingrZ   r   rC   r   r"   r9   rA   )r,   sock1future1sock2future2s        r   test_stop_servingz,BaseProactorEventLoopTests.test_stop_servingd  s    		))+		))+LLNGLLNG%
		!
 			&**+--.##66u=++,../r   c                     t        j                  t        j                        | _        | j
                  j                  | j                  | j                        S r   )r$   r%   r   r  r'   r   _make_datagram_transportr)   rn  s    r   r  z-BaseProactorEventLoopTests.datagram_transportu  s9    "55g6N6NOyy11$))T]]KKr   c                     | j                         }| j                  |t               | j                  |t        j                         t        |       y r   )r  rM   r   r   DatagramTransportr   rE   s     r   test_make_datagram_transportz7BaseProactorEventLoopTests.test_make_datagram_transporty  s?    $$&b"<=b'";";<r   c                    | j                         }|j                  j                  d       |j                          | j                  j
                  j                  j                  | j                  dd       | j                  j
                  j                  j                  j                  j                  |j                         t        |       y )NrH   	127.0.0.1i$/  rH   r  r  )r  rx   
appendleftru   r   r#   r!  r9   r)   r   r   r   rE   s     r   test_datagram_loop_writingz5BaseProactorEventLoopTests.test_datagram_loop_writing  s    $$&


=>
		""55diiOc5d		""//AAr//0r   c                    | j                         }|j                          | j                  j                  j                  j                  | j                  d       | j                  | j                  j                  j                         | j                  | j                  j                  j                         t        |       y )N   )r  r@   r   r#   recvfromr9   r)   rA   r'   datagram_receivedrC   rE  r   rE   s     r   test_datagram_loop_readingz5BaseProactorEventLoopTests.test_datagram_loop_reading  s    $$&
		$$77		:N88??@55<<=r   c                    | j                   j                         }|j                  d       | j                         }||_        |j                  |       | j                   j                  j                  j                  | j                  d       | j                  j                  j                  dd       t        |       y )Nr  r  rH   r  )r   r3   rI   r  rK   r@   r#   r  r9   r)   r'   r  r   r[   s      r   test_datagram_loop_reading_dataz:BaseProactorEventLoopTests.test_datagram_loop_reading_data  s    ii%%'67$$&
		$$77		:N''::7DXYr   rU   c                 N   | j                   j                         }|j                  d       | j                         }| j	                  t
        |j                  |       t        j                         |_	        ||_
        |j                  |       | j                  | j                   j                  j                  j                         | j                  | j                   j"                  j                         | j                  |j                  j                         t%        |       y )N)r   r  )r   r3   rI   r  rX   rY   r@   r   r!   r   rK   rZ   r#   r  rC   rA   r'   rE  r   r[   s      r   "test_datagram_loop_reading_no_dataz=BaseProactorEventLoopTests.test_datagram_loop_reading_no_data  s    ii%%'23$$&."*:*:C@99;
		++44;;<55<<=)r   c                 z   t               x}| j                  j                  j                  _        | j                         }t        j                         |_        t        j                         |j                  _
        |j                          |j                  j                  j                  |       t        |       y r   )r_   r   r#   r  r`   r  r   r!   ra   	_protocolrE  r@   r9   r   rb   s      r   "test_datagram_loop_reading_abortedz=BaseProactorEventLoopTests.test_datagram_loop_reading_aborted  s{    9O9QQdii!!**6$$&))+&*iik#

##66s;r   c                    t               x}| j                  j                  j                  _        | j                         }t        j                         |_        t        j                         |j                  _
        |j                  j                  d       |j                          |j                  j                  j                  |       t        |       y )N)s   Hellor  )r_   r   r#   r!  r`   r  r   r!   ra   r  rE  rx   r  ru   r9   r   rb   s      r   "test_datagram_loop_writing_abortedz=BaseProactorEventLoopTests.test_datagram_loop_writing_aborted  s    7M7OOdii!!((4$$&))+&*iik#


>?

##66s;r   ) r  r  r	  r   r   r  r>   ro  r   rs  rx  r{  r}  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  r  r  s   @r   r]  r]    s    ' TZZ;< =	!	<
**A2& TZZ,-, .,600"L	 X__SYY'')TU V	r   r]  win32z%Proactor is supported on Windows onlyc                        e Zd Zddz  Z G d dej
                        Ze fd       Ze fd       Z	 fdZ
ddZd	 Zd
 Zd Zd Zd Zd Z xZS )&ProactorEventLoopUnixSockSendfileTestss   12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde   c                   *    e Zd Zd Zd Zd Zd Zd Zy).ProactorEventLoopUnixSockSendfileTests.MyProtoc                 v    d| _         d| _        t               | _        |j	                         | _        d | _        y rj   )startedclosedr:   rt   r3   r<   r   )r,   r   s     r   __init__z7ProactorEventLoopUnixSockSendfileTests.MyProto.__init__  s0     DLDK!DI))+DH!DNr   c                      d| _         || _        y rf   )r  r   r,  s     r   r7   z>ProactorEventLoopUnixSockSendfileTests.MyProto.connection_made  s    DL&DNr   c                 :    | j                   j                  |       y r   )rt   extend)r,   rt   s     r   rB   z<ProactorEventLoopUnixSockSendfileTests.MyProto.data_received  s    IIT"r   c                 H    d| _         | j                  j                  d        y rf   )r  r<   rI   )r,   excs     r   r   z>ProactorEventLoopUnixSockSendfileTests.MyProto.connection_lost  s    DKHH%r   c                 8   K   | j                    d {    y 7 wr   )r<   rn  s    r   wait_closedz:ProactorEventLoopUnixSockSendfileTests.MyProto.wait_closed  s     ((NNs   N)r  r  r	  r  r7   rB   r   r  r   r   r   MyProtor    s    	"	'	#	&	r   r  c                     t        t        j                  d      5 }|j                  | j                         d d d        t
        |           y # 1 sw Y   xY w)Nwb)openr	   TESTFNrv   DATAr   
setUpClass)clsfpr-   s     r   r  z1ProactorEventLoopUnixSockSendfileTests.setUpClass  sE    )""D) 	RHHSXX		 	s   AAc                 h    t        j                  t         j                         t        |           y r   )r	   unlinkr  r   tearDownClass)r  r-   s    r   r  z4ProactorEventLoopUnixSockSendfileTests.tearDownClass  s"    ))*r   c                 \   t        j                         | _        | j                  | j                         | j	                  | j                  j
                         t        t        j                  d      | _	        | j	                  | j                  j
                         t        | -          y )Nrb)r   ProactorEventLoopr   rd  r    r   r  r	   r  filer   r   r+   s    r   r   z,ProactorEventLoopUnixSockSendfileTests.setUp  sj    --/	DII&		())40			(r   c                    t        j                   t         j                  t         j                        }|j                  |       |j	                  t         j
                  t         j                  d       |j	                  t         j
                  t         j                  d       |r| j                  |j                         |S )Nr  )
r(   AF_INETSOCK_STREAMsetblocking
setsockopt
SOL_SOCKET	SO_SNDBUF	SO_RCVBUFr    r   )r,   cleanupblockingr)   s       r   make_socketz2ProactorEventLoopUnixSockSendfileTests.make_socket  sz    }}V^^V-?-?@"))6+;+;TB))6+;+;TBOODJJ'r   c                 8    | j                   j                  |      S r   )r   run_until_complete)r,   coros     r   run_loopz/ProactorEventLoopUnixSockSendfileTests.run_loop  s    yy++D11r   c                      j                         } j                   j                        t        j                         } j                  d      }|j                  d|f        j                   j                  j                  fd|             j                   j                  j                  ||j                                       fd} j                  |       |fS )NF)r  r  c                       S r   r   )protos   r   r   z@ProactorEventLoopUnixSockSendfileTests.prepare.<locals>.<lambda>  s    E r   )r)   c                       j                   9 j                   j                          j                   j                                j                          j                  j                                y r   )r   r   r  r  )r  r,   servers   r   r  z?ProactorEventLoopUnixSockSendfileTests.prepare.<locals>.cleanup  sR    * %%'e//12LLNMM&,,./r   )r  r  r   r
   find_unused_portbindr  create_serversock_connectgetsocknamer    )r,   r)   portsrv_sockr  r  r  s   `    @@r   preparez.ProactorEventLoopUnixSockSendfileTests.prepare  s    !TYY'--/##E#2{D)*tyy66  7  * +dii,,T83G3G3IJK	0 	 U{r   c           	      V   | j                         \  }}t               }| j                  t        j                  d      5  | j                  | j                  j                  ||dd              d d d        | j                  | j                  j                         d       y # 1 sw Y   4xY wNnot a regular filer   )r  r1  assertRaisesRegexr   SendfileNotAvailableErrorr  r   _sock_sendfile_nativerw   r  tellr,   r)   r  r   s       r   test_sock_sendfile_not_a_filezDProactorEventLoopUnixSockSendfileTests.test_sock_sendfile_not_a_file  s    llneH##G$E$E$8: 	DMM$))99$:;TC D	D 	)1-		D 	Ds   .BB(c           	      j   | j                         \  }}t        j                         }| j                  t        j
                  d      5  | j                  | j                  j                  ||dd              d d d        | j                  | j                  j                         d       y # 1 sw Y   4xY wr  )r  ioBytesIOr  r   r  r  r   r  rw   r  r  r  s       r   test_sock_sendfile_iobufferzBProactorEventLoopUnixSockSendfileTests.test_sock_sendfile_iobuffer  s    llneJJL##G$E$E$8: 	DMM$))99$:;TC D	D 	)1-		D 	Ds   .B))B2c           	         | j                         \  }}t        j                         }d|j                  _        | j                  t        j                  d      5  | j                  | j                  j                  ||dd              d d d        | j                  | j                  j                         d       y # 1 sw Y   4xY w)Nr   r  r   )r  r   r!   r   r   r  r   r  r  r   r  rw   r  r  r  s       r   #test_sock_sendfile_not_regular_filezJProactorEventLoopUnixSockSendfileTests.test_sock_sendfile_not_regular_file'  s    llneIIK "##G$E$E$8: 	DMM$))99$:;TC D	D 	)1-		D 	Ds   .B::Cc                    | j                   j                  d       | j                  d      }| j                  t        d      5  | j                  | j                   j                  || j                               d d d        y # 1 sw Y   y xY w)NT)r  zmust be non-blocking)r   	set_debugr  r  rL  r  sock_sendfiler  )r,   r)   s     r   test_blocking_socketz;ProactorEventLoopUnixSockSendfileTests.test_blocking_socket1  sr    		D!.##J0FG 	DMM$))11$		BC	D 	D 	Ds   6BB)TF)r  r  r	  r  r   r&   r  classmethodr  r  r   r  r  r  r  r  r  r  r  r  s   @r   r  r    sr     $D'"" .  
    20...Dr   r  __main__)__doc__r  r(   r
  r  r   r   asyncio.proactor_eventsr   r   r   r   r   test.supportr	   r
   test.test_asyncior   r$   r   r   TestCaser   r  r]  r  platformr  r  mainr   r   r   <module>r     s    " 	   
   9 < ? @ > " & 1({=:#6#6 {=|G"Z%8%8 G"TV!4!4 Vr (8:qDZ-@-@ qD:qDf zHMMO r   