
    dafe                       d Z ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZ	 ddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddlZddlZej                  dvrddl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l&m)Z)m*Z*m+Z+ d Z,d Z-d Z. G d d      Z/ G d dej`                        Z1 G d de1      Z2 G d dejf                        Z4 G d dej`                        Z5 G d dejl                        Z7 G d dejp                        Z9 G d d       Z: G d! d"      Z;ej                  d#k(  r. G d$ d%e:e#jx                        Z= G d& d'e:e;e#jx                        Z>nddl?Z? G d( d)e:      Z@ eAe?d*      r G d+ d,e@e;e#jx                        ZB eAe?d-      r G d. d/e@e;e#jx                        ZC eAe?d0      r G d1 d2e@e;e#jx                        ZD G d3 d%e@e;e#jx                        Z=d4 ZE G d5 d6e#jx                        ZF G d7 d8ejx                        ZG G d9 d:ejx                        ZH G d; d<ejx                        ZI G d= d>      ZJ G d? d@eJejx                        ZK	 ddlLZL G dA dBeJejx                        ZM G dC dDejx                        ZN G dE dFejx                        ZOePdGk(  r ej                          yy# e$ r dZY w xY w# e$ r Y Ww xY w)HzTests for events.py.    N)mock)win32vxworks)
coroutines)events)selector_events)_cleanup_tests)utils)support)socket_helper)threading_helper)	ALWAYS_EQLARGESTSMALLESTc                  .    t        j                  d        y N)asyncioset_event_loop_policy     8/root/Python-3.12.4/Lib/test/test_asyncio/test_events.pytearDownModuler   *   s    !!$'r   c                      t         j                  j                  d      ryt         j                  dk7  ryt        j                         d   } t	        t        t        | j                  d                  } | dk  S )z4Return True if the platform is Mac OS 10.4 or older.aixTdarwinFr   .)
      )sysplatform
startswithmac_vertuplemapintsplit)versions    r   broken_unix_getsocknamer(   .   s^    
||u%		! #GCW]]3/01GWr   c                      d } t        j                         }t        j                  |       |j                   |              S )Nc                     K   ywNhellor   r   r   r   doitz8_test_get_event_loop_new_process__sub_proc.<locals>.doit:   s	        )r   new_event_loopset_event_looprun_until_complete)r-   loops     r   *_test_get_event_loop_new_process__sub_procr3   9   s8     !!#D4 ""46**r   c                   $    e Zd Zd Zd Zd Zd Zy)CoroLikec                      y r   r   )selfvs     r   sendzCoroLike.sendC       r   c                      y r   r   r7   excs     r   throwzCoroLike.throwF   r:   r   c                      y r   r   r7   s    r   closezCoroLike.closeI   r:   r   c                      y r   r   r@   s    r   	__await__zCoroLike.__await__L   r:   r   N)__name__
__module____qualname__r9   r>   rA   rC   r   r   r   r5   r5   B   s    r   r5   c                   :    e Zd ZdZdZddZd Zd Zd Zd Z	d Z
y)	MyBaseProtoNc                     d | _         d| _        d| _        |+|j                         | _        |j                         | _        y y NINITIALr   )	transportstatenbytescreate_future	connecteddoner7   r2   s     r   __init__zMyBaseProto.__init__T   sB    
!//1DN**,DI r   c                 V    | j                   |vrt        d| j                   d|      y Nzstate: z, expected: rM   AssertionErrorr7   expecteds     r   _assert_statezMyBaseProto._assert_state\   s/    ::X% 74::.XL!QRR &r   c                     || _         | j                  d       d| _        | j                  r| j                  j	                  d        y y NrK   	CONNECTEDrL   rZ   rM   rP   
set_resultr7   rL   s     r   connection_madezMyBaseProto.connection_made`   s<    "9% 
>>NN%%d+ r   c                 b    | j                  d       | xj                  t        |      z  c_        y Nr]   rZ   rN   lenr7   datas     r   data_receivedzMyBaseProto.data_receivedg   s"    ;'s4y r   c                 4    | j                  d       d| _        y )Nr]   EOF)rZ   rM   r@   s    r   eof_receivedzMyBaseProto.eof_receivedk   s    ;'
r   c                     | j                  dd       d| _        | j                  r| j                  j                  d        y y )Nr]   rj   CLOSEDrZ   rM   rQ   r_   r<   s     r   connection_lostzMyBaseProto.connection_losto   s7    ;.
99II  & r   r   )rD   rE   rF   rP   rQ   rS   rZ   ra   rh   rk   ro   r   r   r   rH   rH   P   s+    ID-S,!'r   rH   c                        e Zd Z fdZ xZS )MyProtoc                 F    t         |   |       |j                  d       y )Ns%   GET / HTTP/1.0
Host: example.com

)superra   write)r7   rL   	__class__s     r   ra   zMyProto.connection_madew   s    	*FGr   rD   rE   rF   ra   __classcell__ru   s   @r   rq   rq   v   s    H Hr   rq   c                   6    e Zd ZdZddZd Zd Zd Zd Zd Z	y)	MyDatagramProtoNc                 P    d| _         d| _        ||j                         | _        y y rJ   )rM   rN   rO   rQ   rR   s     r   rS   zMyDatagramProto.__init__   s+    
**,DI r   c                 X    | j                   |k7  rt        d| j                   d|      y rU   rV   rX   s     r   rZ   zMyDatagramProto._assert_state   /    ::! 74::.XL!QRR "r   c                 B    || _         | j                  d       d| _        y )NrK   INITIALIZEDrL   rZ   rM   r`   s     r   ra   zMyDatagramProto.connection_made   s    "9%"
r   c                 b    | j                  d       | xj                  t        |      z  c_        y Nr   rd   r7   rg   addrs      r   datagram_receivedz!MyDatagramProto.datagram_received   s"    =)s4y r   c                 &    | j                  d       y r   )rZ   r<   s     r   error_receivedzMyDatagramProto.error_received   s    =)r   c                     | j                  d       d| _        | j                  r| j                  j                  d        y y )Nr   rm   rn   r<   s     r   ro   zMyDatagramProto.connection_lost   s5    =)
99II  & r   r   )
rD   rE   rF   rQ   rS   rZ   ra   r   r   ro   r   r   r   rz   rz   |   s&    D-S#
!*'r   rz   c                   6    e Zd ZdZddZd Zd Zd Zd Zd Z	y)	MyReadPipeProtoNc                 `    dg| _         d| _        d | _        ||j                         | _        y y rJ   )rM   rN   rL   rO   rQ   rR   s     r   rS   zMyReadPipeProto.__init__   s4    [
**,DI r   c                 X    | j                   |k7  rt        d| j                   d|      y rU   rV   rX   s     r   rZ   zMyReadPipeProto._assert_state   r}   r   c                 l    || _         | j                  dg       | j                  j                  d       y r\   )rL   rZ   rM   appendr`   s     r   ra   zMyReadPipeProto.connection_made   s+    "I;'

+&r   c                 f    | j                  ddg       | xj                  t        |      z  c_        y r\   rd   rf   s     r   rh   zMyReadPipeProto.data_received   s'    I{34s4y r   c                 `    | j                  ddg       | j                  j                  d       y )NrK   r]   rj   )rZ   rM   r   r@   s    r   rk   zMyReadPipeProto.eof_received   s'    I{34

% r   c                    d| j                   vr| j                   j                  d       | j                  g d       | j                   j                  d       | j                  r| j                  j	                  d        y y )Nrj   )rK   r]   rj   rm   )rM   r   rZ   rQ   r_   r<   s     r   ro   zMyReadPipeProto.connection_lost   s_    

"JJe$:;

(#99II  & r   r   )
rD   rE   rF   rQ   rS   rZ   ra   rh   rk   ro   r   r   r   r   r      s&    D-S'
!!'r   r   c                   *    e Zd ZdZddZd Zd Zd Zy)MyWritePipeProtoNc                 P    d| _         d | _        ||j                         | _        y y )NrK   )rM   rL   rO   rQ   rR   s     r   rS   zMyWritePipeProto.__init__   s+    
**,DI r   c                 X    | j                   |k7  rt        d| j                   d|      y rU   rV   rX   s     r   rZ   zMyWritePipeProto._assert_state   r}   r   c                 B    || _         | j                  d       d| _        y r\   r   r`   s     r   ra   z MyWritePipeProto.connection_made   s    "9% 
r   c                     | j                  d       d| _        | j                  r| j                  j                  d        y y Nr]   rm   rn   r<   s     r   ro   z MyWritePipeProto.connection_lost   s5    ;'
99II  & r   r   )rD   rE   rF   rQ   rS   rZ   ra   ro   r   r   r   r   r      s    D-S!
'r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	MySubprocessProtocolc                 V   d| _         d | _        |j                         | _        |j                         | _        t        d      D ci c]  }||j                          c}| _        ddd| _        d | _        t        j                         t        j                         d| _        y c c}w )NrK      r         )rM   rL   rO   rP   	completedrangedisconnectsrg   
returncoder   Eventgot_data)r7   r2   fds      r   rS   zMySubprocessProtocol.__init__   s    
++-++-?DQxHB 2 2 44H$	#MMO#MMO- Is   B&c                 X    | j                   |k7  rt        d| j                   d|      y rU   rV   rX   s     r   rZ   z"MySubprocessProtocol._assert_state   r}   r   c                 x    || _         | j                  d       d| _        | j                  j	                  d        y r\   r^   r`   s     r   ra   z$MySubprocessProtocol.connection_made   s0    "9% 
!!$'r   c                 j    | j                  d       d| _        | j                  j                  d        y r   )rZ   rM   r   r_   r<   s     r   ro   z$MySubprocessProtocol.connection_lost   s)    ;'
!!$'r   c                     | j                  d       | j                  |xx   |z  cc<   | j                  |   j                          y rc   )rZ   rg   r   set)r7   r   rg   s      r   pipe_data_receivedz'MySubprocessProtocol.pipe_data_received   s7    ;'		"br   c                     | j                  d       |r| j                  |   j                  |       y | j                  |   j                  |       y rc   )rZ   r   set_exceptionr_   )r7   r   r=   s      r   pipe_connection_lostz)MySubprocessProtocol.pipe_connection_lost   sE    ;'R ..s3R ++C0r   c                 d    | j                  d       | j                  j                         | _        y rc   )rZ   rL   get_returncoder   r@   s    r   process_exitedz#MySubprocessProtocol.process_exited  s$    ;'..779r   N)
rD   rE   rF   rS   rZ   ra   ro   r   r   r   r   r   r   r   r      s&    	-S((
 
1:r   r   c                   
    e Zd Z fdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z ej"                   eed      d      d        Z ej"                   eed      d       ej"                   eed      d      d               Z ej"                   eed      d       ej"                   eed      d      d               Zd_dZd Zej4                  d        Zddi fdZ	 	 d`dZ	 d`dZ ej>                  e du d      d         Z!ej4                   ej>                  e du d      d!               Z"d" Z#ejH                  d#        Z%ejH                  d$        Z&d% Z'dad&Z( ej>                  e du d      d'        Z)d( Z* e+jX                  d)      d*        Z-d+ Z.d, Z/d- Z0d. Z1 ej"                   ee2d/      d0      d1        Z3d2 Z4ej4                  d3        Z5 ej"                   ee2d4      d5      d6        Z6dbd7Z7dbd8Z8dbd9Z9 ej>                  e du d      d:        Z:ej4                   ej>                  e du d      d;               Z; ej>                  e du d      d<        Z<ej4                   ej>                  e du d      d=               Z= ej>                  e du d      d>        Z>ej4                   ej>                  e du d      d?               Z? ej>                  e du d      d@        Z@dA ZAdB ZB ej"                  ej                  dC      dD        ZDejH                  dE        ZEdF ZFdG ZG ej"                  ej                  dC      dH        ZHdI ZIdJ ZJdK ZK ej"                  eLj                  dLk7  dM      dN        ZN ej"                  eLj                  dLk7  dM      dO        ZO ej"                  eLj                  dLk7  dM       ej"                   eePdP      dQ      dR               ZQ ej"                  eLj                  dLk7  dM      dS        ZR ej"                  eLj                  dLk7  dM      dT        ZS ej"                  eLj                  dLk7  dM       ej"                   eePdP      dQ       eTj                  dUdV      dW                      ZV ej"                  eLj                  dLk7  dM       ej"                   eePdP      dQ       eTj                  dUdV      dX                      ZWdY ZXdZ ZYd[ ZZd\ Z[d] Z\d^ Z] xZ^S )cEventLoopTestsMixinc                     t         |           | j                         | _        | j	                  | j                         y r   )rs   setUpcreate_event_loopr2   r0   r7   ru   s    r   r   zEventLoopTestsMixin.setUp  s.    **,	DII&r   c                     | j                   j                         st        j                  | j                          | j	                          t        j                          t        | !          y r   )	r2   	is_closed
test_utilsrun_briefly
doCleanupsr   
gc_collectrs   tearDownr   s    r   r   zEventLoopTestsMixin.tearDown  sF    yy""$""499-r   c                      d  fd} j                  t        d      5   j                  t         j                  j
                   |              d d d        y # 1 sw Y   y xY w)Nc                  J   K   t        j                  d       d {    y 7 wNr   r   sleepr   r   r   coro1zBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro1  s     --"""s   #!#c                     K   j                  j                  j                                j                  j                                  y wr   )
assertTruer2   
is_runningr1   )r   r7   s   r   coro2zBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro2  s4     OODII0023II((1s   AAzcoroutine \S+ was never awaited)assertWarnsRegexRuntimeWarningassertRaisesRuntimeErrorr2   r1   )r7   r   r   s   ` @r   test_run_until_complete_nestingz3EventLoopTestsMixin.test_run_until_complete_nesting  s`    	#	2 "".
 	E dii::EGE		E 	E 	Es   1AA%c                    d}| j                   j                         }| j                   j                  t        j                  |             | j                   j                         |z
  }| j                  ||t        j                  z
         y N皙?)r2   timer1   r   r   assertGreaterEqualr   	CLOCK_RES)r7   delayt0dts       r   test_run_until_completez+EventLoopTestsMixin.test_run_until_complete(  sb    YY^^		$$W]]5%9:YY^^"EJ,@,@$@Ar   c                 t      fd} |       } j                  t         j                  j                  |       y )Nc                     K    j                   j                          t        j                  d       d {    y 7 wr   )r2   stopr   r   r@   s   r   cbz?EventLoopTestsMixin.test_run_until_complete_stopped.<locals>.cb1  s'     IINN--$$$s   3><>)r   r   r2   r1   )r7   r   tasks   `  r   test_run_until_complete_stoppedz3EventLoopTestsMixin.test_run_until_complete_stopped/  s0    	% t,))66	>r   c                      g  fd} j                   j                  d|d        j                   j                           j                  dg       y )Nc                 \    j                  |        j                  j                          y r   r   r2   r   argresultsr7   s    r   callbackz5EventLoopTestsMixin.test_call_later.<locals>.callback;  s    NN3IINNr   r   zhello world)r2   
call_laterrun_foreverassertEqualr7   r   r   s   ` @r   test_call_laterz#EventLoopTestsMixin.test_call_later8  sG    	 			S(M:		=/2r   c                      g  fd} j                   j                  |dd        j                   j                           j                  dg       y )Nc                 `    j                  | |f       j                  j                          y r   r   )arg1arg2r   r7   s     r   r   z4EventLoopTestsMixin.test_call_soon.<locals>.callbackF  s!    NND$<(IINNr   r,   world)r,   r   )r2   	call_soonr   r   r   s   ` @r   test_call_soonz"EventLoopTestsMixin.test_call_soonC  sI    	 			Hgw7		#5"67r   c                     g t        j                          fd fd}j                          t        j                  |      }|j	                          5   j
                  j                  d        j
                  j                          d d d        |j                           j                  ddg       y # 1 sw Y   .xY w)Nc                 z    j                  |        t              dk\  rj                  j                          y y Nr   r   re   r2   r   r   s    r   r   z?EventLoopTestsMixin.test_call_soon_threadsafe.<locals>.callbackR  .    NN37|q 		  !r   c                  ^    j                   j                   d       j                          y r+   )r2   call_soon_threadsaferelease)r   lockr7   s   r   run_in_threadzDEventLoopTestsMixin.test_call_soon_threadsafe.<locals>.run_in_threadW  s     II**8W=LLNr   targetr   r,   )
	threadingLockacquireThreadstartr2   r   r   joinr   )r7   r   tr   r   r   s   `  @@@r   test_call_soon_threadsafez-EventLoopTestsMixin.test_call_soon_threadsafeN  s    ~~	!
	 	M2		 	$II'2II!!#	$ 	
7G"45		$ 	$s    7CCc                      g  fd} j                   j                  |d        j                   j                  |d        j                   j                           j	                  ddg       y )Nc                 z    j                  |        t              dk\  rj                  j                          y y r   r   r   s    r   r   zKEventLoopTestsMixin.test_call_soon_threadsafe_same_thread.<locals>.callbackh  r   r   r,   r   )r2   r   r   r   r   r   s   ` @r   %test_call_soon_threadsafe_same_threadz9EventLoopTestsMixin.test_call_soon_threadsafe_same_threade  s\    	!
 			&&x9		Hg.		7G"45r   c                     d }| j                   j                  d |d      }| j                   j                  |      \  }}| j                  |d       | j	                  |t        j                                y )Nc                 .    | t        j                         fS r   )r   	get_ident)r   s    r   runz5EventLoopTestsMixin.test_run_in_executor.<locals>.runs  s    ,,.//r   yo)r2   run_in_executorr1   r   assertNotEqualr   r  )r7   r  f2res	thread_ids        r   test_run_in_executorz(EventLoopTestsMixin.test_run_in_executorr  s`    	0YY&&tS$755b9Yd#Iy':':'<=r   c                    dfd}d }| j                   j                  d |      }|j                          | j                   j                  | j                   j	                                | j                   j                          || j                   _        || j                   _        t        j                  d       | j                         y )NFc                  
    dy NTr   )argscalleds    r   patched_call_soonzJEventLoopTestsMixin.test_run_in_executor_cancel.<locals>.patched_call_soon}  s    Fr   c                  .    t        j                  d       y )Ng?)r   r   r   r   r   r  z<EventLoopTestsMixin.test_run_in_executor_cancel.<locals>.run  s    JJtr   g?)r2   r  cancelr1   shutdown_default_executorrA   r   r   r   r   assertFalse)r7   r  r  r  r  s       @r   test_run_in_executor_cancelz/EventLoopTestsMixin.test_run_in_executor_cancelz  s    		 YY&&tS1
				$$		335	7		/		):		&

3 r   c                     t        j                         \  }j                  d       t                fd} j                  j                  j                         |        j                  j                  |j                  d       t        j                   j                  fd        j                  j                  |j                  d       t        j                   j                  fd        j                  j                  |j                          j                  j                   j                  j                          j                  j                           j                  d       y )NFc                      	 j                  d      } | rj                  |        y j                  j                  j                  j                                      j                          y # t        $ r Y y w xY wN   )recvBlockingIOErrorextendr   r2   remove_readerfilenorA   )rg   
bytes_readrr7   s    r   readerz8EventLoopTestsMixin.test_reader_callback.<locals>.reader  sh    vvd|
 !!$'		 7 7
 CD	 #  s   A1 1	A=<A=s   abcc                       t               dk\  S )Nr   re   r(  s   r   <lambda>z:EventLoopTestsMixin.test_reader_callback.<locals>.<lambda>      J10D r   s   defc                       t               dk\  S )N   r,  r-  s   r   r.  z:EventLoopTestsMixin.test_reader_callback.<locals>.<lambda>  r/  r   s   abcdef)socket
socketpairsetblocking	bytearrayr2   
add_readerr'  r   r9   r   	run_untilrA   r   r   r   )r7   wr*  r(  r)  s   `  @@r   test_reader_callbackz(EventLoopTestsMixin.test_reader_callback  s      "1	e[
	 			QXXZ0		AFFF+TYY(DE		AFFF+TYY(DE		AGG$		DIINN+		Y/r   c                 p    t        j                         \  }j                  d        fd}d} j                  j	                  j                         ||        j                  j                           j                   j                  j                  j                                       j                   j                  j                  j                                      j                          |j                  t        |      dz        }|j                           j                  ||       y )NFc                 \    j                  |        j                  j                          y r   )r9   r2   r   )rg   r7   r8  s    r   writerz8EventLoopTestsMixin.test_writer_callback.<locals>.writer  s    FF4LIINNr   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr   )r2  r3  r4  r2   
add_writerr'  r   r   remove_writerr  rA   r#  re   r   )r7   r)  r<  rg   readr8  s   `    @r   test_writer_callbackz(EventLoopTestsMixin.test_writer_callback  s      "1	e	 		QXXZ6				//
;<00<=		vvc$i!m$		t$r   SIGKILLz
No SIGKILLc                 \   dfd}| j                  t        | j                  j                  d|       | j                  t        | j                  j                  d       | j                  t
        | j                  j                  t        j                  dz   |       | j                  t
        | j                  j                  t        j                  dz          | j                  t
        | j                  j                  d|       | j                  t
        | j                  j                  d       | j                  t
        | j                  j                  d|       | j                  t
        | j                  j                  d       | j                  t        | j                  j                  t        j                  |       | j                  | j                  j	                  t        j                               | j                  j                  t        j                  |       t        j                  t        j                         t        j                         t        j                   | j                  fd       | j#                  | j                  j	                  t        j                               | j%                  t        j&                  t        j                        t        j(                         | j                  | j                  j	                  t        j                               y )Nr   c                       dz   y Nr   r   caughts   r   
my_handlerz?EventLoopTestsMixin.test_add_signal_handler.<locals>.my_handler  s    aKFr   boomr   c                       S r   r   rE  s   r   r.  z=EventLoopTestsMixin.test_add_signal_handler.<locals>.<lambda>  s     r   )r   	TypeErrorr2   add_signal_handlerremove_signal_handler
ValueErrorsignalNSIGr   rA  r  SIGINToskillgetpidr   r7  r   r   	getsignaldefault_int_handlerr7   rG  rF  s     @r   test_add_signal_handlerz+EventLoopTestsMixin.test_add_signal_handler  s    	
 	tyy33VZ	Ityy66	@		44fkk!m	 			77Q	H		44a	E		77	<		44b*	F		77	=$))66	 	88HI		$$V]]J?
		V]]+TYY7 			77FG))&--833	5 	88GHr   SIGALRMz
No SIGALRM	setitimerzneed signal.setitimer()c                 n    d fd} j                   j                  t        j                  |       t        j                  t        j
                  dd        j                   j                  d j                   j                          j                   j                           j                  d       y )Nr   c                  D     dz   j                   j                          y rD  )r2   r   )rF  r7   s   r   rG  zLEventLoopTestsMixin.test_signal_handling_while_selecting.<locals>.my_handler  s    aKFIINNr   {Gz?<   r   
r2   rL  rO  rY  rZ  ITIMER_REALr   r   r   r   rW  s   ` @r   $test_signal_handling_while_selectingz8EventLoopTestsMixin.test_signal_handling_while_selecting  s}    
 	
 			$$V^^Z@++T15		R0		#r   c                 z    dd fd}  j                   j                  t        j                  |g  t        j                  t        j
                  dd        j                   j                  d j                   j                          j                   j                           j                  d       y )N)*   r   c                  h    dz  j                  |        j                  j                          y rD  )r   r2   r   )r  rF  r7   	some_argss    r   rG  zAEventLoopTestsMixin.test_signal_handling_args.<locals>.my_handler  s*    aKFT9-IINNr   r   r^  r   r_  )r7   rG  rF  re  s   ` @@r   test_signal_handling_argsz-EventLoopTestsMixin.test_signal_handling_args  s     		 	%		$$V^^ZL)L++S!4		R0		#r   Tc                    | j                   j                  |      \  }}| j                  |t        j                         | j                  |t        j
                         | j                  |j                  |       |r | j                  |j                  d             | j                   j                  |j                         | j                  |j                  d       |j                          y )Nsocknamer   )r2   r1   assertIsInstancer   	TransportProtocolassertIsrL   assertIsNotNoneget_extra_inforQ   assertGreaterrN   rA   )r7   connection_futcheck_socknametrprs        r   _basetest_create_connectionz/EventLoopTestsMixin._basetest_create_connection  s    --n=Bb'"3"34b'"2"23bllB'  !2!2:!>?		$$RWW-299a(

r   c                      t        j                         5 }  j                  j                   fdg|j                   } j                  |       d d d        y # 1 sw Y   y xY w)Nc                  0    t         j                        S Nr2   rq   r2   r@   s   r   r.  z<EventLoopTestsMixin.test_create_connection.<locals>.<lambda>      TYY/ r   )r   run_test_serverr2   create_connectionaddressrt  )r7   httpdconn_futs   `  r   test_create_connectionz*EventLoopTestsMixin.test_create_connection  s[    '') 	7U2tyy22/A27--AH,,X6	7 	7 	7s   <AA$c                      t                }t        j                         5 } j                  j	                   fd|j
                        } j                  ||       d d d        y # 1 sw Y   y xY w)Nc                  0    t         j                        S rw  ry  r@   s   r   r.  zAEventLoopTestsMixin.test_create_unix_connection.<locals>.<lambda>*  rz  r   )r(   r   run_test_unix_serverr2   create_unix_connectionr}  rt  )r7   rq  r~  r  s   `   r   test_create_unix_connectionz/EventLoopTestsMixin.test_create_unix_connection"  se     566,,. 	G%yy77/@H,,X~F	G 	G 	Gs   <A&&A/Nc                    |r | j                  |j                  d             |r"| j                  ||j                  d             n | j                  |j                  d             | j                  ||j                  d             |j                  d      }| j                  |t               | j                  t        |      d|       | j                  |d   t               | j                  |d   t               | j                  |d   t               |j                  d	      }| j                  |       | j                  |j                         |j                  d
             | j                  |j                         |j                  d             | j                  |j                         |j                  d             | j                  |j                         |j                  d
             y )Nrh  peernamepeercertcipherr   r   r   r   
ssl_objectcompression)rm  rn  r   ri  r#   re   strr%   r  r  getpeercert)r7   clientrq  r  r  r  sslobjs          r   check_ssl_extra_infoz(EventLoopTestsMixin.check_ssl_extra_info-  s     !6!6z!BCX#22:>@   !6!6z!BC..z:	< &&x0fe,Va0fQi-fQi-fQi- &&|4V$++-..}=	?..x8	:++-..z:	<++-..}=	?r   c                    | j                   j                  |      \  }}| j                  |t        j                         | j                  |t        j
                         | j                  d|j                  j                  j                         v        | j                  |||       | j                   j                  |j                         | j                  |j                  d       |j                          y )Nsslr   )r2   r1   ri  r   rj  rk  r   ru   rD   lowerr  rQ   ro  rN   rA   )r7   rp  rq  r  rr  rs  s         r   _basetest_create_ssl_connectionz3EventLoopTestsMixin._basetest_create_ssl_connectionM  s     --n=Bb'"3"34b'"2"23!6!6!<!<!>>?!!"nh?		$$RWW-299a(

r   c                      |t        j                               } j                  |||       t        t        d      r|t        j
                  j                  fd d d d fd}t        j                  d|      5 } |d      } j                  |||        j                  |j                  d       d d d         j                  t        j                        5 } |d      }t        j                         5   j                  |||       d d d        d d d         j                  j                  j                  d	       y # 1 sw Y   xY w# 1 sw Y   DxY w# 1 sw Y   HxY w)
Nr  Purpose)cafilecapathcadatac                    j                  | t        j                  j                         t	        j
                         S )z
                A ssl.create_default_context() replacement that doesn't enable
                cert validation.
                )r   r  r  SERVER_AUTHr   dummy_ssl_context)purposer  r  r  r7   s       r   _dummy_ssl_create_contextzREventLoopTestsMixin._test_create_ssl_connection.<locals>._dummy_ssl_create_contexta  s.       #++*A*AB!3355r   zssl.create_default_context)side_effectTr   CERTIFICATE_VERIFY_FAILED)r   r  r  hasattrr  r  r  r   patchr   
call_countr   SSLErrordisable_logger	exceptionreason)	r7   r~  r|  rq  r  r  r  mcms	   `        r   _test_create_ssl_connectionz/EventLoopTestsMixin._test_create_ssl_connectionY  s>   $)E)E)GH,,X~-5	7 3	"25++2I2I 615d156 8(AC 2FG,644X~5=?  q12 s||, 	?(T2H**, ?44X~5=??	? 	,,.IJ!2 2? ?	? 	?s0   ;9EE9EEEE	EE%zNo ssl modulec                     t        j                  d      5 }t        j                   j                  j
                   fdg|j                   } j                  |||j                         d d d        y # 1 sw Y   y xY w)NTuse_sslc                  0    t         j                        S rw  ry  r@   s   r   r.  z@EventLoopTestsMixin.test_create_ssl_connection.<locals>.<lambda>  rz  r   r  )r   r{  	functoolspartialr2   r|  r}  r  )r7   r~  r|  s   `  r   test_create_ssl_connectionz.EventLoopTestsMixin.test_create_ssl_connection~  s}    ''5 	E ) 1 1		++/!  !  ,,U4E6;mm - E	E 	E 	Es   AA88Bc                 $    t                }t        j                  d      5 }t        j                   j
                  j                   fd|j                  d      } j                  ||||j                         d d d        y # 1 sw Y   y xY w)NTr  c                  0    t         j                        S rw  ry  r@   s   r   r.  zEEventLoopTestsMixin.test_create_ssl_unix_connection.<locals>.<lambda>  rz  r   	127.0.0.1)server_hostnamer  )	r(   r   r  r  r  r2   r  r}  r  )r7   rq  r~  r|  s   `   r   test_create_ssl_unix_connectionz3EventLoopTestsMixin.test_create_ssl_unix_connection  s    
 566,,T: 	Ee ) 1 1		00/ +!-
 ,,U4E-;6;mm - E	E 	E 	Es   ABBc                     t        j                         5 }t        j                         }  j                  j
                   fdg|j                  d|j                  d   |fi} j                  j                  |      \  }}|j                  j                  d      d   } j                  ||       |j                          d d d        y # 1 sw Y   y xY w)Nc                  0    t         j                        S rw  ry  r@   s   r   r.  zGEventLoopTestsMixin.test_create_connection_local_addr.<locals>.<lambda>  rz  r   
local_addrr   rh  r   )r   r{  r   find_unused_portr2   r|  r}  r1   rL   rn  r   rA   )r7   r~  portfrr  rs  rY   s   `      r   !test_create_connection_local_addrz5EventLoopTestsMixin.test_create_connection_local_addr  s    '') 	U 113D+		++/EE,1MM!,<d+CEA YY11!4FB||22:>qAHT8,HHJ	 	 	s   B/CCc                     t        j                         }t        j                          j                  j                  fd}| j                  _         j                  j	                   fdd|df      } j                  t              5   j                  j                  |       d d d        y # 1 sw Y   y xY w)Nc                    K   |k(  rFt         j                  t         j                  dddft         j                  t         j                  dddfgS  | |g|i | d {   S 7 w)Nr    ::1r   r   r   r  r   )r2  AF_INET6SOCK_STREAMAF_INEThostr  r  kwargsgetaddrinfo_origport2s       r   getaddrinfoz`EventLoopTestsMixin.test_create_connection_local_addr_skip_different_family.<locals>.getaddrinfo  si     u}&*<*<aEUV););QDTUW W)$FtFvFFFFs   AA&A$ A&c                  0    t         j                        S rw  ry  r@   s   r   r.  z]EventLoopTestsMixin.test_create_connection_local_addr_skip_different_family.<locals>.<lambda>      G+ r   	localhostr  r   r  r2   r  r|  r   OSErrorr1   r7   port1r  r  r  r  s   `   @@r   7test_create_connection_local_addr_skip_different_familyzKEventLoopTestsMixin.test_create_connection_local_addr_skip_different_family  s     ..0..09900	G !,		II''+K+? ( A w' 	,II((+	, 	, 	,   B77C c                     t        j                         }t        j                          j                  j                  fd}| j                  _         j                  j	                   fdd|df      } j                  t              5   j                  j                  |       d d d        y # 1 sw Y   y xY w)Nc                    K   |k(  r$t         j                  t         j                  dddfgS  | |g|i | d {   S 7 w)Nr   r  r  )r2  r  r  r  s       r   r  zYEventLoopTestsMixin.test_create_connection_local_addr_nomatch_family.<locals>.getaddrinfo  sJ     u}&*<*<aEUVWW)$FtFvFFFFs   :AAAc                  0    t         j                        S rw  ry  r@   s   r   r.  zVEventLoopTestsMixin.test_create_connection_local_addr_nomatch_family.<locals>.<lambda>  r  r   r  r  r  r  s   `   @@r   0test_create_connection_local_addr_nomatch_familyzDEventLoopTestsMixin.test_create_connection_local_addr_nomatch_family  s     ..0..09900	G
 !,		II''+K+? ( A w' 	,II((+	, 	, 	,r  c                 *    t        j                         5 }  j                  j                   fdg|j                  d|j                  i} j                  t              5 } j                  j                  |       d d d         j                  j                  j                  t        j                          j                  t        |j                        |j                  j                         d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                  0    t         j                        S rw  ry  r@   s   r   r.  zNEventLoopTestsMixin.test_create_connection_local_addr_in_use.<locals>.<lambda>  rz  r   r  )r   r{  r2   r|  r}  r   r  r1   r   r  errno
EADDRINUSEassertInr  strerror)r7   r~  r  r  s   `   r   (test_create_connection_local_addr_in_usez<EventLoopTestsMixin.test_create_connection_local_addr_in_use  s    '') 	EU+		++/::+0==:A ""7+ 0r		,,Q/0R\\//1A1ABMM#emm,bll.C.CD	E 	E0 0		E 	Es%   AD	#C=?A5D	=D	D		Dc                   	
 | j                    G 
fddt              }t        j                  dd      }|j	                         	dd d
	fd}t        j                  |d	
      }|j                          |j                         \  }} |      _         j                  j                  fd||             j                          j                  j                          |j                          t        j                  |       | j!                  |j#                                | j%                  j&                  d       | j%                  j(                  t+                     | j%                  
       y )Nc                   .     e Zd Z fdZ fdZ xZS )AEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProtoc                 Z    t         |   |       j                  j                         y r   )rs   ro   r   r   )r7   r=   ru   r2   s     r   ro   zQEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.connection_lost  s     ',tyy)r   c                 Z    t         |   |       | j                  j                         y r   )rs   rh   rL   rt   )r7   rg   ru   expected_responses     r   rh   zOEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.data_received  s#    %d+$$%67r   )rD   rE   rF   ro   rh   rw   )ru   r  r2   s   @r   rq   r    s    *8 8r   rq   r  r   )backlogs	   test datas   rogerc                      	 t        j                          } j                  |       } | j                         | j                         | j	                  d      | j                          y # t        $ r}t        d|       Y d }~y d }~ww xY w)Nc   z8Failure in client thread in test_connect_accepted_socket)r2  wrap_socketconnectsendallr#  rA   	Exceptionprint)csockr=   r   
client_sslmessageresponses     r   r  z@EventLoopTestsMixin.test_connect_accepted_socket.<locals>.client  sz    )&2259Ed#g& ::b> N s   A*A. .	B7BBT)r   daemonrx  c                       S r   r   protos   r   r.  zBEventLoopTestsMixin.test_connect_accepted_socket.<locals>.<lambda>  s     r   r  rm   )r2   rH   r2  create_servergetsocknamer   r  r  acceptr1   connect_accepted_socketr   rL   rA   r   join_threadr  is_aliver   rM   rN   re   )r7   
server_sslr  rq   lsockr  threadconn_r   r  r2   r  r  r  s     `      @@@@@@r   test_connect_accepted_socketz0EventLoopTestsMixin.test_connect_accepted_socket  s<   yy	8k 	8 $$%5qA  "$	 !!=,,.aT"
((: ) 7	8 	$$V,*+h/s7|4#45r   c                 x    t        j                         }t        j                         }| j                  ||       y r   )r   simple_server_sslcontextsimple_client_sslcontextr  )r7   server_contextclient_contexts      r    test_ssl_connect_accepted_socketz4EventLoopTestsMixin.test_ssl_connect_accepted_socket  s.    #<<>#<<>))..Ir   c                 N   t        j                          }| j                  |j                         | j                  j	                  t
        |t        j                        }| j                  t        d      5  | j                  j                  |       d d d        y # 1 sw Y   y xY w)N)ssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)r2  
addCleanuprA   r2   r  rq   r   LOOPBACK_TIMEOUTassertRaisesRegexrN  r1   )r7   sockcoros      r   9test_connect_accepted_socket_ssl_timeout_for_plain_socketzMEventLoopTestsMixin.test_connect_accepted_socket_ssl_timeout_for_plain_socket  s    }}

#yy00T1I1I 1 K##CE 	/ II((.	/ 	/ 	/s   6BB$zasyncio.base_events.socketc                     fd fd}t        |      }t        j                  k(  r0|D cg c]  }|df c}|j                         j                  _        n1|D cg c]  }|dddf
 c}|j                         j                  _        | j
                  _        t        j                          j
                  _	        t        j                          j
                  _
         j
                  j                   fd|d      } j
                  j                  |      } j                  |j                         |j                  D 	ch c]  }	|	j                         d    }
}	 j!                  |
|       y c c}w c c}w c c}	w )Nc                    K   t         j                  k(  rt         j                  dd| |ffgS t         j                  dd| |ddffgS w)Nr1  r  r   )r2  r  r  )r  r  r  kwfamilys       r   r  zEEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfo"  sT     '!3!3QT4LIJJ!3!3QT4A<NOPPs   AA	c                  F    j                   j                   | i |      S r   )r2   create_task)r  kwdsr  r7   s     r   getaddrinfo_taskzJEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfo_task(  s"    99((d)Cd)CDDr   P   r   c                  .    t         j                        S r   ry  r@   s   r   r.  zBEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<lambda>6  s    GDII,> r   )r   r2  r  getsockbynamer  r2   r  r   Mock_start_serving_stop_servingr  r1   r  rA   socketsr   )r7   r  hosts	mock_sockr  unique_hostsr  r  serverr  server_hostsr  s   ``         @r   create_server_multiple_hostsz0EventLoopTestsMixin.create_server_multiple_hosts   s5   	Q	E 5zV^^#'3<5#r
<5I,,8 .:<;%)r1a <;I,,8 0		#'99;		 "&))+		II##$>rJ--a0%<BNNKD**,Q/KK|4<5<; Ls   E8!E=	Fc                 H    | j                  t        j                  g d       y )N)1.2.3.4z5.6.7.8r*  )r(  r2  r  r@   s    r   &test_create_server_multiple_hosts_ipv4z:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv4<  s    ))&..*K	Mr   c                 H    | j                  t        j                  g d       y )N)r  z::2r  )r(  r2  r  r@   s    r   &test_create_server_multiple_hosts_ipv6z:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv6@  s    ))&//*?	Ar   c                 n   t        | j                        | j                  j                  fddd      }| j                  j                  |      }| j	                  t        |j                        d       |j                  d   }|j                         \  }}| j	                  |d       t        j                         }|j                  d|f       |j                  d       | j                  j                  j                         | j	                  dj                         t        j                  | j                  fd       | j	                  d	j                         | j!                  j"                  j%                  d
             | j	                  dj"                  j%                  d      d          j"                  j'                          | j                  j                  j(                         | j	                  dj                         |j'                          |j'                          y )Nc                       S r   r   r  s   r   r.  z8EventLoopTestsMixin.test_create_server.<locals>.<lambda>F      E r   0.0.0.0r   r   r     xxxr]   c                  "     j                   dkD  S r   rN   r  s   r   r.  z8EventLoopTestsMixin.test_create_server.<locals>.<lambda>S      q0@ r   r   rh  r  rm   )rq   r2   r  r1   r   re   r"  r  r2  r  r  rP   rM   r   r7  rN   rm  rL   rn  rA   rQ   )r7   r  r&  r  r  r  r  r  s          @r   test_create_serverz&EventLoopTestsMixin.test_create_serverD  s   		"II##M9a@--a0V^^,a0~~a %%'
dy)T*+v		$$U__5ekk2TYY(@AELL) 	U__;;JGH77
CAF	H 			$$UZZ05;;/ 	 	r   c                    t        | j                        | j                  j                  fddd      }| j                  j                  |      }| j	                  t        |j                        d       |j                  d   }| j                  |t        j                  j                         |j                         \  }}| j	                  |d       |j                         }| j                  |j                         | j                  |t        j                         | j!                  |j#                                | j%                  t&              5  |j)                  d       d d d        |j)                  d       | j	                  |j+                         d       | j%                  t&              5  |j-                  d       d d d        |j-                  d       |j                          y # 1 sw Y   xY w# 1 sw Y   7xY w)Nc                       S r   r   r  s   r   r.  z?EventLoopTestsMixin.test_create_server_trsock.<locals>.<lambda>j  r0  r   r1  r   r   TF)rq   r2   r  r1   r   re   r"  ri  r   trsockTransportSocketr  dupr  rA   r2  r  get_inheritabler   rN  
settimeout
gettimeoutr4  )r7   r  r&  r  r  r  r;  r  s          @r   test_create_server_trsockz-EventLoopTestsMixin.test_create_server_trsockh  s   		"II##M9a@--a0V^^,a0~~a dGNN$B$BC%%'
dy)hhj		"c6==1--/0z* 	OOA	*A.z* 	#T"	#	 		# 	#s   G04G<0G9<HSO_REUSEPORTzNo SO_REUSEPORTc                    t        | j                        | j                  j                  fddd      }| j                  j                  |      }| j	                  t        |j                        d       |j                  d   }| j                  |j                  t        j                  t        j                               |j                          t        j                  | j                         t        | j                        | j                  j                  fdddd      }| j                  j                  |      }| j	                  t        |j                        d       |j                  d   }| j                  |j                  t        j                  t        j                               |j                          y )Nc                       S r   r   r  s   r   r.  zCEventLoopTestsMixin.test_create_server_reuse_port.<locals>.<lambda>      E r   r1  r   r   c                       S r   r   r  s   r   r.  zCEventLoopTestsMixin.test_create_server_reuse_port.<locals>.<lambda>  rC  r   T)
reuse_port)rq   r2   r  r1   r   re   r"  r  
getsockoptr2  
SOL_SOCKETr@  rA   r   r   r   )r7   r  r&  r  r  s       @r   test_create_server_reuse_portz1EventLoopTestsMixin.test_create_server_reuse_port  sN   		"II##9a)--a0V^^,a0~~a OO!!6#6#68	9 	tyy)		"II##9aD $ :--a0V^^,a0~~a OO!!6#6#68	9 	r   c                     t        j                         | j                  fd        | j                  j                  |fi |}| j                  j                  |      }|fS )Nc                  p    t         j                  j                         xr t        j                         S r   )rR  pathexistsunlink)rK  s   r   r.  z7EventLoopTestsMixin._make_unix_server.<locals>.<lambda>  s!    t 4 H4 r   )r   gen_unix_socket_pathr  r2   create_unix_serverr1   )r7   factoryr  r  r&  rK  s        @r   _make_unix_serverz%EventLoopTestsMixin._make_unix_server  sY    ..0HI(DII(($A&A--a0t|r   c                 *   t        | j                        | j                  fd      \  }}| j                  t	        |j
                        d       t        j                  t        j                        }|j                  |       |j                  d       | j                  j                  j                         | j                  dj                         t        j                  | j                  fd       | j                  dj                         j                   j#                          | j                  j                  j$                         | j                  dj                         |j#                          |j#                          y )	Nrx  c                       S r   r   r  s   r   r.  z=EventLoopTestsMixin.test_create_unix_server.<locals>.<lambda>  s    e r   r   r2  r]   c                  "     j                   dkD  S r   r4  r  s   r   r.  z=EventLoopTestsMixin.test_create_unix_server.<locals>.<lambda>  r5  r   r   rm   )rq   r2   rQ  r   re   r"  r2  AF_UNIXr  r  r1   rP   rM   r   r7  rN   rL   rA   rQ   )r7   r&  rK  r  r  s       @r   test_create_unix_serverz+EventLoopTestsMixin.test_create_unix_server  s   TYY'--m<V^^,a0v~~.tv		$$U__5ekk2TYY(@AELL) 			$$UZZ05;;/ 	 	r   rU  zNo UNIX Socketsc                 V   t        | j                        t        j                         }|5  | j                  j                  fdd|      }| j	                  t
        d      5  | j                  j                  |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nrx  c                       S r   r   r  s   r   r.  zOEventLoopTestsMixin.test_create_unix_server_path_socket_error.<locals>.<lambda>  s    U r   z/testr  z3path and sock can not be specified at the same time)rq   r2   r2  rO  r  rN  r1   )r7   r  r  r  s      @r   )test_create_unix_server_path_socket_errorz=EventLoopTestsMixin.test_create_unix_server_path_socket_error  s    TYY'}} 	0		,,]G$,OA''
);< 0 		,,Q/0	0 	00 0	0 	0s#   8B&BBB	BB(c                     t        j                  t         j                        }|xj                  t         j                  z  c_        |j                  ||       |S r   )r  
SSLContextPROTOCOL_TLS_SERVERoptionsOP_NO_SSLv2load_cert_chain)r7   certfilekeyfile
sslcontexts       r   _create_ssl_contextz'EventLoopTestsMixin._create_ssl_context  sA    ^^C$;$;<
coo-""8W5r   c                    | j                  ||      }| j                  j                  |dd|      }| j                  j                  |      }|j                  d   }|j                         \  }}	| j                  |d       |||	fS )Nr  r   r  )rd  r2   r  r1   r"  r  r   )
r7   rP  ra  rb  rc  r  r&  r  r  r  s
             r   _make_ssl_serverz$EventLoopTestsMixin._make_ssl_server  s    --h@
II##G[!#L--a0~~a %%'
d{+tT!!r   c                 L    | j                  ||      }| j                  ||      S )Nr  )rd  rQ  )r7   rP  ra  rb  rc  s        r   _make_ssl_unix_serverz)EventLoopTestsMixin._make_ssl_unix_server  s*    --h@
%%g:%>>r   c                    t        | j                        | j                  fdt        j                  t        j
                        \  }}}| j                  j                  t        ||t        j                               }| j                  j                  |      \  }}|j                  d       | j                  j                  j                         | j                  dj                         t        j                  | j                  fd       | j                  dj                         | j!                  |||f       j"                  j%                          | j                  j                  j&                         | j                  d	j                         |j%                          |j%                          y )
Nrx  c                       S r   r   r  s   r   r.  z<EventLoopTestsMixin.test_create_server_ssl.<locals>.<lambda>  rC  r   r  r2  r]   c                  "     j                   dkD  S r   r4  r  s   r   r.  z<EventLoopTestsMixin.test_create_server_ssl.<locals>.<lambda>  r5  r   r   r  rm   )rq   r2   rf  r   ONLYCERTONLYKEYr|  rH   r  r1   rt   rP   r   rM   r7  rN   r  rL   rA   rQ   )r7   r&  r  r  f_cr  rs  r  s          @r   test_create_server_sslz*EventLoopTestsMixin.test_create_server_ssl  sL   TYY'!22:..
0B0BDd ii))+tT.8.J.J.L * NYY11#6
V		$$U__5ekk2TYY(@AELL) 	!!&D$<!@ 			$$UZZ05;;/ 	 	r   c                 Z   t        | j                        | j                  fdt        j                  t        j
                        \  }}| j                  j                  t        |t        j                         d      }| j                  j                  |      \  }}|j                  d       | j                  j                  j                         | j                  dj                         t        j                  | j                  fd       | j                  dj                         j                   j#                          | j                  j                  j$                         | j                  d	j                         |j#                          |j#                          y )
Nrx  c                       S r   r   r  s   r   r.  zAEventLoopTestsMixin.test_create_unix_server_ssl.<locals>.<lambda>  rC  r   r  r  r  r2  r]   c                  "     j                   dkD  S r   r4  r  s   r   r.  zAEventLoopTestsMixin.test_create_unix_server_ssl.<locals>.<lambda>  r5  r   r   rm   )rq   r2   rh  r   rl  rm  r  rH   r  r1   rt   rP   r   rM   r7  rN   rL   rA   rQ   )r7   r&  rK  rn  r  rs  r  s         @r   test_create_unix_server_sslz/EventLoopTestsMixin.test_create_unix_server_ssl  s4    TYY'11:..
0B0BD ii..:#?#?#A /   YY11#6
V		$$U__5ekk2TYY(@AELL) 			$$UZZ05;;/ 	 	r   c                    t        | j                        | j                  fdt        j                        \  }}}t        j                  t
        j                        }|xj                  t
        j                  z  c_        t
        j                  |_        t        |d      rd|_        | j                  j                  t         |||      }t        j                   j#                  | j                  d      5  t        j$                         5  | j'                  t
        j(                  d      5  | j                  j+                  |       d d d        d d d        t        j,                  | j                         d d d        | j/                  j0                         |j3                          y # 1 sw Y   dxY w# 1 sw Y   hxY w# 1 sw Y   MxY w)Nrx  c                       S r   r   r  s   r   r.  zJEventLoopTestsMixin.test_create_server_ssl_verify_failed.<locals>.<lambda>!  rC  r   check_hostnameTr  call_exception_handler(?i)certificate.verify.failed)rq   r2   rf  r   SIGNED_CERTFILEr  r\  PROTOCOL_TLS_CLIENTr^  r_  CERT_REQUIREDverify_moder  rw  r|  r   r  objectr  r  r  r1   r   assertIsNonerL   rA   )r7   r&  r  r  sslcontext_clientrn  r  s         @r   $test_create_server_ssl_verify_failedz8EventLoopTestsMixin.test_create_server_ssl_verify_failed  sg   TYY'!22:557d  NN3+B+BC!!S__4!(+(9(9%$&67/3, ii))'4.? * AZZtyy*BC 	.**, 6++CLL,KM 6II00566 ""499-	. 	%//*6 66 6	. 	.s<   :G!F;0F/F;'G/F84F;;G	 GGc                    t        | j                        | j                  fdt        j                        \  }}t        j                  t
        j                        }|xj                  t
        j                  z  c_        t
        j                  |_        t        |d      rd|_        | j                  j                  t         ||d      }t        j                   j#                  | j                  d      5  t        j$                         5  | j'                  t
        j(                  d      5  | j                  j+                  |       d d d        d d d        t        j,                  | j                         d d d        | j/                  j0                         |j3                          y # 1 sw Y   dxY w# 1 sw Y   hxY w# 1 sw Y   MxY w)	Nrx  c                       S r   r   r  s   r   r.  zOEventLoopTestsMixin.test_create_unix_server_ssl_verify_failed.<locals>.<lambda>?  rC  r   rw  Tinvalidrr  rx  ry  )rq   r2   rh  r   rz  r  r\  r{  r^  r_  r|  r}  r  rw  r  r   r  r~  r  r  r  r1   r   r  rL   rA   )r7   r&  rK  r  rn  r  s        @r   )test_create_unix_server_ssl_verify_failedz=EventLoopTestsMixin.test_create_unix_server_ssl_verify_failed:  si    TYY'11:557  NN3+B+BC!!S__4!(+(9(9%$&67/3, ii..w3D?H / J ZZtyy*BC 	.**, 6++CLL,KM 6II00566 ""499-	. 	%//*6 66 6	. 	.s<   9G!F:/F.F:'G.F73F::G	?GGc                    t        | j                        | j                  fdt        j                        \  }}}t        j                  t
        j                        }|xj                  t
        j                  z  c_        t
        j                  |_        |j                  t        j                         t        |d      rd|_        | j                  j!                  t         |||      }t#        j$                  dt"        j&                        }t(        j*                  j-                  | j                  d      5  t        j.                         5  | j1                  t
        j2                  |      5  | j                  j5                  |       d d d        d d d        d d d        | j7                  j8                         |j;                          y # 1 sw Y   ExY w# 1 sw Y   IxY w# 1 sw Y   MxY w)	Nrx  c                       S r   r   r  s   r   r.  zIEventLoopTestsMixin.test_create_server_ssl_match_failed.<locals>.<lambda>\  rC  r   r  rw  Tr  z(
            IP address mismatch, certificate is not valid for '127.0.0.1'   # OpenSSL
            |
            CERTIFICATE_VERIFY_FAILED                                       # AWS-LC
        )rx  )rq   r2   rf  r   rz  r  r\  r{  r^  r_  r|  r}  load_verify_locations
SIGNING_CAr  rw  r|  recompileXr   r  r~  r  r  CertificateErrorr1   r  rL   rA   )r7   r&  r  r  r  rn  regexr  s          @r   #test_create_server_ssl_match_failedz7EventLoopTestsMixin.test_create_server_ssl_match_failedX  s   TYY'!22:557d  NN3+B+BC!!S__4!(+(9(9%//(( 	0 	*$&67/3, ii))'4.? * A 

  dd	
 ZZtyy*BC 	6**, 6++C,@,@%H 6II00566	6 	%//*6 66 6	6 	6s<   >G,!G 4GG G,GG  G)	%G,,G5c                 $   t        | j                        | j                  fdt        j                        \  }}t        j                  t
        j                        }|xj                  t
        j                  z  c_        t
        j                  |_        |j                  t        j                         t        |d      rd|_        | j                  j!                  t         ||d      }| j                  j#                  |      \  }}| j                  j#                  j$                         j&                  j)                          |j)                          |j)                          | j                  j#                  j*                         y )Nrx  c                       S r   r   r  s   r   r.  zJEventLoopTestsMixin.test_create_unix_server_ssl_verified.<locals>.<lambda>  rC  r   r  rw  Tr  rr  )rq   r2   rh  r   rz  r  r\  r{  r^  r_  r|  r}  r  r  r  rw  r  r1   rP   rL   rA   rQ   )r7   r&  rK  r  rn  r  rs  r  s          @r   $test_create_unix_server_ssl_verifiedz8EventLoopTestsMixin.test_create_unix_server_ssl_verifiedz  s)    TYY'11:557  NN3+B+BC!!S__4!(+(9(9%//z7L7L/M$&67/3, ii..w3D?J / L YY11#6
		$$U__5 			$$UZZ0r   c                 p   t        | j                        | j                  fdt        j                        \  }}}t        j                  t
        j                        }|xj                  t
        j                  z  c_        t
        j                  |_        |j                  t        j                         t        |d      rd|_        | j                  j!                  t         |||d      }| j                  j#                  |      \  }}| j                  j#                  j$                         | j'                  |||ft        j(                         j*                  j-                          |j-                          |j-                          | j                  j#                  j.                         y )	Nrx  c                       S r   r   r  s   r   r.  zEEventLoopTestsMixin.test_create_server_ssl_verified.<locals>.<lambda>  rC  r   r  rw  Tr  rr  )r  r  )rq   r2   rf  r   rz  r  r\  r{  r^  r_  r|  r}  r  r  r  rw  r|  r1   rP   r  PEERCERTrL   rA   rQ   )	r7   r&  r  r  r  rn  r  rs  r  s	           @r   test_create_server_ssl_verifiedz3EventLoopTestsMixin.test_create_server_ssl_verified  sS   TYY'!22:557d  NN3+B+BC!!S__4!(+(9(9%//z7L7L/M$&67/3, ii))'4.?:E * G YY11#6
		$$U__5 	!!&D$<+5+>+> 	" 	@ 			$$UZZ0r   c                 j  	 | j                   j                         	 G 	fddt              }t        j                  d      }| j                   j	                  ||      }| j                   j                  |      }|j                  d   }| j                  |j                         |j                                |j                         \  }}| j                  |d       t        j                         }|j                  d|f       |j                  d       |j                          |j                          y )	Nc                   "     e Zd Z fdZ xZS )@EventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProtoc                 F    t         |   |       j                  |        y r   rs   ra   r_   )r7   rL   ru   r  s     r   ra   zPEventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProto.connection_made  s    '	2  &r   rv   )ru   r  s   @r   TestMyProtor    s    ' 'r   r  r1  r   rY  r   r1  r  r2  )r2   rO   rq   r2  r  r1   r"  r   r'  r  r  r9   rA   )
r7   r  sock_obr  r&  r  r  r  r  r  s
            @r   test_create_server_sockz+EventLoopTestsMixin.test_create_server_sock  s    		'')	'' 	'
 &&~6II##Kg#>--a0~~a (89%%'
dy)T*+Fr   c                 @   t        j                  d      }| j                  j                  t        |      }| j                  j	                  |      }|j
                  d   }|j                         \  }}| j                  j                  t        ||      }| j                  t              5 }| j                  j	                  |       d d d        | j                  j                  j                  t        j                         |j                          y # 1 sw Y   NxY w)Nr  rY  r   r  r  )r2  r  r2   rq   r1   r"  r  r   r  r   r  r  r  rA   )r7   r  r  r&  r  r  r  r  s           r   test_create_server_addr_in_usez2EventLoopTestsMixin.test_create_server_addr_in_use  s    &&~6II##G'#:--a0~~a %%'
dII##G$T#Bw' 	,2II((+	,++U-=-=>		, 	,s   +DDzIPv6 not supported or enabledc                   	 | j                   j                         	 G 	fddt              }d}	 	 t        j                         }| j                   j                  |d |      }| j                   j                  |      }	 t        j                         }|j                  d|f       |j                  d       | j                   j                  	      }|j                  j                          |j                          | j                   j                         	t        j                  t        j                         }|j                  d	|f       |j                  d       | j                   j                  	      }|j                  j                          |j                          |j                          y # t        $ r@}|j                  t        j                  k(  r|dz  }| j                  d|       Y d }~ǂ d }~ww xY w)
Nc                   "     e Zd Z fdZ xZS )FEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProtoc                 F    t         |   |       j                  |        y r   r  )r7   rL   ru   f_protos     r   ra   zVEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProto.connection_made  s    '	2""4(r   rv   )ru   r  s   @r   r  r    s    ) )r   r  r   r  r   r   r  r2  r  )r2   rO   rq   r   r  r  r1   r  r  r  r   r2  r  r9   rL   rA   r  )
r7   r  	try_countr  r  r&  exr  r  r  s
            @r   test_create_server_dual_stackz1EventLoopTestsMixin.test_create_server_dual_stack  s   ))))+	)' 	)
 	$557II++Kd+N55a8 T*+F		,,W5))))+v/t}%F		,,W51  88u///NI++Ay9s   AF3 3	G<<4G76G77G<c                    | j                   j                  t        dd      }| j                   j                  |      }|j                  d   }|j                         \  }}t        j                         }|j                  d|f       |j                  d       |j                          |j                          t        j                         }| j                  t        |j                  d|f       |j                          y )Nr1  r   r  r2  )r2   r  rq   r1   r"  r  r2  r  r9   rA   r   ConnectionRefusedError)r7   r  r&  r  r  r  r  s          r   test_server_closez%EventLoopTestsMixin.test_server_close  s    II##GY:--a0~~a %%'
dT*+F"FNN[$4G	Ir   c                    
  G  fddt               } j                  j                  |||      } j                  j                  |      \  }|j	                  d      }t        j                  |t
        j                  t
        j                  z        \  }} j                  |t        j                          j                  |        j                  dj                          j                  j                  |        j                  j                   fd||f      } j                  j                  |      \  }	
 j                  |	t        j                          j                  
t                 j                  d
j                          j                  
j                  |	       |	j!                  d       t#        j$                   j                  fd	        j                  d
j&                         t#        j$                   j                  
fd        j                  d
j&                          j)                  |	j	                  d             |	j+                           j                  j                  
j,                          j                  d
j                         j                  j+                          y )Nc                   ,     e Zd Z fdZ fdZ xZS )OEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.TestMyDatagramProtoc                 :    t         |   j                         y rw  )rs   rS   r2   )
inner_selfru   r7   s    r   rS   zXEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.TestMyDatagramProto.__init__  s     dii 0r   c                 d    t         |   ||       | j                  j                  d|z   |       y )Ns   resp:)rs   r   rL   sendto)r7   rg   r   ru   s      r   r   zaEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.TestMyDatagramProto.datagram_received  s*    )$5%%htmT:r   )rD   rE   rF   rS   r   rw   )ru   r7   s   @r   TestMyDatagramProtor    s    1; ;r   r  )r  r  rh  r   c                  0    t         j                        S rw  rz   r2   r@   s   r   r.  zDEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.<lambda>+      O3 r   )remote_addrr2  c                       j                   S r   r4  )r&  s   r   r.  zDEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.<lambda>5       r   r   c                       j                   S r   r4  )r  s   r   r.  zDEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.<lambda>7  r  r      rm   )rz   r2   create_datagram_endpointr1   rn  r2  getnameinfoNI_NUMERICHOSTNI_NUMERICSERVri  r   rj  r   rM   rl  rL   r  r   r7  rN   rm  rA   rQ   )r7   r  r  r  r  s_transportrh  r  r  rL   r  r&  s   `         @@r   _test_create_datagram_endpointz2EventLoopTestsMixin._test_create_datagram_endpoint  s(   	;/ 	; yy11Jv 2 G"ii::4@V--j9''f++F,A,AAC
d 	k7+<+<=f&9:5f&&4yy113t 2 & !II88>	6i):):;fo65f&&	2 TYY(=>FMM*TYY(=> 	FMM* 	Y55jAB 			$$V[[16<<0 r   c                 D    | j                  dt        j                         y )Nr  )r  r2  r  r@   s    r   test_create_datagram_endpointz1EventLoopTestsMixin.test_create_datagram_endpointE  s    ++,<fnnMr   c                 D    | j                  dt        j                         y )N)r  r   )r  r2  r  r@   s    r   "test_create_datagram_endpoint_ipv6z6EventLoopTestsMixin.test_create_datagram_endpoint_ipv6H  s    ++JHr   c                     d }d} j                   j                    j                   j                  |dt        j                  i      }|D ]D  \  }}}}}	 t        j                  |||      }|j                  d       |j                  |        n  j                  d        j                   j                   fd|      }	 j                   j                  |	      \  }
} j                  |
t        j                          j                  |t               |
j                           j                   j                  |j                         y #  Y xY w)Nr  type)r  r  r  FzCan not create socket.c                  0    t         j                        S rw  r  r@   s   r   r.  zHEventLoopTestsMixin.test_create_datagram_endpoint_sock.<locals>.<lambda>_  r  r   rY  )r2   r1   r  r2  
SOCK_DGRAMr4  bindfailr  ri  r   rj  rz   rA   rQ   )r7   r  local_addressinfosr  r  r  cnamer}  r  rr  rs  s   `           r   "test_create_datagram_endpoint_sockz6EventLoopTestsMixin.test_create_datagram_endpoint_sockL  s-   (		,,!DII!!8%+%6%689 49 
	0/FD%}}FUK  '		'" 
	0 II./II..3$ / @--a0Bb'"3"34b/2

		$$RWW-s   :EEc                    | j                    G fddt        j                        }d } |       }j                  j	                  ||            \  }}|j                         } |       }j                  j	                  ||            \  }}	|j                         }
 |       }j                  j	                  ||            \  }}|j                         }|j                          |j                  d|
       | j                  j                  |	j                               d       |j                  d|       | j                  j                  |j                               d       |j                  d|       j                  t        j                  d	             |j                  d
|       | j                  j                  |j                               d
       |j                          |j                          y )Nc                   "    e Zd ZdZd Z fdZy)QEventLoopTestsMixin.test_datagram_send_to_non_listening_address.<locals>.ProtocolNc                 :    | j                   j                  |       y r   )_received_datagramr_   r   s      r   r   zcEventLoopTestsMixin.test_datagram_send_to_non_listening_address.<locals>.Protocol.datagram_receivedt  s    ''2248r   c                    K   j                         | _        t        j                  | j                  d       d {   }d | _        |S 7 w)Nr   )rO   r  r   wait_for)r7   resultr2   s     r   wait_for_datagram_receivedzlEventLoopTestsMixin.test_datagram_send_to_non_listening_address.<locals>.Protocol.wait_for_datagram_receivedw  sF     *.*<*<*>'&//0G0GLL*.' Ms   9AA
A)rD   rE   rF   r  r   r  rx  s   r   rk  r  p  s    !%9r   rk  c                      t        j                   t         j                  t         j                        } | j                  d       | j	                  d       | S )NFr  )r2  r  r  r4  r  rY  s    r   create_socketzVEventLoopTestsMixin.test_datagram_send_to_non_listening_address.<locals>.create_socket}  s<    ==1B1BCDU#II&'Kr   rY     a)r      b   cr      d)r2   r   DatagramProtocolr1   r  r  abortr  r   r  r   rA   )r7   rk  r  socket_1transport_1
protocol_1addr_1socket_2transport_2
protocol_2addr_2socket_3transport_3
protocol_3addr_3r2   s                  @r   +test_datagram_send_to_non_listening_addressz?EventLoopTestsMixin.test_datagram_send_to_non_listening_addressf  s    yy	w// 		 !?"&"9"9))()B#
Z %%' ?"&"9"9))()B#
Z %%' !?"&"9"9))()B#
Z %%'4f-00113
	 	4f-00113
	
 	4f-a 01 	4f-00113
	 	r   c                    | j                         }t        |t        j                        s!|j	                          | j                  d       | j                  d|j                         |j	                          | j                  d|j                         | j                  |j                         | j                  |j                         y )Nz#loop is not a BaseSelectorEventLoopr   r   )r   
isinstancer   BaseSelectorEventLooprA   skipTestr   _internal_fdsr  _csock_ssockrR   s     r   test_internal_fdsz%EventLoopTestsMixin.test_internal_fds  s    %%'$ E EFJJLMM?@D../

D../$++&$++&r   r   zDon't support pipes for Windowsc                 t    t         j                        t        j                         \  }}t	        j
                  |dd       fd} j                  j                   |              t        j                  |d       t        j                   j                  fd        j                  dj                         t        j                  |d       t        j                   j                  fd	        j                  d
dgj                          j                  dj                         t        j                  |        j                  j                  j                          j                  g dj                          j                  j                   j#                  d             y )Nrx  rbr"  c                  6  K   j                   j                  fd       d {   \  } }j                  |       j                  | j                         j	                  ddgj
                         j	                  dj                         y 7 pw)Nc                       S r   r   r  s   r   r.  zEEventLoopTestsMixin.test_read_pipe.<locals>.connect.<locals>.<lambda>  s     r   rK   r]   r   r2   connect_read_piperl  rL   r   rM   rN   )r  ppipeobjr  r7   s     r   r  z3EventLoopTestsMixin.test_read_pipe.<locals>.connect  s{     44w( (DAqMM!U#MM!U__-i5u{{CQ-(   #BBA1B   1c                  "     j                   dk\  S rD  r4  r  s   r   r.  z4EventLoopTestsMixin.test_read_pipe.<locals>.<lambda>      0A r   r      2345c                  "     j                   dk\  S Nr   r4  r  s   r   r.  z4EventLoopTestsMixin.test_read_pipe.<locals>.<lambda>  r  r   rK   r]   r   rK   r]   rj   rm   pipe)r   r2   rR  r	  ioopenr1   rt   r   r7  r   rN   rM   rA   rQ   rm  rL   rn  )r7   rpipewpiper  r   r  s   `   @@r   test_read_pipez"EventLoopTestsMixin.test_read_pipe  s.     TYY/wwyu''%t,	. 			$$WY/
TYY(ABELL)
 TYY(AB)[15;;?ELL)
		$$UZZ05u{{	D 	U__;;FCDr   c                   	
 | j                         t              t              
t        j                         \  }}t        j                  |dd      t        j                  |ddd      		
fd}j                   |             \  }}j                          | j                  dt        |             | j                  dt        |             j                          	j                          d |_        d |_        y )	Nrx  r  r"  r8  zutf-8)encodingc                     K   j                  fd       d {   \  } }j                  fd       d {   \  }}| |fS 7 +7 w)Nc                       S r   r   
read_protos   r   r.  zSEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect.<locals>.<lambda>  s    
 r   c                       S r   r   write_protos   r   r.  zSEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect.<locals>.<lambda>  s     r   )r  connect_write_pipe)read_transportr  write_transportr2   r  rpipeobjwpipeobjr  s      r   r  zAEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect  s[     &*&<&<"H'. !.NA'+'>'>#X(/ "/OQ!?22	!."/s   AAAA
A
Ar  )r   r   r   rR  r	  r
  r  r1   rA   r  repr_pipe)r7   r  r  r  r  r  r2   r  r  r  r  s         @@@@@r   test_unclosed_pipe_transportz0EventLoopTestsMixin.test_unclosed_pipe_transport  s     %%'$$/
&D1wwyu775$-775#tg>	3 	3 +/*A*A')*L'

 	fd>23fd?34 	# $r   openptyzneed os.openpty()c                     t         j                        t        j                         \  }}t	        j
                  |dd       fd} j                  j                   |              t        j                  |d       t        j                   j                  fd        j                  dj                         t        j                  |d       t        j                   j                  fd	        j                  d
dgj                          j                  dj                         t        j                  |       j                  j                           j                  j                  j                          j                  g dj                          j!                  j                  j#                  d             y )Nrx  r  r   c                  6  K   j                   j                  fd       d {   \  } }j                  |       j                  | j                         j	                  ddgj
                         j	                  dj                         y 7 pw)Nc                       S r   r   r  s   r   r.  zKEventLoopTestsMixin.test_read_pty_output.<locals>.connect.<locals>.<lambda>
  s    U r   rK   r]   r   r  )r  r  master_read_objr  r7   s     r   r  z9EventLoopTestsMixin.test_read_pty_output.<locals>.connect	  s~     44]5DF FDAqMM!U#MM!U__-i5u{{CQ-Fr  r  c                       j                   S r   r4  r  s   r   r.  z:EventLoopTestsMixin.test_read_pty_output.<locals>.<lambda>  s     r   r   r  c                  "     j                   dk\  S r  r4  r  s   r   r.  z:EventLoopTestsMixin.test_read_pty_output.<locals>.<lambda>  r  r   rK   r]   r   r  r	  )r   r2   rR  r   r
  r  r1   rt   r   r7  r   rN   rM   rA   rL   rQ   rm  rn  )r7   masterslaver  r$  r  s   `   @@r   test_read_pty_outputz(EventLoopTestsMixin.test_read_pty_output   s>     TYY/

''&$2	. 			$$WY/
TYY(<=ELL)
 TYY(AB)[15;;?ELL)
		$$UZZ05u{{	D 	U__;;FCDr   c                 H  	 t        j                         \  	}t        j                  |dd      }t	        | j
                        | j
                  j                  fd|      }| j
                  j                  |      \  }}| j                  |       | j                  |j                         | j                  dj                         |j                  d       t               	fdt        j                  | j
                  fd       | j                  d       |j                  d	       t        j                  | j
                  fd
       | j                  d       | j                  dj                         t        j                   	       | j#                  j                  j%                  d             j                  j!                          | j
                  j                  j&                         | j                  dj                         y )Nwbr"  rx  c                       S r   r   r  s   r   r.  z5EventLoopTestsMixin.test_write_pipe.<locals>.<lambda>+      u r   r]   r  c                 P    t        j                  d      }| |z  } t        |       S r!  rR  r?  re   )rg   chunkr  s     r   r*  z3EventLoopTestsMixin.test_write_pipe.<locals>.reader4  s&    GGE4(EEMDt9r   c                              dk\  S rD  r   rg   r*  s   r   r.  z5EventLoopTestsMixin.test_write_pipe.<locals>.<lambda>9      t0A r   r  c                              dk\  S r  r   r2  s   r   r.  z5EventLoopTestsMixin.test_write_pipe.<locals>.<lambda>=  r3  r      12345r	  rm   )rR  r	  r
  r  r   r2   r  r1   rl  rL   r   rM   rt   r5  r   r7  rA   rm  rn  rQ   )
r7   r  r   r  rL   r  rg   r  r*  r  s
         @@@@r   test_write_pipez#EventLoopTestsMixin.test_write_pipe$  s    wwyu''%t, dii0))..}gFyy33G<	1ai1ekk2{	
 	TYY(ABt$ TYY(AB4(ekk2
 	U__;;FCD 			$$UZZ05;;/r   c                 ,   t        j                         \  }}|j                  d       t        j                  |j                         dd      }t        | j                        | j                  j                  fd|      }| j                  j                  |      \  }}| j                  |       | j                  |j                         | j                  dj                         |j                  d       | j                  j                  | j                  j                  |d            }| j                  d|       |j!                          | j                  j                  j"                         | j                  dj                         y )	NFr+  r"  rx  c                       S r   r   r  s   r   r.  zIEventLoopTestsMixin.test_write_pipe_disconnect_on_close.<locals>.<lambda>S  r-  r   r]   r  rm   )r2  r3  r4  r
  r  detachr   r2   r  r1   rl  rL   r   rM   rt   	sock_recvrA   rQ   )	r7   rsockwsockr   r  rL   r  rg   r  s	           @r   #test_write_pipe_disconnect_on_closez7EventLoopTestsMixin.test_write_pipe_disconnect_on_closeK  s!    ((*u% ''%,,.$5 dii0))..}gFyy33G<	1ai1ekk2yy++DII,?,?t,LMt$		$$UZZ05;;/r   r   r1  c                   	 t        j                         \  }t        j                  |dd      }t	        | j
                        | j
                  j                  fd|      }| j
                  j                  |      \  }}| j                  |       | j                  |j                         | j                  dj                         |j                  d       t               fd	t        j                  | j
                  	fdt         j"                  	       | j                  d       |j                  d
       t        j                  | j
                  	fdt         j"                  	       | j                  d       | j                  dj                         t        j$                         | j'                  j                  j)                  d             j                  j%                          | j
                  j                  j*                         | j                  dj                         y )Nr+  r   rx  c                       S r   r   r  s   r   r.  z4EventLoopTestsMixin.test_write_pty.<locals>.<lambda>m  r-  r   r]   r  c                 P    t        j                  d      }| |z  } t        |       S r!  r/  rg   r0  r'  s     r   r*  z2EventLoopTestsMixin.test_write_pty.<locals>.readerv  &    GGFD)EEMDt9r   c                              dk\  S rD  r   r2  s   r   r.  z4EventLoopTestsMixin.test_write_pty.<locals>.<lambda>{  r3  r   timeoutr  c                              dk\  S r  r   r2  s   r   r.  z4EventLoopTestsMixin.test_write_pty.<locals>.<lambda>  r3  r   r5  r	  rm   )rR  r   r
  r  r   r2   r  r1   rl  rL   r   rM   rt   r5  r   r7  r   SHORT_TIMEOUTrA   rm  rn  rQ   )
r7   r(  slave_write_objr  rL   r  rg   r'  r  r*  s
         @@@@r   test_write_ptyz"EventLoopTestsMixin.test_write_ptyb  s    

''%q1 dii0))..}oNyy33G<	1ai1ekk2{	
 	TYY(A%,%:%:	<t$ TYY(A%,%:%:	<4(ekk2
 	U__;;FCD 			$$UZZ05;;/r   c                 	  
 t        j                         \  }t        j                  |      }t        j                  |       t        j                  |dd      }t        | j                        | j                  j                  fd|      }| j                  j                  |      \  }}| j                  |       | j                  |j                         | j                  ddgj                         | j                  dj                         t        j                  |dd      }t!        | j                        | j                  j#                  fd|      }| j                  j                  |      \  }	}| j                  |       | j                  |	j                         | j                  dj                         t%               
fd	|	j'                  d
       t)        j*                  | j                  
fdt,        j.                         | j                  d

       | j                  ddgj                         | j                  dj                         t        j&                  d       t)        j*                  | j                  fdt,        j.                         | j                  ddgj                         | j                  dj                         | j                  dj                         |	j'                  d       t)        j*                  | j                  
fdt,        j.                         | j                  d
       | j                  ddgj                         | j                  dj                         t        j&                  d       t)        j*                  | j                  fdt,        j.                         | j                  ddgj                         | j                  dj                         | j                  dj                         t        j0                         |j1                          | j                  j                  j2                         | j                  g dj                         |	j1                          | j                  j                  j2                         | j                  dj                         y )Nr  r   rx  c                       S r   r   r  s   r   r.  z<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>  s    : r   rK   r]   r+  c                       S r   r   r  s   r   r.  z<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>  s    [ r   c                 P    t        j                  d      }| |z  } t        |       S r!  r/  rA  s     r   r*  z:EventLoopTestsMixin.test_bidirectional_pty.<locals>.reader  rB  r   r  c                              dk\  S rD  r   r2  s   r   r.  z<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>  r3  r   rD  r  c                  "     j                   dk\  S rD  r4  r  s   r   r.  z<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>      
0A0AQ0F r   r   r  c                              dk\  S r  r   r2  s   r   r.  z<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>  r3  r   r5  s   bcdec                  "     j                   dk\  S r  r4  r  s   r   r.  z<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>  rP  r   r   r  rm   )rR  r   r;  ttysetrawr
  r  r   r2   r  r1   rl  rL   r   rM   rN   r   r  r5  rt   r   r7  r   rG  rA   rQ   )r7   
read_slavewrite_slaveslave_read_objread_connectr  r  rH  write_connectr  rg   r'  r  r*  r  s             @@@@@r   test_bidirectional_ptyz*EventLoopTestsMixin.test_bidirectional_pty  s     ZZ\
ffZ(

:T15$$))4
yy223E3AC II88Fa$nj&:&:;)[1:3C3CDJ--. ''+tQ7&DII6		445H5DF!YY99-Ha%o{'<'<=k&7&78{	
 	d#TYY(A%,%:%:	<t$)[1:3C3CDk&7&78
TYY(F%,%:%:	<)[1:3C3CDJ--.k&7&78g&TYY(A%,%:%:	<4()[1:3C3CDk&7&78
!TYY(F%,%:%:	<)[1:3C3CDJ--.k&7&78
		$$Z__55z7G7G	I 			$$[%5%56;#4#45r   c                     t        j                         \  }}|j                  d        j                  j	                   j                  j                  |d            t        dd       }| j                  |j                          fd} j                  j	                   |             } j                  j                           j                  |j                         d        j                  t        j                  j                         | j                  |j                          j                  j!                  |       |j#                          |j#                          y )NFr   ovc                     K   	 j                   j                  j                          d {    d } j                   j                          | S 7 "# t        j                  $ r d} Y 5w xY w# j                   j                          w xY ww)N	cancelled)r2   r   r  r   CancelledErrorr   )r  r  r7   s    r   mainz:EventLoopTestsMixin.test_prompt_cancellation.<locals>.main  sr     !		##AHH- 		 J )) "!"
 		 sH   B*A AA A/ BA A,)A/ +A,,A/ /BBr^  )r2  r3  r4  r2   r  r:  getattrr   pendingr   r   r  r   r   r_  r  r!  rA   )r7   r)  r8  r\  r`  r  r  s   `     @r   test_prompt_cancellationz,EventLoopTestsMixin.test_prompt_cancellation  s     "1	eII!!$))"5"5a";<Qd#>OOBJJ'
	 II!!$&)		[1'00!((;>RZZ(		"				r   c                      fd} j                   j                  d j                   _        | j                   _        d } j                   j                   |               j	                   j                   j                  d j                   j
                   j                   j                  j                  j                  d       y )Nc                  R    j                   xj                  dz  c_                  y rD  )r2   _run_once_counter)orig_run_oncer7   s   r   	_run_oncez<EventLoopTestsMixin.test_timeout_rounding.<locals>._run_once  s    II''1,'Or   r   c                  B  K   t        j                  d       d {    t        j                  d       d {    t        j                  d       d {    t        j                  d       d {    t        j                  d       d {    y 7 y7 ^7 C7 (7 w)Nr]  g-C6?gư>g:0yE>g|=r   r   r   r   waitz7EventLoopTestsMixin.test_timeout_rounding.<locals>.wait  su     --%%%--%%%--%%%--%%%--&&&	 &%%%&sU   BBBBBBB2B3BBBBBBB   )clock_resolutionselector)	r2   rh  rf  r1   assertLessEqual_clock_resolution	_selectorru   rD   )r7   rh  rj  rg  s   `  @r   test_timeout_roundingz)EventLoopTestsMixin.test_timeout_rounding  s    	 		++&'		#'			' 			$$TV,
 	TYY88"!%!<!<,,66??A	Br   c                    | j                         }d }t        j                         \  }}| j                  |j                         | j                  |j                         |j                  ||       |j                  ||       |j	                          | j                  |j                  |             | j                  |j                  |             y )Nc                       y r   r   r   r   r   r.  zCEventLoopTestsMixin.test_remove_fds_after_closing.<locals>.<lambda>      r   )
r   r2  r3  r  rA   r6  r=  r  r&  r>  r7   r2   r   r)  r8  s        r   test_remove_fds_after_closingz1EventLoopTestsMixin.test_remove_fds_after_closing  s    %%'  "1  8$8$

++A./++A./r   c                    | j                         }d }t        j                         \  }}| j                  |j                         | j                  |j                         |j	                          | j                  t              5  |j                  ||       d d d        | j                  t              5  |j                  ||       d d d        y # 1 sw Y   :xY w# 1 sw Y   y xY w)Nc                       y r   r   r   r   r   r.  z@EventLoopTestsMixin.test_add_fds_after_closing.<locals>.<lambda>"  rt  r   )	r   r2  r3  r  rA   r   r   r6  r=  ru  s        r   test_add_fds_after_closingz.EventLoopTestsMixin.test_add_fds_after_closing   s    %%'  "1  

|, 	)OOAx(	)|, 	)OOAx(	) 	)	) 	)	) 	)s   C6CCC'c                       fd} | j                         } j                  t              5   j                   j                  |       d d d        y # 1 sw Y   y xY w)Nc                 B   K   j                   j                          y wr   )r2   rA   r2   r7   s    r   
close_loopzEEventLoopTestsMixin.test_close_running_event_loop.<locals>.close_loop-  s     IIOOs   )r2   r   r   r1   )r7   r}  r  s   `  r   test_close_running_event_loopz1EventLoopTestsMixin.test_close_running_event_loop,  sM    	 $))$|, 	/II((.	/ 	/ 	/s   AAc                 ,   | j                   j                          d }d } |       }| j                  |j                         | j                  t              5  | j                   j                          d d d        | j                  t              5  | j                   j                         }| j                   j                  |       d d d        | j                  t              5  | j                   j                  |       d d d        | j                  t              5  | j                   j                  |       d d d        | j                  t              5  | j                   j                  d|       d d d        | j                  t              5  | j                   j                  | j                   j                         dz   |       d d d        | j                  t              5  | j                   j                  |       d d d        | j                  t              5  | j                   j                  t        j                   |       d d d        | j                  t              5  | j                   j#                  d |      j%                         }t'        |       d d d        y # 1 sw Y   3xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   hxY w# 1 sw Y    xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nc                     K   y wr   r   r   r   r   testz,EventLoopTestsMixin.test_close.<locals>.test7  s	     r.   c                       yNFr   r   r   r   r.  z0EventLoopTestsMixin.test_close.<locals>.<lambda>:  rt  r   g      ?g        )r2   rA   r  r   r   r   rO   r1   r   r   r   call_atr   r  rL  rO  SIGTERMr  rC   next)r7   r  funcr  futits         r   
test_closezEventLoopTestsMixin.test_close4  sY   			 v

# |, 	$II!!#	$|, 	.))))+CII((-	. |, 	&II%	&|, 	1II**40	1|, 	,II  d+	,|, 	;IIdiinn.3T:	;|, 	(II!!$'	(|, 	?II((>	? |, 	**46@@BBH	 	+	$ 	$	. 	.	& 	&	1 	1	, 	,	; 	;	( 	(	? 	?	 	sl   J$6J1#J>KK8K%$K2+K>%6L
$J.1J;>KKK"%K/2K;>L
L)T)TN)NNr   )_rD   rE   rF   r   r   r   r   r   r   r   r  r  r  r  r9  r@  unittest
skipUnlessr  rO  rX  ra  rf  rt  r  r   skip_unless_bind_unix_socketr  r  r  r  skipIfr  r  r  r  skip_if_tcp_blackholer  r  r  r  r  r  r   r  r(  r+  r-  r6  r?  r2  rH  rQ  rV  rZ  rd  rf  rh  ro  rt  r  r  r  r  r  r  r  IPV6_ENABLEDr  r  r  r  r  r  r  r  r   r    r  r  rR  r)  r6  r=  r   requires_mac_verrI  rZ  rc  rq  rv  ry  r~  r  rw   rx   s   @r   r   r     s   '
E$B>	3	86.6>!(08%( X3\B)I C)IV X3\BX524$4 C$  X3\BX524$4 C$"	7 //G 0G ;?&*R?B 8<15
 CG#KJ X__SD[/2E 3E //X__SD[/2E 3 0E	 ((, ),* ((, ),(E46l X__SD[/2J 3J/ TZZ,-5 .56MA"H. X8:KL M2 // 06 X35FG0 H0	"? X__SD[/2 3> //X__SD[/2 3 0: X__SD[/2 38 //X__SD[/2 3 08 X__SD[/2 3B //X__SD[/21 3 012 X__SD[/21 31:. X335TU& V&P (( )$.!`N X335TUI VI.4HT
' X0:<E<E@ X0:<%<%@ X0:<XY/1DEE F<EB X0:<#0<#0J X0:<0<0* X0:<XY/1DE Wb!$%0 % F<%0N X0:<XY/1DE Wb!$D6 % F<D6L@B2
0
)/"r   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Z ej                  ej                  d
k(  d      d        Zd Zd Zd Zd Zd Zd Zy)SubprocessTestsMixinc                     t         j                  dk(  r| j                  |t               y | j	                  t
        j                   |       y Nr   )r   r    ri  r%   r   rO  r  r7   r   s     r   check_terminatedz%SubprocessTestsMixin.check_terminated[  6    <<7"!!*c2 fnn_j9r   c                     t         j                  dk(  r| j                  |t               y | j	                  t
        j                   |       y r  )r   r    ri  r%   r   rO  rA  r  s     r   check_killedz!SubprocessTestsMixin.check_killedb  r  r   c                    t         j                  j                  t         j                  j                  t              d      }| j
                  j                  t        j                  t        | j
                        t        j                  |      }| j
                  j                  |      \  }}| j                  |t               | j
                  j                  |j                         | j                  d|j                          |j#                  d      }|j%                  d       | j
                  j                  |j&                  d   j)                                t+        j,                         5  |j/                          d d d        | j
                  j                  |j0                         | j3                  |j4                         | j                  d|j6                  d          y # 1 sw Y   ixY w)Necho.pyr]   r      Python The Winnerr   )rR  rK  r  dirname__file__r2   subprocess_execr  r  r   r   
executabler1   ri  rP   r   rM   get_pipe_transportrt   r   rj  r   r  rA   r   r  r   rg   r7   progr  transpr  stdins         r   test_subprocess_execz)SubprocessTestsMixin.test_subprocess_execi  sX   ww||BGGOOH5yA))++!))*>		J. 		44W=e%9:		$$U__5ekk2))!,()		$$U^^A%6%;%;%=>&&( 	LLN			$$U__5%**+-uzz!}=		 	s   0G))G2c                    t         j                  j                  t         j                  j                  t              d      }| j
                  j                  t        j                  t        | j
                        t        j                  |      }| j
                  j                  |      \  }}| j                  |t               | j
                  j                  |j                         | j                  d|j                          |j#                  d      }|j%                  d       | j
                  j                  |j&                  d   j)                                |j&                  d   j+                          | j                  d|j,                  d          |j%                  d       | j
                  j                  |j&                  d   j)                                | j                  d|j,                  d          t/        j0                         5  |j3                          d d d        | j
                  j                  |j4                         | j7                  |j8                         y # 1 sw Y   JxY w)Nr  r]   r   s   Python r   s
   The Winnerr  )rR  rK  r  r  r  r2   r  r  r  r   r   r  r1   ri  rP   r   rM   r  rt   r   rj  clearrg   r   r  rA   r   r  r   r  s         r   test_subprocess_interactivez0SubprocessTestsMixin.test_subprocess_interactive~  s   ww||BGGOOH5yA))++!))*>		J. 		44W=e%9:		$$U__5ekk2))!,J		$$U^^A%6%;%;%=>q!UZZ]3M"		$$U^^A%6%;%;%=>-uzz!}=&&( 	LLN			$$U__5%**+	 	s   I,,I5c                    | j                   j                  t        j                  t        | j                         d      }| j                   j                  |      \  }}| j                  |t               | j                   j                  |j                         |j                  d      j                          | j                   j                  |j                         | j                  d|j                         | j                  t        d |j                  j!                         D                     | j                  |j"                  d   j%                  d      d       | j                  |j"                  d   d       |j                          y )	Nzecho Pythonr   c              3   <   K   | ]  }|j                           y wr   )rQ   ).0r  s     r   	<genexpr>z=SubprocessTestsMixin.test_subprocess_shell.<locals>.<genexpr>  s     IAFFHIs   r   s   
s   Pythonr   r   )r2   subprocess_shellr  r  r   r1   ri  rP   r  rA   r   r   r   r   allr   valuesrg   rstripr7   r  r  r  s       r   test_subprocess_shellz*SubprocessTestsMixin.test_subprocess_shell  s   )),,!))*>		J%' 		44W=e%9:		$$U__5!!!$**,		$$U__5E,,-Ie.?.?.F.F.HIIJA--g6	BA,r   c                    | j                   j                  t        j                  t        | j                         dd d d       }| j                   j                  |      \  }}| j                  |t               | j                   j                  |j                         | j                  d|j                         |j                          y )Nexit 7r  stdoutstderr   r2   r  r  r  r   r1   ri  r   r   r   rA   r  s       r   test_subprocess_exitcodez-SubprocessTestsMixin.test_subprocess_exitcode  s    )),,!))*>		J T$ - H 		44W=e%9:		$$U__5E,,-r   c                 p   | j                   j                  t        j                  t        | j                         dd d d       }| j                   j                  |      \  }}| j                  |t               | j                  |j                  d             | j                  |j                  d             | j                  |j                  d             | j                   j                  |j                         | j                  d|j                         | j                  |j                                y )Nr  r  r   r   r   r  )r2   r  r  r  r   r1   ri  r  r  r   r   r   rA   r  s       r   "test_subprocess_close_after_finishz7SubprocessTestsMixin.test_subprocess_close_after_finish  s    )),,!))*>		J T$ - H 		44W=e%9:&33A67&33A67&33A67		$$U__5E,,-&,,.)r   c                    t         j                  j                  t         j                  j                  t              d      }| j
                  j                  t        j                  t        | j
                        t        j                  |      }| j
                  j                  |      \  }}| j                  |t               | j
                  j                  |j                         |j                          | j
                  j                  |j                          | j#                  |j$                         |j'                          y Nr  )rR  rK  r  r  r  r2   r  r  r  r   r   r  r1   ri  rP   rS  r   r  r   rA   r7   r  r  r  r  s        r   test_subprocess_killz)SubprocessTestsMixin.test_subprocess_kill  s    ww||BGGOOH5yA))++!))*>		J. 		44W=e%9:		$$U__5		$$U__5%**+r   c                    t         j                  j                  t         j                  j                  t              d      }| j
                  j                  t        j                  t        | j
                        t        j                  |      }| j
                  j                  |      \  }}| j                  |t               | j
                  j                  |j                         |j                          | j
                  j                  |j                          | j#                  |j$                         |j'                          y r  )rR  rK  r  r  r  r2   r  r  r  r   r   r  r1   ri  rP   	terminater   r  r   rA   r  s        r   test_subprocess_terminatez.SubprocessTestsMixin.test_subprocess_terminate  s    ww||BGGOOH5yA))++!))*>		J. 		44W=e%9:		$$U__5		$$U__5e../r   r   zDon't have SIGHUPc                    t        j                   t         j                  t         j                        }	 t        j                  j                  t        j                  j                  t              d      }| j                  j                  t        j                  t        | j                        t        j                  |      }| j                  j                  |      \  }}| j!                  |t               | j                  j                  |j"                         |j%                  t         j                         | j                  j                  |j&                         | j)                  t         j                   |j*                         |j-                          t        j                   t         j                  |       y # t        j                   t         j                  |       w xY wr  )rO  SIGHUPSIG_DFLrR  rK  r  r  r  r2   r  r  r  r   r   r  r1   ri  rP   send_signalr   r   r   rA   )r7   old_handlerr  r  r  r  s         r   test_subprocess_send_signalz0SubprocessTestsMixin.test_subprocess_send_signal  s'   
 mmFMM6>>B	677<< 99EDii//%--.BDIINNND2G
 !II88AMFE!!%)=>II((9v}}-II((9fmm^U-=-=>LLNMM&--5FMM&--5s   E&F? ?&G%c                 l   t         j                  j                  t         j                  j                  t              d      }| j
                  j                  t        j                  t        | j
                        t        j                  |      }| j
                  j                  |      \  }}| j                  |t               | j
                  j                  |j                         |j                  d      }|j!                  d       | j
                  j                  |j"                         |j%                          | j'                  d|j(                  d          | j+                  |j(                  d   j-                  d      |j(                  d          | j'                  d|j.                         y )Necho2.pyr      test   OUT:testr   r   s   ERR:test)rR  rK  r  r  r  r2   r  r  r  r   r   r  r1   ri  rP   r  rt   r   rA   r   rg   r   r!   r   r  s         r   test_subprocess_stderrz+SubprocessTestsMixin.test_subprocess_stderr  s(   ww||BGGOOH5zB))++!))*>		J. 		44W=e%9:		$$U__5))!,G		$$U__5ejjm4

100=uzz!}ME,,-r   c                    t         j                  j                  t         j                  j                  t              d      }| j
                  j                  t        j                  t        | j
                        t        j                  |t        j                        }| j
                  j                  |      \  }}| j                  |t               | j
                  j                  |j                          |j#                  d      }| j%                  |j#                  d             | j'                  |j#                  d             |j)                  d       | j
                  j                  |j*                         | j-                  |j.                  d   j1                  d      |j.                  d          | j3                  d|j.                  d          |j5                          | j3                  d|j6                         y )	Nr  )r  r   r   r   r  s   OUT:testERR:testr   )rR  rK  r  r  r  r2   r  r  r  r   r   r  
subprocessSTDOUTr1   ri  rP   r  rm  r  rt   r   r   rg   r!   r   rA   r   r  s         r   )test_subprocess_stderr_redirect_to_stdoutz>SubprocessTestsMixin.test_subprocess_stderr_redirect_to_stdout  sl   ww||BGGOOH5zB))++!))*>		JZ5F5F , H
 		44W=e%9:		$$U__5))!,V66q9:&33A67G		$$U__5

1001DE

1	'ejjm,E,,-r   c                 v   t         j                  j                  t         j                  j                  t              d      }| j
                  j                  t        j                  t        | j
                        t        j                  |      }| j
                  j                  |      \  }}| j                  |t               | j
                  j                  |j                         |j                  d      }|j                  d      }|j!                  d       | j
                  j                  |j"                  d   j%                                | j'                  d|j(                  d          |j+                          | j
                  j                  |j,                  d          |j!                  d       | j
                  j                  |j"                  d   j%                                t        j.                  dk7  r | j'                  d	|j(                  d          n| j'                  d
|j(                  d          t1        j2                         5  |j+                          d d d        | j
                  j                  |j4                         | j7                  |j8                         y # 1 sw Y   JxY w)Nzecho3.pyr   r   r  r  r2  r   r   s   ERR:BrokenPipeErrors   ERR:OSError)rR  rK  r  r  r  r2   r  r  r  r   r   r  r1   ri  rP   r  rt   r   rj  r   rg   rA   r   r    r   r  r   r  r   )r7   r  r  r  r  r  r  s          r   #test_subprocess_close_client_streamz8SubprocessTestsMixin.test_subprocess_close_client_stream)  s   ww||BGGOOH5zB))++!))*>		J. 		44W=e%9:		$$U__5))!,**1-G		$$U^^A%6%;%;%=>ejjm4		$$U%6%6q%9:F		$$U^^A%6%;%;%=><<7"3UZZ]C ^UZZ];&&( 	LLN			$$U__5%**+	 	s   J//J8c                    | j                   j                  t        j                  t        | j                         dd d d d      }| j                   j                  |      \  }}| j                  |t               | j                   j                  |j                         | j                  d|j                         |j                          y )Nr  T)r  r  r  start_new_sessionr  r  r  s       r   "test_subprocess_wait_no_same_groupz7SubprocessTestsMixin.test_subprocess_wait_no_same_groupK  s    )),,!))*>		J T$*. - 0 		44W=e%9:		$$U__5E,,-r   c                      fd} j                  t              5   j                  j                   |d             d d d         j                  t              5   j                  j                   |d             d d d         j                  t              5   j                  j                   |d             d d d        y # 1 sw Y   xY w# 1 sw Y   VxY w# 1 sw Y   y xY w)Nc                  z   K    j                   j                  t        j                  dfi |  d {    y 7 wNpwd)r2   r  r   SubprocessProtocol)r  r7   s    r   r  zGSubprocessTestsMixin.test_subprocess_exec_invalid_args.<locals>.connectX  s9     +$))++**  s   0;9;Tuniversal_newlines   bufsizeshellr   rN  r2   r1   r7   r  s   ` r   !test_subprocess_exec_invalid_argsz6SubprocessTestsMixin.test_subprocess_exec_invalid_argsW  s    	
 z* 	KII((D)IJ	Kz* 	@II(()>?	@z* 	>II((t)<=	> 	>		K 	K	@ 	@	> 	>s#   #C#C#C CC C)c                 t    d
 fd	} j                  t              5   j                  j                   |ddg             d d d         j                  t              5   j                  j                   |d             d d d         j                  t              5   j                  j                   |d             d d d         j                  t              5   j                  j                   |d	             d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   bxY w# 1 sw Y   y xY w)Nc                    K   | sd}  j                   j                  t        j                  | fi | d {    y 7 wr  )r2   r  r   r  )cmdr  r7   s     r   r  zHSubprocessTestsMixin.test_subprocess_shell_invalid_args.<locals>.connectf  sA     ,$)),,**  s   4?=?lsz-lTr  r  r  Fr  r   r  r  s   ` r   "test_subprocess_shell_invalid_argsz7SubprocessTestsMixin.test_subprocess_shell_invalid_argsd  s   	 z* 	@II(($)>?	@z* 	KII((D)IJ	Kz* 	@II(()>?	@z* 	?II((u)=>	? 	?	@ 	@	K 	K	@ 	@	? 	?s/   $D
#D#D"#D.
DD"D+.D7N)rD   rE   rF   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  Y  sz    ::>*,6 	*   X__S\\W,.AB6 C60.*.2 ,D
>?r   r  r   c                       e Zd Zd Zy)SelectEventLoopTestsc                 *    t        j                         S r   )r   SelectorEventLoopr@   s    r   r   z&SelectEventLoopTests.create_event_loop|      ,,..r   NrD   rE   rF   r   r   r   r   r  r  y  s    	/r   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ProactorEventLoopTestsc                 *    t        j                         S r   )r   ProactorEventLoopr@   s    r   r   z(ProactorEventLoopTests.create_event_loop  r  r   c                 ,    t        j                  d      Nz(IocpEventLoop does not have add_reader()r  SkipTestr@   s    r   r9  z+ProactorEventLoopTests.test_reader_callback      ##$NOOr   c                 ,    t        j                  d      r  r  r@   s    r   test_reader_callback_cancelz2ProactorEventLoopTests.test_reader_callback_cancel  r  r   c                 ,    t        j                  d      Nz(IocpEventLoop does not have add_writer()r  r@   s    r   r@  z+ProactorEventLoopTests.test_writer_callback  r  r   c                 ,    t        j                  d      r   r  r@   s    r   test_writer_callback_cancelz2ProactorEventLoopTests.test_writer_callback_cancel  r  r   c                 ,    t        j                  d      r  r  r@   s    r   rv  z4ProactorEventLoopTests.test_remove_fds_after_closing  r  r   N)	rD   rE   rF   r   r9  r  r@  r  rv  r   r   r   r  r    s%    	/	P	P	P	P	Pr   r  c                   (     e Zd Z fdZ fdZ xZS )UnixEventLoopTestsMixinc                 0   t         |           t        j                         5  t        j                  dt
               t        j                         }|j                  | j                         t        j                  |       d d d        y # 1 sw Y   y xY wNignore)rs   r   warningscatch_warningssimplefilterDeprecationWarningr   SafeChildWatcherattach_loopr2   set_child_watcherr7   watcherru   s     r   r   zUnixEventLoopTestsMixin.setUp  sl    GMO((* 3%%h0BC!224##DII.))'2	3 3 3s   ABBc                     t        j                         5  t        j                  dt               t	        j
                  d        d d d        t        |           y # 1 sw Y   xY wr  )r	  r
  r  r  r   r  rs   r   r   s    r   r   z UnixEventLoopTestsMixin.tearDown  sP    ((* 0%%h0BC))$/0 G0 0s   0AA&)rD   rE   rF   r   r   rw   rx   s   @r   r  r    s    	3	 	r   r  KqueueSelectorc                        e Zd Zd Z ej
                  dd       ej                  ej                  j                  d      d       fd              Z ej
                  dd       fd       Z xZS )KqueueEventLoopTestsc                 P    t        j                  t        j                               S r   )r   r  	selectorsr  r@   s    r   r   z&KqueueEventLoopTests.create_event_loop  s!    00,,.0 0r   r   	   openbsdztest hangs on OpenBSDc                 "    t         |           y r   )rs   r)  r   s    r   r)  z)KqueueEventLoopTests.test_read_pty_output  s     ,.r   c                 "    t         |           y r   )rs   rI  r   s    r   rI  z#KqueueEventLoopTests.test_write_pty  s    &(r   )rD   rE   rF   r   r   r  r  r  r   r    r!   r)  rI  rw   rx   s   @r   r  r    sw    0 &W%%b!, X__S\\44Y?46/6 -
/
 &W%%b!,) -)r   r  EpollSelectorc                       e Zd Zd Zy)EPollEventLoopTestsc                 P    t        j                  t        j                               S r   )r   r  r  r  r@   s    r   r   z%EPollEventLoopTests.create_event_loop  s    001H1H1JKKr   Nr  r   r   r   r  r    s    Lr   r  PollSelectorc                       e Zd Zd Zy)PollEventLoopTestsc                 P    t        j                  t        j                               S r   )r   r  r  r   r@   s    r   r   z$PollEventLoopTests.create_event_loop  s    001G1G1IJJr   Nr  r   r   r   r"  r"    s    Kr   r"  c                       e Zd Zd Zy)r  c                 P    t        j                  t        j                               S r   )r   r  r  SelectSelectorr@   s    r   r   z&SelectEventLoopTests.create_event_loop  s    ,,Y-E-E-GHHr   Nr  r   r   r   r  r    s    	Ir   c                       y r   r   )r  r  s     r   noopr(    s    r   c                        e Zd Z fdZd Zd Zd Zd Zd Zd Z	 e
j                   eej                  d      d	      d
        Z xZS )HandleTestsc                     t         |           t        j                         | _        d| j                  j
                  _        y r  )rs   r   r   r  r2   	get_debugreturn_valuer   s    r   r   zHandleTests.setUp  s+    IIK	+/		(r   c                 \   d }d}t        j                  ||| j                        }| j                  |j                  |       | j                  |j
                  |       | j                  |j                                |j                          | j                  |j                                y )Nc                      | S r   r   r  s    r   r   z)HandleTests.test_handle.<locals>.callback      Kr   r   )
r   Handler2   rl  	_callback_argsr  r^  r  r   )r7   r   r  hs       r   test_handlezHandleTests.test_handle  sw    	 NN8T4995akk8,aggt$'	
&r   c                    d }t        j                         | _        t        j                         | j                  _        t	        j
                  |d| j                        }|j                          | j                  j                  j                  t        j                  d      t         j                  ||j                  d       y )Nc                      t               r   )rN  r   r   r   r   z:HandleTests.test_callback_with_exception.<locals>.callback  s
    ,r   r   zException in callback.*)r  r  handlesource_traceback)r   r  r2   rx  r   r2  _runassert_called_withr   MockPatternANY_source_traceback)r7   r   r5  s      r   test_callback_with_exceptionz(HandleTests.test_callback_with_exception  s    	 IIK	+/99;		(NN8R3			((;;!--.GH ! 3 3	=
 	r   c                 z    t        j                         }t        j                  d d| j                        }||d<   y )Nc                       y r   r   r   r   r   r.  z1HandleTests.test_handle_weakref.<locals>.<lambda>	  rt  r   r   r5  )weakrefWeakValueDictionaryr   r2  r2   )r7   wdr5  s      r   test_handle_weakrefzHandleTests.test_handle_weakref	  s/    ((*NN<TYY73r   c                    d| j                   j                  _        t        j                  t
        d| j                         }t        j                  t
              \  }}| j                  t        |      d|d|d       |j                          | j                  t        |      d       t        j                  t
              }t        j                  |d| j                         }| j                  t        |      d|d|d       t        j                  t
        d	d
      }t        j                  |d| j                         }dt        j                   |      d|d}| j#                  t        |      |       t        j                  t
        d	      }t        j                  |d| j                         }dt        j                   |      d|d}| j#                  t        |      |       t$        j&                  }t        j(                  |      }t        j                  |      \  }}t        j                  |d| j                         }d}d| d}d| dt        j                   |       d| d}| j#                  t        |      |       y )NFr   <Handle noop(1, 2) at :>z<Handle cancelled>r   z<Handle noop() at r   r   )r   z^<Handle noop\(1, 2\)\(3\) at z>$)x)r   r   z ^<Handle noop\(x=1\)\(2, 3\) at z*<function HandleTests.test_handle_repr .*>zfunctools.partialmethod\(z
, , \)\(\)z	^<Handle z at )r2   r,  r-  r   r2  r(  r   get_function_sourcer   r  r  types	coroutiner  r  r  escapeassertRegexr*  test_handle_reprpartialmethod)r7   r5  filenamelinenor   r  methodcb_regexs           r   rQ  zHandleTests.test_handle_repr	  s    +0		( NN43%99$?&a#V-	.
 	

a,	. __T"NN2r499-a#V-	.
 tQ*NN2tTYY/IIh'1a%( tq)NN2vtyy1IIh'1a%( --$$V,%99&A&NN2r499-@/zDXJd299X+>*?qKa%(r   c                 :   d| j                   j                  _        t        }t	        j
                         j                  dz   }t        j                  t        d| j                         }t        j                  t              \  }}| j                  t        |      d|d|d|d|d	       |j                          | j                  t        |      d|d|d|d|d	       |j                          | j                  t        |      d|d|d|d|d	       y )	NTr   r   rH  rI   created at rJ  z <Handle cancelled noop(1, 2) at )r2   r,  r-  r  r   	_getframef_linenor   r2  r(  r   rL  r   r  r  r7   create_filenamecreate_linenor5  rS  rT  s         r   test_handle_repr_debugz"HandleTests.test_handle_repr_debug6	  s    +/		( #0014NN43%99$?&a#V_mM	N
 	

G-A	B 	

G-A	Br   c                     t        j                         j                         }|j                  d        j	                  |        fd}|j                  t              } ||       |j                  t              } ||       |j                  dt              } ||       |j                  dt              } ||       y )NTc                     t        j                  d      j                  dz
  }j                  | j                  t
               j                  | j                  d   d d t        |df       y )Nr   rI  r   test_handle_source_traceback)r   rY  rZ  ri  r?  listr   r  )r5  rT  r7   s     r   check_source_tracebackzHHandleTests.test_handle_source_traceback.<locals>.check_source_tracebackU	  sb    ]]1%..2F!!!"5"5t<Q004Ra8&$<>?r   r   )	r   get_event_loop_policyr/   	set_debugr0   r   r(  r   r   )r7   r2   rc  r5  s   `   r   ra  z(HandleTests.test_handle_source_tracebackP	  s    ,,.==?tD!	? NN4 q! %%d+q! OOAt$q! OOAt$q!r   	CoroutinezNo collections.abc.Coroutinec                    t               }d|_        | j                  t        j                  |             | j                  t        j                  |      d       d|_        | j                  t        j                  |      d       d|_	        | j                  t        j                  |      d       d x|_        |_        | j                  t        j                  |      d       t               }d|_        | j                  t        j                  |      d	       t               }d|_        d |_
        | j                  t        j                  |      d       y )
NAAAzAAA()BBBzBBB()TzBBB() runningz%<CoroLike without __name__>() runningr5   z
CoroLike())r5   rD   r   r   iscoroutiner   r   _format_coroutinerF   
cr_runningcr_code)r7   r  s     r   +test_coroutine_like_object_debug_formattingz7HandleTests.test_coroutine_like_object_debug_formattingm	  s    z++D1255d;WE!55d;WE55d;_M,00)55d;@	B z& 	55d;\Jz!55d;WEr   )rD   rE   rF   r   r6  r@  rF  rQ  r^  ra  r  r  r  collectionsabcrn  rw   rx   s   @r   r*  r*    s[    0
'"
-)^B4": X+>79F9Fr   r*  c                   B     e Zd Z fdZd Zd Zd Zd Zd Zd Z	 xZ
S )
TimerTestsc                 T    t         |           t        j                         | _        y r   )rs   r   r   r  r2   r   s    r   r   zTimerTests.setUp	  s    IIK	r   c                     t        j                         }t        j                  |d dt	        j
                               }| j                  t        |      t        |             y )Nc                       yr  r   r   r   r   r.  z&TimerTests.test_hash.<locals>.<lambda>	  rt  r   r   )r   	monotonicr   TimerHandler   r  r   hashr7   whenr5  s      r   	test_hashzTimerTests.test_hash	  sE    ~~mR $		-a$t*-r   c                     t        j                         }t        j                  |d dt	        j
                               }| j                  ||j                                y )Nc                       yr  r   r   r   r   r.  z&TimerTests.test_when.<locals>.<lambda>	  rt  r   r   )r   rv  r   rw  r   r  r   rz  ry  s      r   	test_whenzTimerTests.test_when	  sC    ~~mR $		-qvvx(r   c                    d }d}t        j                         }t        j                  |||t	        j
                               }| j                  |j                  |       | j                  |j                  |       | j                  |j                                |j                          | j                  |j                                | j                  |j                         | j                  |j                         y )Nc                      | S r   r   r0  s    r   r   z'TimerTests.test_timer.<locals>.callback	  r1  r   )r   r   r   )r   rv  r   rw  r   r  rl  r3  r4  r  r^  r  r   r  )r7   r   r  rz  r5  s        r   
test_timerzTimerTests.test_timer	  s    	 ~~hdiikBakk8,aggt$' 	

&!++&!''"r   c                 J   d| j                   j                  _        t        j                  dt
        d| j                         }t        j                  t
              }| j                  t        |      d|z         |j                          | j                  t        |      d       y )NF{   r   z&<TimerHandle when=123 noop() at %s:%s>z <TimerHandle cancelled when=123>)r2   r,  r-  r   rw  r(  r   rL  r   r  r  )r7   r5  srcs      r   test_timer_reprzTimerTests.test_timer_repr	  s    +0		( T2tyy9,,T2a@3F	H 	

a:	<r   c                    d| j                   j                  _        t        }t	        j
                         j                  dz   }t        j                  dt        d| j                         }t        j                  t              \  }}| j                  t        |      d|d|d|d|d	       |j                          | j                  t        |      d	|d|d|d|d	       y )
NTr   r  r   z <TimerHandle when=123 noop() at rI  rX  rJ  z*<TimerHandle cancelled when=123 noop() at )r2   r,  r-  r  r   rY  rZ  r   rw  r(  r   rL  r   r  r  r[  s         r   test_timer_repr_debugz TimerTests.test_timer_repr_debug	  s    +/		( #0014T2tyy9%99$?&a $V_mM	N 	

a $V_mM	Nr   c                 6	   d }t        j                         }t        j                  ||d| j                        }t        j                  ||d| j                        }| j                  ||k         | j                  ||k         | j                  ||k         | j                  ||k         | j                  ||kD         | j                  ||kD         | j                  ||k\         | j                  ||k\         | j                  ||k(         | j                  ||k7         |j                          | j                  ||k(         t        j                  ||d| j                        }t        j                  |dz   |d| j                        }| j                  ||k         | j                  ||k         | j                  ||k         | j                  ||k         | j                  ||kD         | j                  ||kD         | j                  ||k\         | j                  ||k\         | j                  ||k(         | j                  ||k7         t        j                  |d| j                        }| j                  t        |j                  |             | j                  t        |j                  |             | j                  t              5  |dk   d d d        | j                  t              5  |dkD   d d d        | j                  t              5  |dk   d d d        | j                  t              5  |dk\   d d d        | j                  |dk(         | j                  |dk7         | j                  |t        k(         | j                  |t        k7         | j                  |t         k         | j                  |t         kD         | j                  |t         k         | j                  |t         k\         | j                  |t"        k         | j                  |t"        kD         | j                  |t"        k         | j                  |t"        k\         y # 1 sw Y   xY w# 1 sw Y   vxY w# 1 sw Y   `xY w# 1 sw Y   JxY w)Nc                      | S r   r   r0  s    r   r   z2TimerTests.test_timer_comparison.<locals>.callback	  r1  r   r   g      $@)r   rv  r   rw  r2   r  r   r  r2  rl  NotImplemented__eq____ne__r   rK  r   r   r   )r7   r   rz  h1h2h3s         r   test_timer_comparisonz TimerTests.test_timer_comparison	  s   	 ~~  xTYY?  xTYY?b!b!b!b!b!b!b!b!b!r"
		r"  xTYY?  hDIIFR b!b!r"b!R r"b!r"b!^^Hb$))4nbiim4nbiim4y) 	G	y) 	G	y) 	"H	y) 	"H	r"b!i(y)W%g&g&w'h'X&x(h')	 		 		 		 	s0   Q':Q4R R'Q14Q>RR)rD   rE   rF   r   r{  r~  r  r  r  r  rw   rx   s   @r   rr  rr  	  s'     .)#$<N*<(r   rr  c                       e Zd Zd Zd Zy)AbstractEventLoopTestsc                    t        j                         }t        j                         }| j	                  t
        |j                         | j	                  t
        |j                  d        | j	                  t
        |j                         | j	                  t
        |j                         | j	                  t
        |j                         | j	                  t
        |j                         | j	                  t
        |j                  d        | j	                  t
        |j                  d d        | j	                  t
        |j                  ||       | j	                  t
        |j                  d        | j	                  t
        |j                          | j	                  t
        |j"                  d        | j	                  t
        |j$                  |       | j	                  t
        |j&                  d|       | j	                  t
        |j(                  d       | j	                  t
        |j*                  d|       | j	                  t
        |j,                  d       | j	                  t
        |j.                  d|       | j	                  t
        |j0                  d       | j	                  t
        |j0                  d       | j	                  t
        |j2                  |       | j	                  t
        |j4                  |       | j	                  t
        |j6                  |       | j	                  t
        |j8                         | j	                  t
        |j:                  |       y rD  )r   r  r   AbstractEventLoopr   NotImplementedErrorr   r1   r   r   r   rA   r  r   r  r   r   r   set_default_executorr6  r&  r=  r>  rL  rM  set_exception_handlerdefault_exception_handlerrx  r,  re  )r7   r  r2   s      r   test_not_implementedz+AbstractEventLoopTests.test_not_implemented
  s   IIK((*!1!1	3!8!8$	@	,	2	1	-!1!14	9$	>q!	5	7	,!:!:D	B!:!:A	?!Q	8!3!3Q	8!Q	8!3!3Q	8!8!8!Q	@!;!;Q	@!;!;Q	@!;!;Q	@!?!?	D!<!<a	A	1	4r   c                       fd}t        j                         }|j                   |              |j                          y )Nc                  \
  K   t        j                         } t        j                         }j	                  t
              5  |j                  | |        d {    d d d        j	                  t
              5  |j                  dd       d {    d d d        j	                  t
              5  |j                  d       d {    d d d        j	                  t
              5  |j                  |        d {    d d d        j	                  t
              5  |j                  |        d {    d d d        j	                  t
              5  |j                  |        d {    d d d        j	                  t
              5  |j                  | d       d {    d d d        j	                  t
              5  |j                  | d       d {    d d d        j	                  t
              5  |j                  | d       d {    d d d        j	                  t
              5  |j                  | |        d {    d d d        j	                  t
              5  |j!                  |        d {    d d d        j	                  t
              5  |j#                  | |        d {    d d d        j	                  t
              5  |j%                  | |        d {    d d d        j	                  t
              5  |j'                  | t         j(                  j*                         d {    d d d        j	                  t
              5  |j-                  | t         j(                  j*                         d {    d d d        j	                  t
              5  |j/                  | t         j(                         d {    d d d        j	                  t
              5  |j1                  |        d {    d d d        y 7 # 1 sw Y   xY w7 # 1 sw Y   xY w7 w# 1 sw Y   wxY w7 P# 1 sw Y   PxY w7 )# 1 sw Y   )xY w7 # 1 sw Y   xY w7 # 1 sw Y   xY w7 # 1 sw Y   xY w7 # 1 sw Y   xY w7 b# 1 sw Y   bxY w7 ;# 1 sw Y   ;xY w7 # 1 sw Y   xY w7 # 1 sw Y   xY w7 # 1 sw Y   xY w7 k# 1 sw Y   kxY w7 5# 1 sw Y   5xY w7 # 1 sw Y   y xY ww)Nr    )r  r  r   )r   r  r   r  r   r  r  r  r  r|  r  r  r:  sock_recv_intosock_sendallsock_connectsock_acceptsock_sendfilesendfiler  sentinelr	  r  r  r  )r  r2   r7   s     r   innerz@AbstractEventLoopTests.test_not_implemented_async.<locals>.innerO
  sw    		A,,.D""#67 1**1a0001""#67 :&&{D999:""#67 <&&':;;;<""#67 0,,Q///0""#67 ,((+++,""#67 733A6667""#67 ,nnQ+++,""#67 1))!R0001""#67 /''2.../""#67 .''1---.""#67 *&&q)))*""#67 /((A.../""#67 *mmAq)))*""#67 D,,Q0B0BCCCD""#67 E--a1C1CDDDE""#67 >++At}}===>""#67 .**1---. .? 11 1 :: : << < 00 0 ,, , 77 7 ,, , 11 1 // / .. . ** * // / ** * DD D EE E >> > .. .s  >T,P PP T,9P0P-P0T,1Q P=Q T,(Q=Q>QT,Q 4Q5Q 9T,Q0+Q-,Q00T,R #Q=$R (T,RRR T,=R RR T,5R0R-R0T,-S R=S T,$S:S;S?T,S 2S3S 7T,.S0S-S0T,$.T S=T T,4$TTTT,:T TT 	T,P  P*%T,-P00P:5T,=Q  Q
T,QQT,Q  Q*%T,-Q00Q:5T,=R  R
T,RRT,R  R*%T,-R00R:5T,=S  S
T,SST,S  S*%T,-S00S:5T,=T  T
T,TTT,T  T)%T,)r   r/   r1   rA   )r7   r  r2   s   `  r   test_not_implemented_asyncz1AbstractEventLoopTests.test_not_implemented_asyncM
  s2    %	.N %%'(

r   N)rD   rE   rF   r  r  r   r   r   r  r  
  s    44l+r   r  c                   l    e Zd Zd Zd Zd Zd Z ej                  d      d        Z	d Z
d Zd	 Zd
 Zy)PolicyTestsc                    t        j                         }| j                  t        |j                         | j                  t        |j
                  t                      | j                  t        |j                         | j                  t        |j                         | j                  t        |j                  t                      y r   )
r   AbstractEventLoopPolicyr   r  get_event_loopr0   r~  r/   get_child_watcherr  r7   policys     r   test_event_loop_policyz"PolicyTests.test_event_loop_policy}
  s    002-v/D/DE-v/D/DfhO-v/D/DE-v/G/GH-v/G/G (	$r   c                    t        j                         }| j                  |j                  j                         | j                  t              5 }|j                         }d d d        | j                  j                  t               | j                  t         j                         | j                  |j                  j                  |       | j                  ||j                                |j                          y # 1 sw Y   xY wr   )r   DefaultEventLoopPolicyr  _local_loopassertWarnsr  r  r   rS  r  ri  r  rl  rA   )r7   r  r  r2   s       r   test_get_event_loopzPolicyTests.test_get_event_loop
  s    //1&----.01 	+R((*D	+h/dG$=$=>fmm))40dF1134

	+ 	+s   C??Dc                    t        j                         }t        j                  j	                  |d|j
                        5 }| j                  t              5 }|j                         }d d d        | j                  j                         | j                  j                  t               |j                  |       d d d        j                          y # 1 sw Y   nxY w# 1 sw Y   &xY w)Nr0   )wraps)r   r  r   r  r~  r0   r  r  r  r  rA   r   rS  r  r<  )r7   r  m_set_event_loopr  r2   s        r   (test_get_event_loop_calls_set_event_loopz4PolicyTests.test_get_event_loop_calls_set_event_loop
  s    //1ZZ(++  - 	60@!!"45 /,,./OODJJ'R[[(3
 //5	6 	

/ /		6 	6s%   C!C(AC!C	C!!C*c                     t        j                         }|j                  d        | j                  t        |j
                         y r   )r   r  r0   r   r   r  r  s     r   "test_get_event_loop_after_set_nonez.PolicyTests.test_get_event_loop_after_set_none
  s4    //1d#,(=(=>r   z'asyncio.events.threading.current_threadc                 |      fd}t        j                  |      }|j                          |j                          y )Nc                  n    t        j                         } j                  t        | j                         y r   )r   r  r   r   r  )r  r7   s    r   r  z1PolicyTests.test_get_event_loop_thread.<locals>.f
  s'    335FlF,A,ABr   r   )r   r  r  r  )r7   m_current_threadr  ths   `   r   test_get_event_loop_threadz&PolicyTests.test_get_event_loop_thread
  s-    	C Q'


	r   c                     t        j                         }|j                         }| j                  |t         j                         |j                          y r   )r   r  r/   ri  r  rA   )r7   r  r2   s      r   test_new_event_loopzPolicyTests.test_new_event_loop
  s=    //1$$&dG$=$=>

r   c                    t        j                         }|j                         }|j                  |       | j	                  t
        |j                  t                      |j                         }|j                  |       | j                  ||j                                | j                  ||j                                |j                          |j                          y r   )r   r  r/   r0   r   rK  r~  rl  r  assertIsNotrA   )r7   r  old_loopr2   s       r   test_set_event_loopzPolicyTests.test_set_event_loop
  s    //1((*h')V%:%:FHE$$&d#dF11346#8#8#:;

r   c                     t        j                         }| j                  |t         j                         | j	                  |t        j                                y r   )r   rd  ri  r  rl  r  s     r   test_get_event_loop_policyz&PolicyTests.test_get_event_loop_policy
  s=    ..0fg&E&EFfg;;=>r   c                 D   | j                  t        t        j                  t	                      t        j
                         }t        j                         }t        j                  |       | j                  |t        j
                                | j                  ||       y r   )	r   rK  r   r   r~  rd  r  rl  r  )r7   
old_policyr  s      r   test_set_event_loop_policyz&PolicyTests.test_set_event_loop_policy
  ss    w44fh	@ 224
//1%%f-fg;;=>,r   N)rD   rE   rF   r  r  r  r  r   r  r  r  r  r  r  r   r   r   r  r  {
  sJ    $
&?
 TZZ9: ;?
	-r   r  c                   h     e Zd ZdZdZdZdZ fdZ fdZe	j                  dk7  rd Zd Zd Z xZS )GetEventLoopTestsMixinNc                 P   t         j                  | _        t         j                  | _        t         j
                  | _        t         j                  | _        t        |       j                  t         _        t        |       j                  t         _        t        |       j                  t         _        t        |       j                  t         _        t        |       j                  t        _        t        |       j                  t        _        t        |       j                  t        _        t        |       j                  t        _        t        | A          t        j"                         | _        t        j&                  | j$                         t(        j*                  dk7  r|t-        j.                         5  t-        j0                  dt2               t        j4                         }|j7                  | j$                         t        j8                  |       d d d        y y # 1 sw Y   y xY wNr   r  )r   _get_running_loop_get_running_loop_saved_set_running_loop_set_running_loop_savedget_running_loopget_running_loop_savedr  get_event_loop_savedr  _get_running_loop_impl_set_running_loop_implget_running_loop_implget_event_loop_implr   rs   r   r/   r2   r0   r   r    r	  r
  r  r  r  r  r  r  s     r   r   zGetEventLoopTestsMixin.setUp
  sl   '-'?'?$'-'?'?$&,&=&=#$*$9$9!#':#D#D #':#D#D "&t*"B"B $T
 > >$(J$E$E!$(J$E$E!#':#C#C !%d!?!?**,	tyy)<<7"((* 3%%h0BC!224##DII.))'2	3 3 #3 3s   3AHH%c                 `   	 t         j                  dk7  rLt        j                         5  t        j                  dt
               t        j                  d        d d d        t        | %          | j                  j                          t        j                  d        | j                  t        _        | j                   t        _        | j$                  t        _        | j(                  t        _        | j                  t        _        | j                   t        _        | j$                  t        _        | j(                  t        _        y # 1 sw Y   xY w# | j                  j                          t        j                  d        | j                  t        _        | j                   t        _        | j$                  t        _        | j(                  t        _        | j                  t        _        | j                   t        _        | j$                  t        _        | j(                  t        _        w xY wr  )r   r    r	  r
  r  r  r   r  rs   r   r2   rA   r0   r  r   r  r  r  r  r  r  r  r   s    r   r   zGetEventLoopTestsMixin.tearDown
  s|   	?||w&,,. 4))(4FG--d34 GIIOO""4('+'C'CF$'+'C'CF$&*&A&AF#$($=$=F!(,(D(DG%(,(D(DG%'+'B'BG$%)%>%>G"#4 4 IIOO""4('+'C'CF$'+'C'CF$&*&A&AF#$($=$=F!(,(D(DG%(,(D(DG%'+'B'BG$%)%>%>G"s#   'E 0EE EE CH-r   c                      t        j                           j                  t                fd} j	                   j
                  j                   |             d       y )Nc                  "  K   t        j                         dk(  rt        j                  d      } nd } t        j                  j                  |       }j                  j                  |t               d {   }|j                          |S 7 w)Nfork
forkserver)
mp_context)
multiprocessingget_start_methodget_context
concurrentfuturesProcessPoolExecutorr2   r  r3   shutdown)r  poolr  r7   s      r   r`  zDGetEventLoopTestsMixin.test_get_event_loop_new_process.<locals>.main  s     "335?!0!<!<\!JJ!%J!))==#- > /#yy88D F FFs   A3B6B7Br,   )r   *skip_if_broken_multiprocessing_synchronizer  multiprocessing_cleanup_testsr   r2   r1   )r7   r`  s   ` r   test_get_event_loop_new_processz6GetEventLoopTestsMixin.test_get_event_loop_new_process  sJ     >>@OO9: 		,,TV4r   c                      G d dt                G fddt        j                        }t        j                         }	 t        j                   |              t        j
                          j                        5  t        j                          d d d        t        j                  d         j                        5  t        j                          d d d         j                  t        d      5  t        j                          d d d         j                  t        j                         d         fd}j                   |              t        j                          j                        5  t        j                          d d d        t        j                  d         j                        5  t        j                          d d d        t        j                  |       j                          	  j                  t        d      5  t        j                          d d d         j                  t        j                         d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   jxY w# 1 sw Y   xY w# 1 sw Y   xY w# t        j                  |       j                          w w xY w# 1 sw Y   xY w)Nc                       e Zd Zy)RGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.TestErrorN)rD   rE   rF   r   r   r   	TestErrorr  0  s    r   r  c                       e Zd Z fdZy)OGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.Policyc                     r   r   )r7   r  s    r   r  z^GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.Policy.get_event_loop4  s    r   N)rD   rE   rF   r  )r  s   r   Policyr  3  s     r   r  
no runningc                     K   j                  t        j                                 j                  t        j                                 j                  t        j                                 y wr   rl  r   r  r  r  r|  s   r   r  zMGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.funcF  L     g446=g668$?g7794@   A.A1)r  r   r  rd  r   r/   r   r  r0   r  r   r  rl  r  r1   rA   )r7   r  r  r  r  r2   s   `   @@r   (test_get_event_loop_returns_running_loopz?GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop/  s+   		 		 W33 	  224
	))&(3))+D""9- )&&()""4(""9- )&&() ''lC +((*+MM'335t<A
 ##DF+""4(""9- )&&()""4(""9- )&&() ))*5

##L,? 	'$$&	' 	g//148A) )) )+ +) )) ) ))*5

  	' 	's   ?J I.J I(J 8I5A.J ;J.J >JJ KI% J (I2-J 5I?:J JJ JJ *KKc                     t        j                         }	 t        j                  t        j                                t        j                          j                  j                          j                  t              5 }t        j                         }d d d         j                  j                          j                  j                  t               t        j                  d         j                  t        d      5  t        j                          d d d         j                  t        d      5  t        j                           d d d         j#                  t        j$                         d         fd}j'                   |              t        j                          j#                  t        j                                t        j                  d         j                  t        d      5  t        j                          d d d        t        j                  |       j                          	  j                  t        d      5  t        j                           d d d         j#                  t        j$                         d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   exY w# 1 sw Y   xY w# t        j                  |       j                          w w xY w# 1 sw Y   xY w)Nz
no currentr  c                     K   j                  t        j                                 j                  t        j                                 j                  t        j                                 y wr   r  r|  s   r   r  zNGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop2.<locals>.funcq  r  r  )r   rd  r   r  r/   r  rA   r  r  r  r   rS  r  r0   r  r   r  rl  r  r1   )r7   r  r  loop2r  r2   s   `    @r   )test_get_event_loop_returns_running_loop2z@GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop2^  s7   224
"	))'*H*H*JK))+DOODJJ'!!"45 1..01OOEKK(R[[(3""4(''lC )&&() ''lC +((*+MM'335t<A
 ##DF+""4(MM'002D9""4(''lC )&&() ))*5

##L,? 	'$$&	' 	g//148E1 1
) )+ +) ) ))*5

  	' 	'sz   A+K
 JA.K
 J$K
 9J1B,K
 :J>K
 K7J!K
 $J.)K
 1J;6K
 >KK
 
*K47L )rD   rE   rF   r  r  r  r  r   r   r   r    r  r  r  rw   rx   s   @r   r  r  
  sC    !! 38?, ||w	2-9^)9r   r  c                   l    e Zd Zej                  Zej                  Zej                  Z	ej                  Zy)TestPyGetEventLoopN)rD   rE   rF   r   _py__get_running_loopr  _py__set_running_loopr  _py_get_running_loopr  _py_get_event_loopr  r   r   r   r  r    s2    #99#99"77 33r   r  c                   l    e Zd Zej                  Zej                  Zej                  Z	ej                  Zy)TestCGetEventLoopN)rD   rE   rF   r   _c__get_running_loopr  _c__set_running_loopr  _c_get_running_loopr  _c_get_event_loopr  r   r   r   r  r    s2    !'!<!<!'!<!< & : :$66r   r  c                       e Zd Zd Zy)
TestServerc                 b   t        j                         }| j                  |j                         t	        |      |j                  |j                  fddd            }| j                  |j                         |       |j                          |j                  |j                                y )Nc                       S r   r   r  s   r   r.  z*TestServer.test_get_loop.<locals>.<lambda>  s    E r   r1  r   )
r   r/   r  rA   rq   r1   r  r   get_loopwait_closed)r7   r2   r&  r  s      @r   test_get_loopzTestServer.test_get_loop  s    %%'

#((););M9VW)XY*D1 2 2 45r   N)rD   rE   rF   r  r   r   r   r
  r
    s    6r   r
  c                       e Zd Zd Zd Zd Zy)TestAbstractServerc                     | j                  t              5  t        j                         j	                          d d d        y # 1 sw Y   y xY wr   )r   r  r   AbstractServerrA   r@   s    r   r  zTestAbstractServer.test_close  s;    23 	,!!#))+	, 	, 	,   #AAc                    t        j                         }| j                  |j                         | j	                  t
              5  |j                  t        j                         j                                d d d        y # 1 sw Y   y xY wr   )
r   r/   r  rA   r   r  r1   r   r  r  rR   s     r   test_wait_closedz#TestAbstractServer.test_wait_closed  sh    %%'

#23 	K##F$9$9$;$G$G$IJ	K 	K 	Ks   2B  B	c                     | j                  t              5  t        j                         j	                          d d d        y # 1 sw Y   y xY wr   )r   r  r   r  r  r@   s    r   r  z TestAbstractServer.test_get_loop  s;    23 	/!!#,,.	/ 	/ 	/r  N)rD   rE   rF   r  r  r  r   r   r   r  r    s    ,K/r   r  __main__)R__doc__collections.abcro  concurrent.futuresr  r  r
  r  rR  r    r  rO  r2  r  ImportErrorr  r   r   r   rM  r  r  r   rC  r	  rS  r   r   r   r   multiprocessing.utilr	   r  test.test_asyncior
   r   r  r   test.supportr   r   r   r   r   r   r(   r3   r5   rk  rH   rq   r  rz   r   BaseProtocolr   r  r   r   r  TestCaser  r  r  r  r  r  r  r"  r(  r*  rr  r  r  r  r  _asyncior  r
  r  rD   r`  r   r   r   <module>r#     s       	  	  	    
        <<++    # P 1  & ) 5 5(+ #''"" #'LHk H'g.. '@!'g&& !'H'w++ '2*:755 *:ZP Pf2[? [?| <<7/2)22/P!4!5!+!4!4P, "5   y*+	)#:#7#-#6#6	)0 y/*	L"9"6","5"5	L y.)	K!8!5!+!4!4	KI63)22I	oF*%% oFdC("" C(LcX.. cL]-(## ]-@l9 l9^4/1B1B 47
72H4E4E 7	6"" 	6/** /$ zHMMO _]  
CJ\  		s#   K  K* K'&K'*K21K2