
    dafO>                    `   d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl	m
Z
 ddl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Ze
j2                  Zd Zd Zd Z G d dej<                        Z G d dej<                        Z  G d dejB                        Z" G d dejF                        Z$ G d dej<                        Z% G d de	j<                        Z& G d dej<                        Z' G d dej<                        Z(e)dk(  r e	jT                          yy)zTests for base_events.py    N)mock)base_events)	constants)utils)support)assert_python_ok)	os_helper)socket_helperc                  .    t        j                  d        y N)asyncioset_event_loop_policy     =/root/Python-3.12.4/Lib/test/test_asyncio/test_base_events.pytearDownModuler      s    !!$'r   c            	      0   t        j                  t              } dD ]:  }t        t        |      rt	        | |t        t        |             /t        | |       < t        j                         | _        t        j                         | j                  _	        | S )N)spec)
AF_INETAF_INET6	AF_UNSPECIPPROTO_TCPIPPROTO_UDPSOCK_STREAM
SOCK_DGRAM
SOL_SOCKETSO_REUSEADDR	inet_pton)
r   	MagicMocksockethasattrsetattrgetattrdelattr
test_utilsmock_nonblocking_socketreturn_value)m_socketnames     r   mock_socket_moduler*      st    ~~6*H $ 64 HdGFD$9:Hd#$ nn&HO#-#E#E#GHOO Or   c                 D     t        j                  dt              |       S )Nzasyncio.base_events.socket)new_callable)r   patchr*   )fs    r   patch_socketr/   /   s%    74::2#5778: :r   c                   (    e Zd Zd Zd Zed        Zy)BaseEventTestsc           
      &   t         j                  }t         j                  }t         j                  }t         j                  }t         j
                  }t         j                  }t         j                  }| j                  |||ddft        j                  dd|||             | j                  |||ddft        j                  dd|||             | j                  |||ddft        j                  dd|||             | j                  |||ddft        j                  dd|||             | j                  |||ddft        j                  dd||d             | j                  |||ddft        j                  dd||d             | j                  t        j                  dd|dd             t        j                  r| j                  t        j                  dd|||             | j                  |||ddft        j                  dd|||             | j                  |||ddft        j                  dd|||             | j                  t        j                  dd|||             | j                  t        j                  d	d|||             y y )
N 1.2.3.4   r5   r6   s   1.2.3.4r   )::3r6   r   r   r7   z::3%lo0)r    r   r   r   r   r   r   r   assertEqualr   _ipaddr_infoassertIsNoner
   IPV6_ENABLED)selfUNSPECINETINET6STREAMDGRAMTCPUDPs           r   test_ipaddr_infozBaseEventTests.test_ipaddr_info6   s   !!~~##!!    63N3$$Y4E	G 	63N3$$ZD&#F	H 	63N3$$Y663G	I 	5#r>2$$Y65#F	H
 	63N3$$Y661E	G
 	5#r>2$$Y65!D	F
 	$$Y61a@	B %%((AufcJL R)9:((5&#FH R)9:((663GI
 ((4EG ((AufcJL% &r   c           
      0   t         j                  }t         j                  }t         j                  }| j	                  |||ddft        j                  dd |||             | j	                  |||ddft        j                  dd|||             | j	                  |||ddft        j                  dd|||             | j	                  |||ddft        j                  dd|||             | j	                  |||ddft        j                  dd|||             y )Nr3   r5   r   r5   r   r4   1   1)r    r   r   r   r8   r   r9   )r<   r>   r@   rB   s       r   test_port_parameter_typesz(BaseEventTests.test_port_parameter_typesr   s(   ~~##  63N3$$YdFCH	J 	63N3$$YT63G	I 	63N3$$YD&#F	H 	63N3$$YT63G	I 	63N3$$YdFCH	Jr   c           	          |` | j                  t        j                  ddt        j
                  t        j                  t        j                               y )Nr5   r6   )r   r:   r   r9   r    r   r   r   r<   r(   s     r   test_ipaddr_info_no_inet_ptonz,BaseEventTests.test_ipaddr_info_no_inet_pton   sB    +229a39>>393E3E393E3EG 	Hr   N)__name__
__module____qualname__rD   rI   r/   rL   r   r   r   r1   r1   4   s%    :LxJ4 H Hr   r1   c                   &    e Z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d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/ xZ0S ).BaseEventLoopTestsc                    t         |           t        j                         | _        t        j                         | j                  _        d| j                  j                  j                  _	        | j                  | j                         y Nr   )supersetUpr   BaseEventLooploopr   Mock	_selectorselectr'   set_event_loopr<   	__class__s    r   rU   zBaseEventLoopTests.setUp   sX    --/	"iik		24		""/DII&r   c           	      J   t        j                         }| j                  t        | j                  j
                  ||       | j                  t        | j                  j                  ||||       | j                  t        | j                  j                  ||       | j                  t        | j                  j                  g        | j                  t        | j                  j                         | j                  t        | j                  j                  ||       | j                  t        | j                  j                  ||       | j                  j                  |||||||      }| j                  t              5  |j                  d        d d d        y # 1 sw Y   y xY wr   )r   rX   assertRaisesNotImplementedErrorrW   _make_socket_transport_make_ssl_transport_make_datagram_transport_process_events_write_to_self_make_read_pipe_transport_make_write_pipe_transport_make_subprocess_transportsend)r<   mgens      r   test_not_implementedz'BaseEventLoopTests.test_not_implemented   sQ   IIKII,,a	4 	II))1aA	7 	II..1	6 	!:!:B	@!9!9	;II//A	7 	II00!Q	8 ii221aAq!QG23 	HHTN	 	 	s   >FF"c                 "   | j                  | j                  j                                | j                  j                          | j	                  | j                  j                                | j                  j                          | j                  j                          | j                  j                         }| j                  t        | j                  j                         | j                  t        | j                  j                  |       y r   )
assertFalserW   	is_closedclose
assertTruecreate_futurer_   RuntimeErrorrun_foreverrun_until_complete)r<   r.   s     r   
test_closezBaseEventLoopTests.test_close   s    ,,./				++-. 					 II##%,		(=(=>,		(D(DaHr   c                    t        j                  d d| j                  d       }| j                  j                  |       | j	                  | j                  j
                         | j                  || j                  j                         y )Nc                       yNFr   r   r   r   <lambda>z>BaseEventLoopTests.test__add_callback_handle.<locals>.<lambda>       r   r   )r   HandlerW   _add_callbackrn   
_scheduledassertIn_readyr<   hs     r   test__add_callback_handlez,BaseEventLoopTests.test__add_callback_handle   s\    NN="dii>		"--.a))*r   c                 4   t        j                  d d| j                  d       }|j                          | j                  j	                  |       | j                  | j                  j                         | j                  | j                  j                         y )Nc                       yry   r   r   r   r   rz   zHBaseEventLoopTests.test__add_callback_cancelled_handle.<locals>.<lambda>   r{   r   r   )r   r|   rW   cancelr}   rn   r~   r   r   s     r   #test__add_callback_cancelled_handlez6BaseEventLoopTests.test__add_callback_cancelled_handle   se    NN="dii>	
		"--.))*r   c                 f    G d dt         j                  j                        }t        j                         | j
                  _        t        j                         | j
                  _         |       }| j
                  j                  |       | j                  || j
                  j                         y )Nc                       e Zd Zd Zy)CBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutorc                     t        d      )Nz#cannot submit into a dummy executor)r`   )r<   fnargskwargss       r   submitzJBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutor.submit   s    )9; ;r   N)rM   rN   rO   r   r   r   r   DummyExecutorr      s    ;r   r   )
concurrentfuturesThreadPoolExecutorr   rX   rW   rd   re   set_default_executorassertIs_default_executorr<   r   executors      r   test_set_default_executorz,BaseEventLoopTests.test_set_default_executor   sq    	;J..AA 	;
 %)IIK		!#'99;		  ?		&&x0h		 ; ;<r   c                    t        j                         }d}| j                  t        |      5  | j                  j                  |       d d d        | j                  | j                  j                         y # 1 sw Y   /xY w)Nz,executor must be ThreadPoolExecutor instance)r   rX   assertRaisesRegex	TypeErrorrW   r   r:   r   )r<   r   msgs      r   test_set_default_executor_errorz2BaseEventLoopTests.test_set_default_executor_error   sc    99;<##Is3 	5II**84	5 	$))556	5 	5s   A77B c                     G d dt         j                  j                        }t        j                         | j
                  _        t        j                         | j
                  _         |       }| j
                  j                  |       | j                  t        d      5  | j
                  j                  | j
                  j                  d             d d d        y # 1 sw Y   y xY w)Nc                       e Zd ZddddZy)PBaseEventLoopTests.test_shutdown_default_executor_timeout.<locals>.DummyExecutorF)cancel_futuresc                4    |rt        j                  d       y y )N皙?)timesleep)r<   waitr   s      r   shutdownzYBaseEventLoopTests.test_shutdown_default_executor_timeout.<locals>.DummyExecutor.shutdown   s    JJsO r   N)T)rM   rN   rO   r   r   r   r   r   r      s    $E $r   r   z&The executor did not finishing joining{Gz?)timeout)r   r   r   r   rX   rW   rd   re   r   assertWarnsRegexRuntimeWarningru   shutdown_default_executorr   s      r   &test_shutdown_default_executor_timeoutz9BaseEventLoopTests.test_shutdown_default_executor_timeout   s    	$J..AA 	$
 %)IIK		!#'99;		  ?		&&x0"">#KM 	CII((		33D3AC	C 	C 	Cs   "6C!!C*c                    d }| j                   j                  |      }| j                  |j                  |       | j	                  |t
        j                         | j                  || j                   j                         y )Nc                       y r   r   r   r   r   cbz-BaseEventLoopTests.test_call_soon.<locals>.cb       r   )	rW   	call_soonr8   	_callbackassertIsInstancer   r|   r   r   r<   r   r   s      r   test_call_soonz!BaseEventLoopTests.test_call_soon   s]    	 II#b)a0a))*r   c                     | j                   j                  d       | j                  t        d      5  | j                   j	                  d       d d d        y # 1 sw Y   y xY w)NTza callable objectr6   )rW   	set_debugr   r   r   r<   s    r   test_call_soon_non_callablez.BaseEventLoopTests.test_call_soon_non_callable  sL    		D!##I/BC 	#II"	# 	# 	#s   AA c                    d }| j                   j                  d|      }| j                  |t        j                         | j                  || j                   j                         | j                  || j                   j                         | j                  t        d      5  | j                   j                  d |       d d d        y # 1 sw Y   y xY w)Nc                       y r   r   r   r   r   r   z.BaseEventLoopTests.test_call_later.<locals>.cb	  r   r         $@zdelay must not be Noner   )rW   
call_laterr   r   TimerHandler   r~   assertNotInr   r_   r   r   s      r   test_call_laterz"BaseEventLoopTests.test_call_later  s    	 II  r*a!4!45a--.DII,,-y.FG 	+II  r*	+ 	+ 	+s   #C		Cc                 4   g fd}t        j                         | j                  _        | j                  j	                  d|d       | j                  j	                  d|d       t        j                  | j                         | j                  ddg       y )Nc                 (    j                  |        y r   )append)argcallss    r   r   z>BaseEventLoopTests.test_call_later_negative_delays.<locals>.cb  s    LLr   ab)r   rX   rW   rd   r   r%   run_brieflyr8   )r<   r   r   s     @r   test_call_later_negative_delaysz2BaseEventLoopTests.test_call_later_negative_delays  ss    	 %)IIK		!		RS)		RS)tyy)c
+r   c                 D     fd}t        j                          j                  _        d} j                  j	                         |z   } j                  j                  ||        j                  j	                         } j                  j                           j                  j	                         |z
  } j                  ||t        j                  z
          j                  t        d      5   j                  j                  d |       d d d        y # 1 sw Y   y xY w)Nc                  :     j                   j                          y r   rW   stopr   s   r   r   z4BaseEventLoopTests.test_time_and_call_at.<locals>.cb   s    IINNr   r   zwhen cannot be Noner   )r   rX   rW   rd   r   call_atrt   assertGreaterEqualr%   	CLOCK_RESr_   r   )r<   r   delaywhent0dts   `     r   test_time_and_call_atz(BaseEventLoopTests.test_time_and_call_at  s    	 %)IIK		!yy~~%'		$#YY^^		YY^^" 	EJ,@,@$@Ay.CD 	(IIdB'	( 	( 	(s   0DDc                 P   d }|j                  |       |rd}| j                  t        |      5  |j                  |       d d d        | j                  t        |      5  |j	                  d|       d d d        | j                  t        |      5  |j                  |j                         dz   |       d d d        y |j                  |       |j	                  d|       |j                  |j                         dz   |       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nc                       y r   r   r   r   r   r   z+BaseEventLoopTests.check_thread.<locals>.cb2  r   r   zMNon-thread-safe operation invoked on an event loop other than the current one<   )r   r   rs   r   r   r   r   )r<   rW   debugr   r   s        r   check_threadzBaseEventLoopTests.check_thread1  s    	 	u*C''c: #r"#''c: (B'(''c: 3TYY[2-r23 3 NN2OOB#LLr)2.# #( (3 3s#   DD$DDDD%c                 J     fddfd	}t        j                          j                  _        t        j                          j                  _         | j                  d        | j                  d        | j                  dd        | j                  dd       y )Nc                    |j                          	 |rbt        j                         }	 t        j                  |       j                  | |       t        j                  d        |j                          nj                  | |       | j                  |j                  d        y # t        j                  d        |j                          w xY w# t        $ r&}| j                  |j                  |       Y d }~y d }~ww xY wr   )r   r   rV   r   r[   r   rp   call_soon_threadsafe
set_result	Exceptionset_exception)rW   eventr   create_loopfutloop2excr<   s          r   check_in_threadz=BaseEventLoopTests.test_check_thread.<locals>.check_in_threadE  s    JJL@'557E&..u5))$6..t4%%dE2 ))#..$?  ..t4  B))#*;*;SAABs.   C 'B& 8C &'CC 	C?C::C?Fc                 "   t        j                         }| j                         }| j                  |j                         | ||||f}t        j
                  |      }|j                          | j                  |       |j                          y )N)targetr   )		threadingEventrr   r   setThreadstartru   join)rW   r   r   r   r   r   threadr   s          r   test_threadz9BaseEventLoopTests.test_check_thread.<locals>.test_threadY  so    OO%E$$&CNN599%%S9D%%_4HFLLN##C(KKMr   T)r   F)r   rX   rW   rd   re   )r<   r   r   s   ` @r   test_check_threadz$BaseEventLoopTests.test_check_threadD  sx    	@(	 %)IIK		!#'99;		  	DIIt$ 	DIIu% 	DIIt6 	DIIu$7r   c                 b   t        j                  t        j                         dz   d d| j                  d       }t        j                  t        j                         dz   d d| j                  d       }|j                          t        j                         | j                  _        | j                  j                  j                  |       | j                  j                  j                  |       | j                  j                          | j                  j                  j                  j                  d   d   }| j                  d|cxk  xr dk  nc |       | j!                  |g| j                  j                         | j                  | j                  j                  j"                         y )	Ng      @c                       yNTr   r   r   r   rz   z3BaseEventLoopTests.test__run_once.<locals>.<lambda>t  r{   r   r   r   c                       yr   r   r   r   r   rz   z3BaseEventLoopTests.test__run_once.<locals>.<lambda>v  r{   r   r   g      #@g      %@)r   r   r   	monotonicrW   r   r   rX   rd   r~   r   	_run_oncerY   rZ   	call_argsrq   r8   called)r<   h1h2ts       r   test__run_oncez!BaseEventLoopTests.test__run_onces  s(     !1C!7r!%D2  !1D!8,!%D2 			$(IIK		!		##B'		##B'		II&&003A6a$*"tyy334		11889r   c                    | j                   j                  d       | j                  | j                   j                                | j                   j                  d       | j	                  | j                   j                                y )NTF)rW   r   rq   	get_debugrn   r   s    r   test_set_debugz!BaseEventLoopTests.test_set_debug  sZ    		D!		++-.		E",,./r   c                    d dfd}t        j                  t        j                         dz
  || j                  f| j                  d       }t        j                         | j                  _        | j                  j                  j                  |       | j                  j                          | j                         | j                  gt        | j                  j                               y )NFc                 .    d| j                  d       y )NTc                       yr   r   r   r   r   rz   zOBaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb.<locals>.<lambda>  r{   r   )r   )rW   handle	processeds    r   r   z=BaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb  s    I^^L1Fr   r6   )r   r   r   r   rW   r   rX   rd   r~   r   r   rq   r8   listr   )r<   r   r   r
  r  s      @@r   test__run_once_schedule_handlez1BaseEventLoopTests.test__run_once_schedule_handle  s    		2
  01 4b499, $		41 %)IIK		!		##A&			"&4		(8(8#9:r   c                    t        j                         | j                  _        | j	                  dt
        j                  cxk  xr dk  nc        d }d}| j                  j                  d|       d}t        d      D ].  }| j                  j                  d|      }|j                          0 |dz  }t        d      D ].  }| j                  j                  d|      }|j                          0 | j                  ||z   t
        j                         | j                  | j                  j                  |       | j                  j                          |dz  }| j                  | j                  j                  |       | j                  t        | j                  j                         ||z          t#        t%        j&                  t
        j                  t
        j                  z              dz   }t)        t
        j                  |z
  d      }||z  }t        |      D ]  }| j                  j                  d|         ||z  }t        |      D ].  }| j                  j                  d|      }|j                          0 | j                  t        | j                  j                         ||z          | j                  j                          | j                  t        | j                  j                         |       | j	                  t+        | j                  j                   D cg c]  }|j,                    c}             y c c}w )	Nr   g      ?c                       y r   r   r   r   r   r   zEBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.cb  r   r   r6        i  d   )r   rX   rW   rd   rq   r   %_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr   ranger   assertLessEqual_MIN_SCHEDULED_TIMER_HANDLESr8   _timer_cancelled_countr   lenr~   intmathceilmaxall
_cancelled)r<   r   not_cancelled_countcancelled_countxr   add_cancel_countadd_not_cancel_counts           r   &test__run_once_cancelled_event_cleanupz9BaseEventLoopTests.test__run_once_cancelled_event_cleanup  s   $(IIK		!AAGCG	I	  		T2&
 q 	A		$$T2.AHHJ	
 	1q 	A		$$S"-AHHJ	
 	_/BB44	6 	99?K		199?KTYY11211	3
 tyy44==> ? @BCD  #;#K#K$ ! 	33+, 	+AII  r*	+ 	++'( 	A		$$T2.AHHJ	
 	TYY11211	3 			 	TYY1124GH 	tyy7K7KL!-LMNLs   #Mc                 Z    | j                  t        | j                  j                  d       y )Nblah)r_   r   rW   ru   r   s    r   "test_run_until_complete_type_errorz5BaseEventLoopTests.test_run_until_complete_type_error  s!    )II((&	2r   c                     | j                   j                         }| j                         }| j                  |j                         | j                  t        |j                  |       y r   )rW   rr   new_test_loop
addCleanuprp   r_   
ValueErrorru   )r<   task
other_loops      r   test_run_until_complete_loopz/BaseEventLoopTests.test_run_until_complete_loop  sO    yy&&('')

(()*))4	1r   c                     G d dt               d }fd}t        j                         | j                  _        | j                  j                  |       | j                        5  | j                  j                   |d             d d d        | j                  j                   |d             y # 1 sw Y   +xY w)Nc                       e Zd Zy)]BaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.ShowStopperNrM   rN   rO   r   r   r   ShowStopperr1        r   r3  c                 J   K   t        j                  |        d {    y 7 wr   r   r   )r   s    r   foozUBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.foo  s     --&&&s   #!#c                       r   r   )r3  s   r   throwzWBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.throw  s	    r   r   g?)
SystemExitr   rX   rW   rd   r   r_   ru   )r<   r7  r9  r3  s      @r   5test_run_until_complete_loop_orphan_future_close_loopzHBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop  s    	* 		'	 %)IIK		!		E"{+ 	3II((S2	3
 			$$SX.	3 	3s   ("B44B=c                    t         j                  ddg}| j                  t        | j                  j
                  | j                  j                  t        j                         | j                  t        | j                  j
                  | j                  j                  t        j                  |       | j                  t        | j                  j
                  | j                  j                  t        j                  t         j                  d        | j                  t        | j                  j
                  | j                  j                  t        j                  g|ddi  | j                  t        | j                  j
                  | j                  j                  t        j                  g|ddi  | j                  t        | j                  j
                  | j                  j                  t        j                  g|ddi y )	N-cpass{   universal_newlinesTshellbufsize   )	sys
executabler_   r   rW   ru   subprocess_execr   SubprocessProtocol)r<   r   s     r   !test_subprocess_exec_invalid_argsz4BaseEventLoopTests.test_subprocess_exec_invalid_args  s   f- 	)II(($))*C*C&&	(
 	)II(($))*C*C&&	.
 	)II(($))*C*C&&	=
 	)		$$dii&?&?&&	H)-	HBF	H 	)II(($))*C*C&&	;)-	;59	; 	)II(($))*C*C&&	=)-	=7;	=r   c           	      H   | j                  t        | j                  j                  | j                  j                  t
        j                  d       | j                  t        | j                  j                  | j                  j                  t
        j                  t        j                  ddg       | j                  t        | j                  j                  | j                  j                  t
        j                  dd       | j                  t        | j                  j                  | j                  j                  t
        j                  dd       | j                  t        | j                  j                  | j                  j                  t
        j                  dd	       y )
Nr?  r=  r>  zexit 0T)r@  )rA  rC  )rB  )	r_   r   rW   ru   subprocess_shellr   rG  rD  rE  r   s    r   "test_subprocess_shell_invalid_argsz5BaseEventLoopTests.test_subprocess_shell_invalid_args%  s1   )II(($))*D*D&&	- 	)II(($))*D*D&&v(F	H
 	)II(($))*D*D&&T 	 	K 	)II(($))*D*D&& 	 	> 	)II(($))*D*D&&$ 	 	@r   c                     t        j                          j                  _        d }t        j                  d      5 } j                  j                         } j                  j                  ||       |j                   fd        j                  j                          |j                  j                  t        j                  d      t        t        t        f       d d d        t        j                  d      5 } j                  j                         } j                  j                  d||       |j                   fd        j                  j                          |j                  j                  t        j                  d      t        t        t        f       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                 0    | j                  d       ddz   y )NTr6   r   )r   r   s    r   
zero_errorzHBaseEventLoopTests.test_default_exc_handler_callback.<locals>.zero_error<  s    NN4 aCr   asyncio.base_events.loggerc                 8    j                   j                         S r   r   r   r<   s    r   rz   zFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>D      diinn.> r   Exception in callback.*zeroexc_infor   c                 8    j                   j                         S r   r   rR  s    r   rz   zFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>N  rS  r   )r   rX   rW   rd   r-   rr   r   add_done_callbackrt   errorassert_called_withr%   MockPatternZeroDivisionErrorMOCK_ANYr   )r<   rO  logr   s   `   r   !test_default_exc_handler_callbackz4BaseEventLoopTests.test_default_exc_handler_callback9  sb   $(IIK		!	
 ZZ45 	B))))+CII
C0!!">?II!!#II((&&'DE+Xx@ ) B	B ZZ45 	B))))+CII  z37!!">?II!!#II((&&'DE+Xx@ ) B	B 	B	B 	B	B 	Bs   B$F,>B%F8,F58Gc                     t        j                          j                  _        d }t        j                  d      5 }t        j                   |        j                        }|j                   fd        j                  j                          d }t        j                          |j                  j                  t        j                  d      t        t         t         f       d d d        y # 1 sw Y   y xY w)Nc                  T   K   t        j                  d       d {    ddz   y 7 
w)Nr   r6   r   r6  r   r   r   zero_error_corozIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_coroW  s$     --%%%aC &s   (&(rP  rW   c                  8    j                   j                         S r   r   )r   r<   s    r   rz   zBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>^  s    		0@ r   z.*exception was never retrievedrU  )r   rX   rW   rd   r-   r   ensure_futurerX  rt   r   
gc_collectrY  rZ  r%   r[  r\  r]  )r<   rb  r^  r   s   `   r   test_default_exc_handler_coroz0BaseEventLoopTests.test_default_exc_handler_coroT  s    $(IIK		!	
 ZZ45 		B''(9		JC!!"@AII!!#C II((&&'HI+Xx@ ) B		B 		B 		Bs   B*C00C9c                     | j                  t        d      5  | j                  j                  d       d d d        y # 1 sw Y   y xY w)NzA callable object or Nonespam)r   r   rW   set_exception_handlerr   s    r   test_set_exc_handler_invalidz/BaseEventLoopTests.test_set_exc_handler_invalidg  s:    ##I/JK 	4II++F3	4 	4 	4s	   <Ac                     d  fd} j                   j                  d       t        j                          j                   _         j                   j                   j                                t        j                         } j                   j                  |        j                   j                   j                         |        |       }|j                   j                   t        t        j                  d      ||j                  d       |j                           j                   j                  d        t        j                  d      5 } |        |j                   j                  t        j                  d      t"        t        t        f       d d d         j%                  |j&                         y # 1 sw Y   %xY w)	Nc                      ddz   y Nr6   r   r   r   r   r   rO  zBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_errorl  s	    aCr   c                  r    j                   j                        } j                   j                          | S r   rW   r   r   )r
  r<   rO  s    r   run_loopz@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopo  s,    YY((4FII!Mr   Tz!Exception in callback.*zero_error)	exceptionmessager
  source_tracebackrP  rT  rU  )rW   r   r   rX   rd   r:   get_exception_handlerrj  r   rZ  r]  r%   r[  _source_traceback
reset_mockr-   rY  r\  rn   r   )r<   rq  mock_handlerr
  r^  rO  s   `    @r   test_set_exc_handler_customz.BaseEventLoopTests.test_set_exc_handler_customk  s]   		
 			D!$(IIK		!$))99;<yy{		''5dii557F''		!!-- CE & 8 84
 	 	!		''-ZZ45 	JJII((".. =?"3Xx!H ) J	J 	,,-	J 	Js   AG  G	c                 r     fd}d }t        j                          j                  _         j                  j	                  |       t        j
                  d      5 } |        |j                  j                  t        j                  d      t        t        t        f       d d d        y # 1 sw Y   y xY w)Nc                  v    d } j                   j                  |        j                   j                          y )Nc                      ddz   y rn  r   r   r   r   rO  zTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_error  	    !r   rp  )rO  r<   s    r   rq  z@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop  s*    II
+II!r   c                     t        d      Nri  )AttributeErrorrW   contexts     r   handlerz?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handler  s     ((r   rP  z$Unhandled error in exception handlerrU  )r   rX   rW   rd   rj  r-   rY  rZ  r%   r[  r  r]  )r<   rq  r  r^  s   `   r   test_set_exc_handler_brokenz.BaseEventLoopTests.test_set_exc_handler_broken  s    	"	) %)IIK		!		''0ZZ45 	?JII((&&:<((H= ) ?	? 	? 	?s   AB--B6c                    d  G fddt         j                        } |       | j                  j                         t	        j
                         fd}t        j                  d      5 } |        |j                  j                  dd       d d d        d }d j                  |       t        j                  d      5 } |        |j                  j                  t        j                  d	      d       | j                  d
       | j                  t        d
   d         t                d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                   \    e Zd Z ej                         Z ej                         Z fdZy)@BaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loopc                     |t        d      r  r+  )r<   r  _contexts     r   default_exception_handlerzZBaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loop.default_exception_handler  s    " ((r   N)rM   rN   rO   r   rX   rY   rd   r  )r  s   r   Loopr    s"    !		I'diikO)r   r  c                  N    d } j                  |        j                          y )Nc                      ddz   y rn  r   r   r   r   rO  zXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error  r}  r   )r   r   )rO  rW   s    r   rq  zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop  s    NN:&NNr   rP  z&Exception in default exception handlerTrU  c                     t        d      )Nhamr  r  s     r   custom_handlerzJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handler  s    U##r   z9Exception in default exception.*while handling.*in customr  rr  )r   rV   r*  rp   r   r[   r   r-   rY  rZ  rj  r%   r[  r   r   typer\  )r<   r  rq  r^  r  r  rW   s        @@r   test_default_exc_handler_brokenz2BaseEventLoopTests.test_default_exc_handler_broken  s5   		);,, 		) v

#t$	 ZZ45 	JII((8 ) 		$ "">2ZZ45 	-JII((&& (C D )  MM)X.MM$x	2;?@+-	- 	-	 		- 	-s   1%E	A/EE
Ec                     | j                  t        d      5  | j                  j                  d       d d d        | j	                  | j                  j                                y # 1 sw Y   3xY w)Nz'task factory must be a callable or Noner6   )r   r   rW   set_task_factoryr:   get_task_factoryr   s    r   test_set_task_factory_invalidz0BaseEventLoopTests.test_set_task_factory_invalid  s]    ##@B 	* II&&q)	*
 	$))4467	* 	*s   A%%A.c                    t        j                         | j                  _         G d dt        j
                        d }fd}| j                  | j                  j                                | j                  j                  |       | j                  | j                  j                         |       | j                  j                   |             }| j                  t        |             | j                  j                  |       | j                  j                  d        | j                  | j                  j                                | j                  j                   |             }| j                  t        |t        j
                               | j                  t        |             | j                  j                  |       y )Nc                       e Zd Zy)8BaseEventLoopTests.test_set_task_factory.<locals>.MyTaskNr2  r   r   r   MyTaskr    r4  r   r  c                     K   y wr   r   r   r   r   coroz6BaseEventLoopTests.test_set_task_factory.<locals>.coro  	        c                      ||       S Nrc  r   )rW   r  r  s     r   rz   z:BaseEventLoopTests.test_set_task_factory.<locals>.<lambda>  s    VDt%< r   )r   rX   rW   rd   r   Taskr:   r  r  r   create_taskrq   
isinstanceru   rn   )r<   r  factoryr,  r  s       @r   test_set_task_factoryz(BaseEventLoopTests.test_set_task_factory  s5   $(IIK		!	W\\ 		 =$))4467		""7+dii002G<yy$$TV,
401		$$T*		""4($))4467yy$$TV,
467D&12		$$T*r   c                     dj                  d      }t        dd|      \  }}}| j                  |j                         d       t        d|dd      \  }}}| j                  |j                         d       t        d|dd      \  }}}| j                  |j                         d	       t        dd|d
      \  }}}| j                  |j                         d       t        dddd|      \  }}}| j                  |j                         d	       y )N
)zimport asynciozloop = asyncio.new_event_loop()zprint(loop.get_debug())z-Er=  s   Falser3   )PYTHONASYNCIODEBUGPYTHONDEVMODErG   s   True)r  z-Xdev)r   r   r8   rstrip)r<   codestsstdoutstderrs        r   test_env_var_debugz%BaseEventLoopTests.test_env_var_debug  s   yy ' ( /tT4@VV(3.tTBD=?AVV 	(3.tTBE=?AVV 	'2.tT4BEGVV(3 /tT5/3T;VV'2r   c                 6    G d dt         j                        d } G fddt        j                        } |       | j	                          |       }t        j
                  |      }| j                  |       d|_        |j                          y )Nc                       e Zd Zy)3BaseEventLoopTests.test_create_task.<locals>.MyTaskNr2  r   r   r   r  r    r4  r   r  c                     K   y wr   r   r   r   r   testz1BaseEventLoopTests.test_create_task.<locals>.test  r  r  c                       e Zd Z fdZy)6BaseEventLoopTests.test_create_task.<locals>.EventLoopc                      |      S r  r   )r<   r  r  rW   s     r   r  zBBaseEventLoopTests.test_create_task.<locals>.EventLoop.create_task  s    d..r   N)rM   rN   rO   r  )r  rW   s   r   	EventLoopr    s    /r   r  rc  F)	r   r  r   rV   r[   re  r   _log_destroy_pendingrp   )r<   r  r  r  r,  r  rW   s        @@r   test_create_taskz#BaseEventLoopTests.test_create_task  s}    	W\\ 			/11 	/ {D!v$$T5dF+ %*!

r   c                 j   d }t        j                         }|j                          t        j                  d      5 }| j                  t              5  t        j                   |       |       d d d        | j                  t        |      d       d d d        y # 1 sw Y   -xY w# 1 sw Y   y xY w)Nc                     K   y wr   r   r   r   r   r  zCBaseEventLoopTests.test_create_task_error_closes_coro.<locals>.test,  r  r  T)recordrc  r   )
r   new_event_looprp   warningscatch_warningsr_   rs   re  r8   r  )r<   r  rW   ws       r   "test_create_task_error_closes_coroz5BaseEventLoopTests.test_create_task_error_closes_coro+  s    	%%'

$$D1 	(Q""<0 9%%df489SVQ'	( 	(9 9	( 	(s#   B)B1#B)B&	"B))B2c                 2   d }t        j                         }|j                   |       d      }	 | j                  |j	                         d       |j                  |       |j                          y # |j                  |       |j                          w xY w)Nc                     K   y wr   r   r   r   r   r  zLBaseEventLoopTests.test_create_named_task_with_default_factory.<locals>.test7  r  r  	test_taskr)   )r   r  r  r8   get_nameru   rp   )r<   r  rW   r,  s       r   +test_create_named_task_with_default_factoryz>BaseEventLoopTests.test_create_named_task_with_default_factory6  s{    	 %%'[9	T]]_k:##D)JJL ##D)JJLs    A3 3#Bc                 Z   d }d }t        j                         }|j                  |       |j                   |       d      }	 | j	                  |j                         d       |j                  |       |j                          y # |j                  |       |j                          w xY w)Nc                 0    t        j                  ||       S r  )r   r  )rW   r  s     r   task_factoryzSBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.task_factoryC  s    <<400r   c                     K   y wr   r   r   r   r   r  zKBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.testF  r  r  r  r  )r   r  r  r  r8   r  ru   rp   )r<   r  r  rW   r,  s        r   *test_create_named_task_with_custom_factoryz=BaseEventLoopTests.test_create_named_task_with_custom_factoryB  s    	1	 %%'l+[9	T]]_k:##D)JJL ##D)JJLs    B #B*c                    d }t        j                         | j                  _        t        j                         | j                  _        	 | j                  j                   |              | j                  j                          t        j                          | j                  | j                  j                  j                         y # t        $ r Y iw xY w)Nc                     K   t         wr   KeyboardInterruptr   r   r   raise_keyboard_interruptzXBaseEventLoopTests.test_run_forever_keyboard_interrupt.<locals>.raise_keyboard_interruptV       ##   	)r   rX   rW   rd   call_exception_handlerru   r  rp   r   rf  rn   r   )r<   r  s     r   #test_run_forever_keyboard_interruptz6BaseEventLoopTests.test_run_forever_keyboard_interruptR  s    	$ %)IIK		!+/99;		(	II(()A)CD 			99@@A ! 		s    C	 		CCc                     d }t        j                          j                  _         j	                  t
              5   j                  j                   |              d d d         fdd_         j                  j                   j                  j                          j                  j                           j                  j                         y # 1 sw Y   |xY w)Nc                     K   t         wr   r  r   r   r   r  zZBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.raise_keyboard_interrupth  r  r  c                  H    j                   j                          d _        y r   )rW   r   r   )funcr<   s   r   r  zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcp  s    IINNDKr   F)r   rX   rW   rd   r_   r  ru   r   r   rt   rq   )r<   r  r  s   ` @r   %test_run_until_complete_baseexceptionz8BaseEventLoopTests.test_run_until_complete_baseexceptione  s    	$ %)IIK		!01 	EII(()A)CD	E	 		DII//6		$	E 	Es   !CC#c                     t               dd  fd} fd fd| j                  _        f j                  j                  j                  _        t        dd      D ]z  } j                  d|z        5   j                  j                   j                  j                          j                  j                           j                  d       d d d        | y # 1 sw Y   xY w)Nr   c                 F    | v rj                   j                        y y r   rW   r   )
event_listdo_eventdoerevent_sentinelr<   s    r   proc_eventszZBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.proc_events  s$    +yy**84 ,r   c                  F     dz   j                   j                         y Nr6   r  )	callcountclear_selectorr<   s   r   r  zWBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.do_event  s    NIII/r   c                  p     j                          dj                  j                  j                  _        y rS   )r   rW   rY   rZ   r'   )r  r<   s   r   r  z]BaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.clear_selector  s$    KKM68DII&&3r   r6      z	Loop %d/2)objectrW   rd   rY   rZ   r'   r  subTestr   r   rt   r8   )r<   r  ir  r  r  r  r  s   `  @@@@@r   2test_single_selecter_event_callback_after_stoppingzEBaseEventLoopTests.test_single_selecter_event_callback_after_stoppingx  s      		5
	0
	9 %0		!3A2C		""/q! 	/AkAo. /		##DIINN3		%%'  A./ /	// /s   AC++C4	c                     dfd}t        j                         | j                  _        | j                  j	                  |       t        j                  | j                         | j                  d       y )Nr   c                       dz   y r  r   )counts   r   callbackz2BaseEventLoopTests.test_run_once.<locals>.callback  s    QJEr   r6   )r   rX   rW   rd   r   r%   run_oncer8   )r<   r  r  s     @r   test_run_oncez BaseEventLoopTests.test_run_once  sW    
 	 %)IIK		!		H%DII&"r   c                    t        j                         | j                  _        | j                  j	                          | j                  j                          | j                  j                  j                  j                  d       y Nr   )	r   rX   rW   rd   r   rt   rY   rZ   assert_called_once_withr   s    r   test_run_forever_pre_stoppedz/BaseEventLoopTests.test_run_forever_pre_stopped  sP    $(IIK		!						""::1=r   c                    K   ddddfd} |       }|j                         fdt        j                                 S w)NF)startedstopped	finalizedc                 R   K   dd<   	 dD ]  } |  	 	 dd<   y # dd<   w xY ww)NTr  )ZEROONETWOTHREEFOURr  r   )itemstatuss    r   agenz;BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.agen  s@      $F9+C DJ '+{#d{#s   ' '$'c                     K   	 j                          d {   } | dk(  rdd<   y t        j                                 y 7 *# t        $ r Y y w xY ww)Nr  Tr  )	__anext__StopAsyncIterationr   r  )r  aiiter_oner  s    r   r  z?BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.iter_one  sV     \\^+ w$(y!
+ ,% s7   AA AA &AA 	AAAA)	__aiter__r   r  )r<   r  agr
  r  r  s      @@@r   leave_unfinalized_asyncgenz-BaseEventLoopTests.leave_unfinalized_asyncgen  sN      #"$&	+ V\\^	, 	HJ's   AAc                    t        j                         | j                  _        t        j                         | j                  _        t        j                         5  | j                  j                  | j                               }|d   s%t        j                  | j                         |d   s%| j                  |d          | j                  |d          | j                  |d          t        j                          t        j                  | j                         | j                  |d          d d d        y # 1 sw Y   y xY w)Nr  r  r  )r   rX   rW   rd   re   r   
disable_gcru   r  r%   r   rq   rn   rf  r<   r  s     r    test_asyncgen_finalization_by_gcz3BaseEventLoopTests.test_asyncgen_finalization_by_gc  s    $(IIK		!#'99;		 ! 		1YY11$2Q2Q2STFY'&&tyy1 Y'OOF9-.OOF9-.VK01 ""499-OOF;/0		1 		1 		1s   AD;/BD;;Ec                 "   t        j                         | j                  _        t        j                         | j                  _        | j                  j                  d       t        j                         5  | j                  j                  | j                               }|d   s%t        j                  | j                         |d   s%| j                  |d          | j                  |d          | j                  |d          | j                  j                  | j                  j                  d t        j                               t        j                  | j                         | j                  |d          d d d        y # 1 sw Y   y xY w)NTr  r  r  )r   rX   rW   rd   re   r   r   r  ru   r  r%   r   rq   rn   run_in_executorrf  r  s     r   0test_asyncgen_finalization_by_gc_in_other_threadzCBaseEventLoopTests.test_asyncgen_finalization_by_gc_in_other_thread  s!    %)IIK		!#'99;		 		D!! 
	1YY11$2Q2Q2STFY'&&tyy1 Y'OOF9-.OOF9-.VK01II((		))$0B0BCE""499-OOF;/0
	1 
	1 
	1s   6AF
B2FF)1rM   rN   rO   rU   rl   rv   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r$  r'  r.  r;  rH  rK  r_  rg  rk  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__r]   s   @r   rQ   rQ      s    '2I++=7C +#
	+
,($/&-8^:$0;&JOX21/&=:@(B6B&4".H?*.-`8+63<,(
 B&%&/<# > D11r   rQ   c                   6    e Zd ZdZddZd Zd Zd Zd Zd Z	y)	MyProtoNc                 t    d| _         d| _        |r(t        j                         j	                         | _        y y NINITIALr   )statenbytesr   get_running_looprr   done)r<   rr   s     r   __init__zMyProto.__init__  s1    
002@@BDI r   c                 V    | j                   |vrt        d| j                   d|      y Nzstate: z, expected: r  AssertionErrorr<   expecteds     r   _assert_statezMyProto._assert_state  s/    ::X% 74::.XL!QRR &r   c                 d    || _         | j                  d       d| _        |j                  d       y )Nr  	CONNECTEDs%   GET / HTTP/1.0
Host: example.com

)	transportr(  r  writer<   r+  s     r   connection_madezMyProto.connection_made  s+    "9% 
FGr   c                 b    | j                  d       | xj                  t        |      z  c_        y )Nr*  r(  r  r  r<   datas     r   data_receivedzMyProto.data_received  s"    ;'s4y r   c                 4    | j                  d       d| _        y )Nr*  EOF)r(  r  r   s    r   eof_receivedzMyProto.eof_received	  s    ;'
r   c                     | j                  dd       d| _        | j                  r| j                  j                  d        y y )Nr*  r5  CLOSEDr(  r  r   r   r<   r   s     r   connection_lostzMyProto.connection_lost  s7    ;.
99II  & r   r   )
rM   rN   rO   r   r!  r(  r.  r3  r6  r;  r   r   r   r  r    s(    DCSH!'r   r  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| _        |r|j                         | _        y y r  )r  r  rr   r   )r<   rr   rW   s      r   r!  zMyDatagramProto.__init__  s(    
**,DI r   c                 X    | j                   |k7  rt        d| j                   d|      y r#  r$  r&  s     r   r(  zMyDatagramProto._assert_state  s/    ::! 74::.XL!QRR "r   c                 B    || _         | j                  d       d| _        y )Nr  INITIALIZED)r+  r(  r  r-  s     r   r.  zMyDatagramProto.connection_made!  s    "9%"
r   c                 b    | j                  d       | xj                  t        |      z  c_        y NrA  r0  )r<   r2  addrs      r   datagram_receivedz!MyDatagramProto.datagram_received&  s"    =)s4y r   c                 &    | j                  d       y rC  )r(  r:  s     r   error_receivedzMyDatagramProto.error_received*  s    =)r   c                     | j                  d       d| _        | j                  r| j                  j                  d        y y )NrA  r8  r9  r:  s     r   r;  zMyDatagramProto.connection_lost-  s5    =)
99II  & r   )FN)
rM   rN   rO   r   r!  r(  r.  rE  rG  r;  r   r   r   r=  r=    s&    D-S#
!*'r   r=  c                   z    e Zd Z fdZ ej
                  d      d        Zed        Zed        Z	d Z
d Zd Zd	 Z ej                   eed
      d      d        Z ej                  ej(                  d      d        Zd Zd Zd Zd Zd Zed        Zd Z ej                  ej(                  d       ej:                  ej>                  jA                  d      d      ed                      Z!ed        Z"ed        Z#ed        Z$d Z%ed        Z&d Z'd Z(d  Z)d! Z*d" Z+d# Z,d$ Z-d% Z.ed&        Z/ed'        Z0ed(        Z1ed)        Z2d* Z3d+ Z4d, Z5ed-        Z6 ej                  ej(                  d.      d/        Z7ed0        Z8d1 Z9ed2        Z:d3 Z; ej                   eed4      d5      d6        Z<ejz                  d7        Z>d8 Z? ej:                  ej>                  d9k(  d:      d;        Z@ed<        ZAed=        ZBd> ZC ej
                  d?      d@        ZDdA ZE ej
                  d?      dB        ZF xZGS )CBaseEventLoopWithSelectorTestsc                     t         |           t        j                         | _        | j                  | j                         y r   )rT   rU   r   SelectorEventLooprW   r[   r\   s    r   rU   z$BaseEventLoopWithSelectorTests.setUp6  s.    --/	DII&r   zsocket.getnameinfoc                     d |_         | j                  j                  | j                  j                  d            }| j	                  |d       y )Nc                       y)N*   r   )r   s    r   rz   zABaseEventLoopWithSelectorTests.test_getnameinfo.<locals>.<lambda>=  r{   r   )abcr?  rO  )side_effectrW   ru   getnameinfor8   )r<   m_gairs      r   test_getnameinfoz/BaseEventLoopWithSelectorTests.test_getnameinfo;  s=    ,II(()>)>|)LMBr   c                    	
  G d dt         j                        }d 		 fd}d
ddg
fd}||_        | j                  _         j                  j                  |d	d
      } j                  t              5 } j                  j                  |       d d d         j                  t        j                        d       d
 j                  j                  |d	d
d      } j                  t              5 } j                  j                  |       d d d         j                  |j                  t               |j                  j                  D ]  } j                  |t                y # 1 sw Y   xY w# 1 sw Y   gxY w)Nc                       e Zd Zy)VBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.MyProtoNr2  r   r   r   r  rX  D  r4  r   r  c                     K   ddgS wNr  r6      r3   )z107.6.106.82P   r   r   kws     r   getaddrinfozZBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfoG  s     779 9   c                  F    j                   j                   | i |      S r   rW   r  r   kwdsr`  r<   s     r   getaddrinfo_taskz_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_taskK  "    99((d)Cd)CDDr   r   err1err2c                  *    dz  t                 r  )OSError)r   r_  errorsidxs     r   _socketzVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socketQ  s    1HC&+&&r   example.comr]  zMultiple exceptions: err1, err2T
all_errors)r   Protocolr    rW   r`  create_connectionr_   rk  ru   r8   strrr  ExceptionGroupr   
exceptions)r<   r(   r  rf  rn  r  cmerl  r`  rm  s   `       @@@r   &test_create_connection_multiple_errorszEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errorsA  sO   	g&& 		9	E &!	'
 " 0		yy**7M2Fw' 	/2II((.	/ 	R\\*,MNyy**7M2RV*W~. 	/"II((.	/ 	bllN;(( 	.A!!!W-	.	/ 	/	/ 	/s   =E2<E>2E;>Fc                 D    t        j                         }||j                  _         fd}| j                  _        t         j                  j                   j                  dt        j                        5   j                  j                  t        dd      } j                  t        j                        5   j                  j                  |       d d d         j                  |j                  j                          d d d        y # 1 sw Y   7xY w# 1 sw Y   y xY w)Nc                      j                   j                         }t        j                  t        j                  dddf}|j                  |g       |S )Nr   r3   )	127.0.0.1r]  )rW   rr   r    r   r   r   )r   r_  r   rD  r<   s       r   r`  zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfoo  sE    ))))+CNNF$6$62%'DNND6"Jr   sock_connect)rQ  r|  r]  )r   rX   r    r'   rW   r`  r-   r  r   TimeoutErrorrs  r  r_   ru   rq   rp   r   )r<   r(   sockr`  r  s   `    r   test_create_connection_timeoutz=BaseEventLoopWithSelectorTests.test_create_connection_timeouti  s     yy{'+$	 !,		ZZtyy.+2+?+?  A 	/99..wRHD""7#7#78 3		,,T23OODJJ--.	/ 	/3 3	/ 	/s%   7AD8D
-D
D	DDc                     | j                   j                  t        ddt                     }| j	                  t
        | j                   j                  |       y )Nro  r]  r  )rW   rs  r  r  r_   r+  ru   r<   r  s     r   %test_create_connection_host_port_sockzDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sock~  sB    yy**]BVX + 7*dii&B&BDIr   c                 d   t        j                   t         j                  t         j                        }|5  | j                  j	                  t
        |      }| 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Nr  zA Stream Socket was expected)	r    r   r   rW   rs  r  r   r+  ru   r<   r  r  s      r   !test_create_connection_wrong_sockz@BaseEventLoopWithSelectorTests.test_create_connection_wrong_sock  s    }}V^^V->->? 	399..wT.BD''
(FH 3		,,T23	3 	33 3	3 	3#   8B&-B	B&B#	B&&B/c                 d   t        j                   t         j                  t         j                        }|5  | j                  j	                  t
        |      }| 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r  )	r    r   r   rW   create_serverr  r   r+  ru   r  s      r   test_create_server_wrong_sockz<BaseEventLoopWithSelectorTests.test_create_server_wrong_sock  s    }}V^^V->->? 	399**7*>D''
(FH 3		,,T23	3 	33 3	3 	3r  c                     | j                   j                  t        ddd      }| j                  t        d      5  | j                   j                  |       d d d        y # 1 sw Y   y xY wNro  r]  r6   )ssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)rW   r  r  r   r+  ru   r  s     r   /test_create_server_ssl_timeout_for_plain_socketzNBaseEventLoopWithSelectorTests.test_create_server_ssl_timeout_for_plain_socket  sc    yy&&]Ba ' A##CE 	/ II((.	/ 	/ 	/   AA(SOCK_NONBLOCKz$no socket.SOCK_NONBLOCK (linux only)c                    t        j                   t         j                  t         j                  t         j                  z        }|5  | j                  j                  d |      }| j                  j                  |      }|j                          | j                  j                  |j                                d d d        y # 1 sw Y   y xY w)Nc                       y r   r   r   r   r   rz   zRBaseEventLoopWithSelectorTests.test_create_server_stream_bittype.<locals>.<lambda>  r{   r   r  )	r    r   r   r  rW   r  ru   rp   wait_closed)r<   r  r  srvs       r   !test_create_server_stream_bittypez@BaseEventLoopWithSelectorTests.test_create_server_stream_bittype  s     }}NNF..1E1EEG 	<99**<d*CD))..t4CIIKII(():;		< 	< 	<s   A3CCzno IPv6 supportc                       fd}	  j                   j                   |              y # t        $ rJ}t        t        d      r/|j                  t        j
                  k(  r j                  d       n Y d }~y d }~ww xY w)Nc                  N  K   t        j                  d dd       d {   } 	 j                  t        | j                        d       | j                          | j                          d {    y 7 S7 # | j                          | j                          d {  7   w xY ww)Nc                       y r   r   r   r   r   rz   zVBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main.<locals>.<lambda>  r{   r   ::1r   )r   start_serverassertGreaterr  socketsrp   r  )r  r<   s    r   mainzDBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main  s}     ,,\5!DDC(""3s{{#3Q7		oo''' E
 ( 		oo'''sD   B%A3B%%A7 
#B%-A5.B%5B%7$B"BB""B%EADDRNOTAVAILzfailed to bind to ::1)rW   ru   rk  r!   errnor  skipTest)r<   r  exs   `  r   test_create_server_ipv6z6BaseEventLoopWithSelectorTests.test_create_server_ipv6  sb    	(	II((0 	/HH 3 3356 7	s    ) 	A<A A77A<c                 F   t        j                   t         j                        }|5  | j                  j                  t        |      }| 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)Nr  zA datagram socket was expected)r    r   rW   create_datagram_endpointr  r   r+  ru   r  s      r   (test_create_datagram_endpoint_wrong_sockzGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_wrong_sock  s    }}V^^, 	39955gD5ID''
(HJ 3		,,T23	3 	33 3	3 	3s#   8BB:BB	BB c                     | j                   j                  t              }| j                  t        | j                   j
                  |       y r   rW   rs  r  r_   r+  ru   r  s     r   (test_create_connection_no_host_port_sockzGBaseEventLoopWithSelectorTests.test_create_connection_no_host_port_sock  s2    yy**73*dii&B&BDIr   c                      d  fd}| j                   _         j                   j                  t        dd      } j	                  t
         j                   j                  |       y )Nc                     K   g S wr   r   r^  s     r   r`  zYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo  s     Is   c                  F    j                   j                   | i |      S r   rc  rd  s     r   rf  z^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_task  rg  r   ro  r]  )rW   r`  rs  r  r_   rk  ru   r<   rf  r  r`  s   `  @r   %test_create_connection_no_getaddrinfozDBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo  sS    		E !1		yy**7M2FTYY114	9r   c                      d  fd}| j                   _        t        j                          j                   _        t
         j                   j                  _         j                   j                  t        dd      } j                  t
         j                   j                  |        j                   j                  t        ddd      } j                  t              5 } j                   j                  |       d d d         j                  j                  t                j                  t        |j                  j                         d        j                  |j                  j                   d   t
               y # 1 sw Y   xY w)	Nc                     K   dgS wrZ  r   r^  s     r   r`  zVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo  s     788s   c                  F    j                   j                   | i |      S r   rc  rd  s     r   rf  z[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_task  rg  r   ro  r]  Trp  r6   r   )rW   r`  r   rX   r}  rk  rQ  rs  r  r_   ru   ru  r   rr  r8   r  rv  )r<   rf  r  rw  r`  s   `   @r   "test_create_connection_connect_errzABaseEventLoopWithSelectorTests.test_create_connection_connect_err  s"   	9	E !1		!%		-4		*yy**7M2FTYY114	9 yy**7M2RV*W~. 	/"II((.	/ 	bllN;R\\445q9bll55a8'B	/ 	/s   #FFc                 <    d  fd}| j                   _        t        j                          j                   _        t
         j                   j                  _         j                   j                  t        ddt        j                        } j                  t
              5   j                   j                  |       d d d         j                   j                  t        ddt        j                  d      } j                  t              5 } j                   j                  |       d d d         j                  j                  t               |j                  j                   D ]  } j                  |t
                y # 1 sw Y   xY w# 1 sw Y   gxY w)Nc                     K   ddgS wN)r  r6   r\  r3   )0.0.0.1r]  )r  r6   r\  r3   )z0.0.0.2r]  r   r^  s     r   r`  zSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo       224 4ra  c                  F    j                   j                   | i |      S r   rc  rd  s     r   rf  zXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_task  rg  r   ro  r]  familyT)r  rq  )rW   r`  r   rX   r}  rk  rQ  rs  r  r    r   r_   ru   ru  r   rr  rv  )r<   rf  r  rw  rx  r`  s   `    @r   test_create_connection_multiplez>BaseEventLoopWithSelectorTests.test_create_connection_multiple  s<   	4	E !1		!%		-4		*yy**]Bv~~ + ?w' 	/II((.	/ yy**]Bv~~$ + P~. 	/"II((.	/ 	bllN;(( 	.A!!!W-	.	/ 	/
	/ 	/s   %FFFFc                 `    d }||j                   j                  _        d  fd}| j                  _        t        j                          j                  _        t        d       j                  j                  _	         j                  j                  t        ddt         j                  d      } j                  t              5 } j                  j                  |       d d d         j                  t!        j"                        j%                  d	              j                  |j                   j                  j&                  j(                          j                  j                  t        ddt         j                  dd
      } j                  t*              5 } j                  j                  |       d d d         j-                  |j"                  t*               |j"                  j.                  D ]  } j-                  |t                y # 1 sw Y   4xY w# 1 sw Y   hxY w)Nc                 <    | d   dk(  rt        d      }d|_        |y )Nr   r  Err)rk  strerror)rD  errs     r   bindz^BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.bind  s(    Aw)#en$	 $r   c                     K   ddgS wr  r   r^  s     r   r`  zeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo  r  ra  c                  F    j                   j                   | i |      S r   rc  rd  s     r   rf  zjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_task  rg  r   Err2ro  r]  Ni  r  
local_addrzMultiple exceptions: T)r  r  rq  )r    r'   r  rW   r`  r   rX   r}  rk  rQ  rs  r  r   r_   ru   rq   rt  rr  
startswithrp   r   ru  r   rv  )r<   r(   r  rf  r  rw  rx  r`  s   `      @r   1test_create_connection_multiple_errors_local_addrzPBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr  s   	 -1$$)	4	E !1		!%		-4V_		*yy**]Bv~~# + % w' 	/2II((.	/ 	BLL)445LMN44::AAByy**]Bv~~# + 6 ~. 	/"II((.	/ 	bllN;(( 	.A!!!W-	.	/ 	/	/ 	/s   	H!H$H!$H-c                    |s|` t        j                  |_        |j                  j                  }t	        j
                         | j                  _        t	        j
                         | j                  _        | j                  j                  t        j                  dd      }| j                  j                  |      \  }}	 |j                  j                  d       |j                  j                  \  }}| j!                  |d   |j"                         | j!                  |d   |j$                         |j'                          t)        j*                  | j                         t,        j.                  r-t        j0                  |_        | j                  j                  t        j                  dd      }| j                  j                  |      \  }}	 |j                  j                  d   \  }	|	d d \  }
}| j5                  |
d	       | j!                  |d       |j                  j                  \  }}| j!                  |d   |j0                         | j!                  |d   |j$                         |j'                          t)        j*                  | j                         y y # |j'                          t)        j*                  | j                         w xY w# |j'                          t)        j*                  | j                         w xY w)
Nr5   r]  r5   r]  r  r  r  r   r  z	::(0\.)*1)r   r    r`  r'   r   rX   rW   _add_reader_add_writerrs  r   rr  ru   connectrZ  r   r8   r   r   rp   r%   r   r
   r;   r   r  assertRegex)r<   r(   allow_inet_ptonr  r  r  p_r   addresshostports               r   _test_create_connection_ip_addrz>BaseEventLoopWithSelectorTests._test_create_connection_ip_addr+  s7   "%11++ $				 $				yy**7+;+;YKyy++D11	.LL++O< 11IAvVH-x/?/?@VF^X-A-ABGGI""499-%% //DK99..w/?/?KD99//5DAq2 !LL2215	$Ra[
d  |4  r*$OO55	6  !183D3DE  1E1EF	&&tyy1# & GGI""499-$ 	&&tyy1s    A2J  BK  1K1LaixzDbpo-25545: IPv6 scope id and getaddrinfo() behave differently on AIXc                 N   t         j                  |_        |j                   j                  }t         j                  |_        t        j                         | j                  _        t        j                         | j                  _	        | j                  j                  t        j                  dd      }| j                  j                  |      \  }}	 |j                  j                  d       |j                   j                   \  }}| j#                  |d   |j                         | j#                  |d   |j$                         |j'                          t)        j*                  | j                         y # |j'                          t)        j*                  | j                         w xY w)Nz	fe80::1%1r]  )zfe80::1r]  r   r6   r  r  )r    r`  r'   r   r  r   rX   rW   r  r  rs  r   rr  ru   r  rZ  r   r8   r   rp   r%   r   )r<   r(   r  r  r  r  r  r   s           r   !test_create_connection_ipv6_scopez@BaseEventLoopWithSelectorTests.test_create_connection_ipv6_scopeT  s    
  &11++oo $				 $				yy**7+;+;["Myy++D11	.LL++,AB 11IAvVH-x/@/@AVF^X-A-ABGGI""499- GGI""499-s   A2E3 31F$c                 (    | j                  |d       y r   r  rK   s     r   test_create_connection_ip_addrz=BaseEventLoopWithSelectorTests.test_create_connection_ip_addrk  s    ,,Xt<r   c                 (    | j                  |d       y ry   r  rK   s     r   #test_create_connection_no_inet_ptonzBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptono  s    ,,Xu=r   c                 *   t         j                  |_        |j                   j                  }t        j                         | j
                  _        t        j                         | j
                  _        dD ]  \  }}| j
                  j                  t        j                  d|      }| j
                  j                  |      \  }}	 |j                  j                  d|f       |j                   j                  \  }}	| j                  |	d   |j                          | j                  |	d   |j"                         |j%                          t'        j(                  | j
                          dD ]f  }| j
                  j                  t        j                  d|      }| j+                  t,              5  | j
                  j                  |       d d d        h y # |j%                          t'        j(                  | j
                         w xY w# 1 sw Y   xY w)N))httpr]  )s   httpr]  r|  r  r  )nonsenses   nonsense)r    r`  r'   r   rX   rW   r  r  rs  r   rr  ru   r  rZ  r   r8   r   r   rp   r%   r   r_   rk  )
r<   r(   r  servicer  r  r  r  r  r   s
             r   #test_create_connection_service_namezBBaseEventLoopWithSelectorTests.test_create_connection_service_names  s   %11++ $				 $				8 	2MGT99..w/?/?/:GED 99//5DAq2//d0CD$OO55	6  !183C3CD  1E1EF	&&tyy1	2 / 	3G99..w/?/?/:GED ""7+ 3		,,T23 3		3 	&&tyy13 3s   A4G.H	1H	H	c                      d  fd}| j                   _         j                   j                  t        ddt        j
                  d      } j                  t         j                   j                  |       y )Nc                     K   | dk(  rddgS g S w)Nro  r[  r   )r  r   r_  s      r   r`  zXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo  s%     }$;;= = 	s   c                  F    j                   j                   | i |      S r   rc  rd  s     r   rf  z]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_task  rg  r   ro  r]  r  r  )	rW   r`  rs  r  r    r   r_   rk  ru   r  s   `  @r   $test_create_connection_no_local_addrzCBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr  sd    		E 0		yy**]Bv~~# + % 	TYY114	9r   c                      d fd}||_         |j                         } j                  j                  |      } j                  j	                  |       y )N)z00:01:02:03:04:05r6   c                 @    j                  | |f       dddddffgS )Ni  r6   r3   )r8   )r  r  r   r_  rD  r<   s       r   r`  zTBaseEventLoopWithSelectorTests.test_create_connection_bluetooth.<locals>.getaddrinfo  s/    dD\40!S"tQi011r   )r`  r    rW   r}  ru   )r<   r(   r`  r  r  rD  s   `    @r    test_create_connection_bluetoothz?BaseEventLoopWithSelectorTests.test_create_connection_bluetooth  sM     (	2  + yy%%dD1		$$T*r   c           
      V   	 t        j                          j                  _         fd}| j                  j                  _        t        j                          j                  _         j                  j                          j                  j
                  _         j                  j
                  j                  j                  d        t        j                          j                  _	         G d d      		fd}| j                  j                  _        t         j                  }t               }t               } j                  j                  j                           j                  j                  t        ddd||      } j                  j                  |      \  }}|j!                           j                  j                  j#                  ||||d	d||
        j                  j                  j                           j                  j                  t        dddd||      } j                  j                  |      \  }}|j!                           j                  j                  j#                  ||||d	d||
        j                  j                  j                           j                  j                  t        dddd||      } j                  j                  |      \  }}|j!                           j                  j                  j#                  ||||d	d||
       y )Nc                      j                   j                         }|j                  t        j                  t        j
                  t        j                  ddfg       |S )Nr3   r  )rW   rr   r   r    r   r   SOL_TCP)r   re  r.   r<   s      r   mock_getaddrinfozkBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_getaddrinfo  sL    		'')ALL6>>6+=+=!>>2@ A BHr   c                       e Zd ZdZd Zd Zy)qBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMockNc                 *    t        j                         S r   )r   rX   )r<   keys     r   get_extra_infozBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.get_extra_info  s    yy{"r   c                 8    | j                   j                          y r   )_sockrp   r   s    r   rp   zwBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.close  s    

  "r   )rM   rN   rO   r  r  rp   r   r   r   _SelectorTransportMockr    s    E##r   r  c                 F    |j                  d                }| |_        |S r   )r   r  )r  protocol
sslcontextwaiterre  r+  r  s         r   mock_make_ssl_transportzrBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_make_ssl_transport  s&    d#.0I"IOr   
python.orgr]  T)sslr  ssl_shutdown_timeoutF)server_sideserver_hostnamer  r  zperl.com)r  r  r  r  r3   )r   rX   rW   r`  rQ  r}  rr   r'   r   rb   ANYr  rw  rs  r  ru   rp   rZ  )
r<   r  r  r  handshake_timeoutshutdown_timeoutr  r+  r  r  s
   `        @r   2test_create_connection_ssl_server_hostname_defaultzQBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default  s    $					 -=		)!%		.2ii.E.E.G		+		++66t<(,				%	# 	#	 5L		%%1hh"H!8		%%002yy**rt&7%5 + 7 yy33D9	1		%%88c3("3!1 	9 	3 			%%002yy**rt *&7%5	 + 7
 yy33D9	1		%%88c3&"3!1 	9 	3 			%%002yy**rt "&7%5	 + 7
 yy33D9	1		%%88S#s! "&7%5 	9 	7r   c                 <   | j                   j                  t        ddd      }| j                  t        | j                   j
                  |       | j                   j                  t        ddd      }| j                  t        | j                   j
                  |       y )Nr  r]  r3   )r  r  r  s     r   4test_create_connection_no_ssl_server_hostname_errorszSBaseEventLoopWithSelectorTests.test_create_connection_no_ssl_server_hostname_errors  s    yy**7L";= + ?*dii&B&BDIyy**7L";G + I*dii&B&BDIr   c                 8   | j                   j                  t        ddd      }| j                  t        | j                   j
                  |       | j                   j                  t        d dd      }| j                  t        | j                   j
                  |       t        j                         }| j                   j                  t        d d d|      }| j                  |j                         | j                  t        | j                   j
                  |       y )Nr3   r]  T)r  )r  r  )	rW   rs  r  r_   r+  ru   r    r*  rp   )r<   r  r  s      r   1test_create_connection_ssl_server_hostname_errorszPBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_errors
  s    yy**7B*E*dii&B&BDIyy**7D"$*G*dii&B&BDI}}yy**7D$/3$ + @

#*dii&B&BDIr   c                     | j                   j                  t        ddd      }| j                  t        d      5  | j                   j                  |       d d d        y # 1 sw Y   y xY wr  )rW   rs  r  r   r+  ru   r  s     r   3test_create_connection_ssl_timeout_for_plain_socketzRBaseEventLoopWithSelectorTests.test_create_connection_ssl_timeout_for_plain_socket  sc    yy**]Ba + A##CE 	/ II((.	/ 	/ 	/r  c                     t               fd fd}| j                  _         j                  j                  t        dd      } j                  t         j                  j                  |        j                         y )Nc                     K   | d   g S wr  r   )r   r_  r  s     r   r`  zQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo"  s     7DIs   c                  F    j                   j                   | i |      S r   rc  rd  s     r   rf  zVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_task'  rg  r   r3   r   )	r  rW   r`  r  r  r_   rk  ru   r:   )r<   rf  r   r`  r  s   `  @@r   test_create_server_empty_hostz<BaseEventLoopWithSelectorTests.test_create_server_empty_host  se    x	
	E !1		ii%%gr15'499#?#?E$r   c                     | j                   j                  t        ddt                     }| j	                  t
        | j                   j                  |       y )N0.0.0.0r   r  )rW   r  r  r  r_   r+  ru   r<   r   s     r   !test_create_server_host_port_sockz@BaseEventLoopWithSelectorTests.test_create_server_host_port_sock/  sB    ii%%Y & 2*dii&B&BCHr   c                     | j                   j                  t              }| j                  t        | j                   j
                  |       y r   )rW   r  r  r_   r+  ru   r  s     r   $test_create_server_no_host_port_sockzCBaseEventLoopWithSelectorTests.test_create_server_no_host_port_sock4  s2    ii%%g.*dii&B&BCHr   c                 Z   t        j                         x}| j                  _        | j                  j	                         |_        |j
                  j                  d        | j                  j                  t        dd      }| j                  t        | j                  j                  |       y )Nr  r   )r   rX   rW   r`  rr   r'   r   r  r  r_   rk  ru   )r<   r`  r.   s      r   !test_create_server_no_getaddrinfoz@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfo8  sv    .2iik9dii+#'99#:#:#<   ++D1II##G\1='499#?#?Cr   c                    t         j                  |_        |`t        j                         |j                   _        | j                  j                  t        ddd      }| j                  t        | j                  j                  |       y )Nr  r   T
reuse_port)r    r`  SO_REUSEPORTr   rX   r'   rW   r  r  r_   r+  ru   r<   r(   r.   s      r    test_create_server_nosoreuseportz?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseport@  sh    %11!'+yy{$II##Yd $ 4 	*dii&B&BAFr   c                    t         j                  |_        t        j                         |j                   _        d|_        | j                  j                  t        ddd      }| j                  t        | j                  j                  |       y )Nr   r  r   Tr  )r    r`  r   rX   r'   r  rW   r  r  r_   r+  ru   r  s      r   +test_create_server_soreuseport_only_definedzJBaseEventLoopWithSelectorTests.test_create_server_soreuseport_only_definedK  sj    %11'+yy{$ "II##Yd $ 4 	*dii&B&BAFr   c                     G d dt               }dg|j                  _        t        j                         x}|j
                  _        ||j                  _        | j                  j                  t        dd      }| j                  t         | j                  j                  |       | j                  |j                  j                         y )Nc                       e Zd ZdZy)HBaseEventLoopWithSelectorTests.test_create_server_cant_bind.<locals>.ErrrY  N)rM   rN   rO   r  r   r   r   r  r"  Y  s    Hr   r  )r  r6   r\  r3   )r|  it'  r  r   )rk  r`  r'   r   rX   r    r  rQ  rW   r  r  r_   ru   rq   rp   r   r<   r(   r  m_sockr   s        r   test_create_server_cant_bindz;BaseEventLoopWithSelectorTests.test_create_server_cant_bindV  s    	' 	 0-1)04		;-"%ii%%gy!<'499#?#?E++,r   c                     g |j                   _        | j                  j                  t        d      }| j                  t        | j                  j                  |       y )N)	localhostr   r  )r`  r'   rW   r  r=  r_   rk  ru   r<   r(   r  s      r   )test_create_datagram_endpoint_no_addrinfozHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfoe  sN    ,.)yy11(8 2 :TYY114	9r   c                 4   | j                   j                  t        d      }| j                  t        | j                   j
                  |       | j                   j                  t        d      }| j                  t        | j                   j
                  |       y )Nr'  r(  )r'  r6   r  r  )rW   r  r=  r_   r   ru   r  s     r   (test_create_datagram_endpoint_addr_errorzGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errorn  s~    yy11 2 5tyy33T	;yy11(> 2 @tyy33T	;r   c                 4   t        j                         | j                  _        t        | j                  j                  _        | j                  j                  t        j                  d      }| j                  t        | j                  j                  |       y )Nr|  r   )remote_addr)r   rX   rW   r}  rk  rQ  r  r   DatagramProtocolr_   ru   r  s     r   )test_create_datagram_endpoint_connect_errzHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_connect_errx  sk    !%		-4		*yy11$$2B 2 DTYY114	9r   c                    t        d| j                        t        j                         x| j                  _        }g |_        | j                  j                  fddd      }| j                  j                  |      \  }}| j                  |j                         |j                          | j                  j                  j                         | j                  dj                         y )NTrr   rW   c                       S r   r   )r  s   r   rz   z^BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcast.<locals>.<lambda>  s    H r   r.  )r/  allow_broadcastr8  )r=  rW   r   rX   r}  r'   r  ru   rn   r   rp   r   r8   r  )r<   r}  r  r+  r  r  s        @r   -test_create_datagram_endpoint_allow_broadcastzLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcast  s    "DIIF04		;		$&!yy11(  2 "
 yy33D9	1,,-		$$X]]38>>2r   c                    t         j                  |_        t        |j                   _        | j                  j                  t        j                  t         j                        }| j                  t        | j                  j                  |       | j                  j                  t        j                  d      }| j                  t        | j                  j                  |       y )Nr  r.  r(  )r    r`  rk  rQ  rW   r  r   r0  r   r_   ru   r)  s      r   (test_create_datagram_endpoint_socket_errzGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_socket_err  s    %11&-#yy11$$V^^ 2 =TYY114	9 yy11$$1A 2 CTYY114	9r   zIPv6 not supported or enabledc                     | j                   j                  t        j                  dd      }| j	                  t
        | j                   j                  |       y )Nr.  )r  r   )r/  r  rW   r  r   r0  r_   r+  ru   r  s     r   0test_create_datagram_endpoint_no_matching_familyzOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_matching_family  sK    yy11$$(Z 2 A 			44d	<r   c                    t         |j                  j                  j                  _        | j
                  j                  t        j                  t        j                        }| j                  t         | j
                  j                  |       | j                  |j                  j                  j                  j                         y )Nr  )rk  r    r'   setblockingrQ  rW   r  r   r0  r   r_   ru   rq   rp   r   r)  s      r   (test_create_datagram_endpoint_setblk_errzGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_setblk_err  s    ?F$$00<yy11$$V^^ 2 =TYY114	9OO((..55	7r   c                     | j                   j                  t        j                        }| j	                  t
        | j                   j                  |       y r   r:  r  s     r   -test_create_datagram_endpoint_noaddr_nofamilyzLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_noaddr_nofamily  s;    yy11$$&*dii&B&BDIr   c                     G d dt               }t        j                  |_        t        j                         x}|j                  _        ||j                  _        | j                  j                  t        dt        j                        }| j                  || j                  j                  |       | j                  |j                  j                          y )Nc                       e Zd Zy)SBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bind.<locals>.ErrNr2  r   r   r   r  rC    r4  r   r  r.  )r  r  )rk  r    r`  r   rX   r'   r  rQ  rW   r  r=  r   r_   ru   rq   rp   r   r#  s        r   'test_create_datagram_endpoint_cant_bindzFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bind  s    	' 	  &1104		;-"%ii00' 1 @ 	#tyy;;SA++,r   c                     t        j                   t         j                  t         j                        }|j                  d        j                  j                   fd|      } j                  j                  |      \  }}|j                           j                  j                  |j                          j                  d|j                         y )Nr.  c                  2    t        d j                        S NTr3  r=  rW   r   s   r   rz   zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>      O$TYYG r   r  r8  )r    r   r   r  rW   r  ru   rp   r   r8   r  )r<   r  r   r+  r  s   `    r   "test_create_datagram_endpoint_sockzABaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock  s    }}V^^V->->?		"#ii00G 1  #ii::3?	8		$$X]]38>>2r   AF_UNIXzNo UNIX Socketsc                      j                   j                   fdt        j                        } j                   j	                  |      \  }} j                  |j                  j                  t        j                         |j                           j                   j	                  |j                          j                  d|j                         y )Nc                  2    t        d j                        S rG  rH  r   s   r   rz   zXBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unix.<locals>.<lambda>  rI  r   r  r8  )rW   r  r    rK  ru   r8   r  r  rp   r   r  )r<   r   r+  r  s   `   r   'test_create_datagram_endpoint_sock_unixzFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unix  s    ii00G>> 1 # #ii::3?	8//@		$$X]]38>>2r   c                     t        j                         5 }t        j                  t        j                  t        j                        }|j                  |       |j                           j                  j                   fd|t        j                        } j                  j                  |      \  }}|j                           j                  j                  |j                         d d d        y # 1 sw Y   y xY w)N)r  c                  2    t        d j                        S rG  rH  r   s   r   rz   zaBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unix.<locals>.<lambda>  s    dK r   r  )r%   unix_socket_pathr    rK  r   r  rp   rW   r  ru   r   )r<   pathr  r  r+  r  s   `     r   0test_create_datagram_endpoint_existing_sock_unixzOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unix  s    ((* 
	8d==f6G6GHDIIdOJJL9955KV^^ 6 -D #'))">">t"DIxOOII((7
	8 
	8 
	8s   CC66C?c                     G d d      }| j                   j                  t        d |             }| j                  t        | j                   j
                  |       | j                   j                  t        d |             }| j                  t        | j                   j
                  |       | j                   j                  t        d |             }| j                  t        | j                   j
                  |       | j                   j                  t        d |             }| j                  t        | j                   j
                  |       | j                   j                  t        d |       	      }| j                  t        | j                   j
                  |       | j                   j                  t        d
 |             }| j                  t        | j                   j
                  |       | j                   j                  t        d
 |             }| j                  t        | j                   j
                  |       y )Nc                   $    e Zd Zej                  Zy)\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockopts.<locals>.FakeSockN)rM   rN   rO   r    r   r  r   r   r   FakeSockrV    s    $$Dr   rW  r.  )r  r  )r/  r  r6   )r  r  )protor  )flagsr  T)r  r  )r5  r  )rW   r  r=  r_   r+  ru   )r<   rW  r   s      r   +test_create_datagram_endpoint_sock_sockoptszJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockopts  s   	% 	% ii00(8xz 1 K*dii&B&BCHii00)9
 1 L*dii&B&BCHii00AHJ 1 8*dii&B&BCHii0018: 1 7*dii&B&BCHii0018: 1 7*dii&B&BCHii008: 1 ?*dii&B&BCHii00T
 1 D*dii&B&BCHr   vxworksz-SO_BROADCAST is enabled by default on VxWorksc                      j                   j                   fdd      } j                   j                  |      \  }}|j                  d      }t	        t
        d      }|r= j                  |j                  t
        j                  t
        j                                j                  |j                  t
        j                  t
        j                               |j                           j                   j                  |j                          j                  d|j                          j                   j                   fdd|d	      } j                   j                  |      \  }}|j                  d      } j                  |j                  t
        j                  t
        j                               |r= j!                  |j                  t
        j                  t
        j                                j!                  |j                  t
        j                  t
        j                               |j                           j                   j                  |j                          j                  d|j                         y )
Nc                  2    t        d j                        S rG  rH  r   s   r   rz   zWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>  rI  r   r.  r(  r    r  r8  c                  2    t        d j                        S rG  rH  r   s   r   rz   zWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>'  rI  r   T)r  r  r5  )rW   r  ru   r  r!   r    rn   
getsockoptr   r  SO_BROADCASTrp   r   r8   r  r   rq   )r<   r  r+  r  r  reuseport_supporteds   `     r   &test_create_datagram_endpoint_sockoptszEBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts  s    yy11G' 2 ) #ii::4@	8''1%fn=%%v':':<= 	OO!!6#6#68	9 			$$X]]38>>2yy11G'* 	 2 "
 #ii::4@	8''1OO!!6#6#68	9 OO%%v':':<= 	OO!!6#6#68	9 			$$X]]38>>2r   c                      |` t        j                         |j                  _         j
                  j                   fddd      } j                  t         j
                  j                  |       y )Nc                  0    t         j                        S r  rH  r   s   r   rz   z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>C      O3 r   r.  Tr  r  )
r  r   rX   r    r'   rW   r  r_   r+  ru   r)  s   `  r   +test_create_datagram_endpoint_nosoreuseportzJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport=  s[    !'+yy{$yy113' 2 
 	*dii&B&BDIr   c                      fd}||_         t        j                         x|j                  j                  _        }t        j                          j                  _        t        t        d      } j                  j                   fdd|      } j                  j                  |      \  }}	 |j                  d       |j                  j                  |j                  |j                  |j                         |j                          t!        j"                   j                         y # |j                          t!        j"                   j                         w xY w)Nc                  (    j                  d       y )Nz"should not have called getaddrinfo)fail)r   r_  r<   s     r   r`  zYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfoK  s    II:;r   r  c                  0    t         j                        S r  rH  r   s   r   rz   zVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>T  re  r   rF   rf  )r  rX  r  )r`  r   rX   r    r'   r  rW   r  r!   r  ru   rZ  r   r   r   rp   r%   r   )r<   r(   r`  r  ra  r  r  r  s   `       r   %test_create_datagram_endpoint_ip_addrzDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addrI  s   	<  +3799;>$$)D $				%fn=yy113%* 2 ,
 yy++D11	.##N3OO..h6F6F5=5I5I4<4G4G / I GGI""499- GGI""499-s   0AD- -1Ec                     t        j                         }t               |j                  _        | j
                  j                  t        |       | j                  |j                  j                         y r   )r   rX   BlockingIOErroracceptrQ  rW   _accept_connectionr  rn   rp   r   r<   r  s     r   test_accept_connection_retryz;BaseEventLoopWithSelectorTests.test_accept_connection_retryb  sH    yy{"1"3		$$Wd3**+r   rP  c                 8   t        j                         }d|j                  _        t	        t
        j                  d      |j                  _        t        j                         | j                  _
        t        j                         | j                  _        | j                  j                  t        |       | j                  |j                  j                          | j#                  |j$                  j                          | j                  j                  j'                  d       | j                  j                  j'                  t(        j*                  t         j,                  t        |d d t         j,                  t         j,                  t         j,                  	       y )N
   zToo many open files)r   rX   filenor'   rk  r  EMFILEro  rQ  rW   _remove_readerr   rp  r  rq   rY  r   rn   rp   rZ  r   ACCEPT_RETRY_DELAYr  )r<   m_logr  s      r    test_accept_connection_exceptionz?BaseEventLoopWithSelectorTests.test_accept_connection_exceptioni  s    yy{#% ")%,,8M"N#'99;		 #yy{				$$Wd3**+**+		  33B7		//((HHT4txx488		Er   c                    d }| j                   j                  d       |} |       }| j                  |j                         ||fD ]W  }| 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                  | j                   j                  d |             d d d        Z y # 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   xY w# 1 sw Y   xY w)Nc                     K   y wr   r   r   r   r   simple_coroutinezLBaseEventLoopWithSelectorTests.test_call_coroutine.<locals>.simple_coroutine|  r  r  Tr   )rW   r   r*  rp   r_   r   r   r   r   r   r   ru   r  )r<   r}  	coro_funccoro_objr  s        r   test_call_coroutinez2BaseEventLoopWithSelectorTests.test_call_coroutine{  s   	 			D!$	;') 	;D""9- *		##D)*""9- 5		..t45""9- /		$$R./""9- ?		!!$)).."2R"7>?""9- ;		,,II--dD9;; ;	;* *5 5/ /? ?; ;s<    F#F0F<8G!6G#F-	0F9	<G	G	G	c                    d }d }t        j                  | j                         | j                  j                  d       d| j                  _        | j                  j                  || j                         | j                  j                          |j                  j                  d   ^}}| j                  |t        |      z  d       t        j                   || j                        | j                         | j                  j                          |j                  j                  d   ^}}| j                  |t        |      z  d       y )	Nc                 $    | j                          y r   r   rc  s    r   stop_loop_cbzLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cb  s    IIKr   c                 ,   K   | j                          y wr   r  rc  s    r   stop_loop_corozNBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_coro  s     IIK   Tg        r   z4^Executing <Handle.*stop_loop_cb.*> took .* seconds$rc  z4^Executing <Task.*stop_loop_coro.*> took .* seconds$)r   r[   rW   r   slow_callback_durationr   rt   warningr   r  tuplere  )r<   m_loggerr  r  fmtr   s         r   test_log_slow_callbacksz6BaseEventLoopWithSelectorTests.test_log_slow_callbacks  s   		 	tyy)		D!+.		( 			L$))4		%%//2
duT{*,	-
 	nTYY7diiH		%%//2
duT{*,	-r   )HrM   rN   rO   rU   r   r-   rU  r/   ry  r  r  r  r  r  unittest
skipUnlessr!   r    r  r
   r;   r  r  r  r  r  r  r  r  skipIfrD  platformr  r  r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r  r%  r*  r,  r1  r6  r8  r;  r>  r@  rD  rJ  rN  skip_unless_bind_unix_socketrS  rZ  rb  rg  rl  rr  rz  r  r  r  r  s   @r   rJ  rJ  4  s   '
 TZZ$%  & 
 %. %.N / /(J
33/ X9?A<A< X335FG H$3J
9C..4 &. &.P'2R X335FGX__S\\,,U3Z\. \ H.& = = > > 3 389$ + +N7`J
J/ "I
ID G G G G - - 9 9;93" 9 9 X335TU< V< 7 7J
 - -	3 X35FG3 H3 //8 08I@ X__S\\Y.CE-3E-3^ 	J 	J . .0, TZZ,-E .E";* TZZ,-- .-r   rJ  c                       e Zd Zd Zy)RunningLoopTestsc                 j   d }t        j                         }t        j                         }	 | j                  t        d      5  |j	                   ||             d d d        |j                          |j                          y # 1 sw Y   *xY w# |j                          |j                          w xY w)Nc                 ,   K   | j                          y wr   )rt   rc  s    r   runnerz@RunningLoopTests.test_running_loop_within_a_loop.<locals>.runner  s     r  zwhile another loop is running)r   r  r   rs   ru   rp   )r<   r  rW   
outer_loops       r   test_running_loop_within_a_loopz0RunningLoopTests.test_running_loop_within_a_loop  s    	 %%'++-
	''(GI <--fTl;< JJL< < JJLs#   B BB B	B "B2N)rM   rN   rO   r  r   r   r   r  r    s    r   r  c                        e Zd Zddz  Z G d dej
                        Ze fd       Ze fd       Z	 fdZ
ddZd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )BaseLoopSockSendfileTestss   12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcdei   c                   *    e Zd Zd Zd Zd Zd Zd Zy)!BaseLoopSockSendfileTests.MyProtoc                 v    d| _         d| _        t               | _        |j	                         | _        d | _        y ry   )r  closed	bytearrayr2  rr   r   r+  )r<   rW   s     r   r!  z*BaseLoopSockSendfileTests.MyProto.__init__  s0     DLDK!DI))+DH!DNr   c                      d| _         || _        y r   )r  r+  r-  s     r   r.  z1BaseLoopSockSendfileTests.MyProto.connection_made  s    DL&DNr   c                 :    | j                   j                  |       y r   )r2  extendr1  s     r   r3  z/BaseLoopSockSendfileTests.MyProto.data_received  s    IIT"r   c                 V    d| _         | j                  j                  d        d | _        y r   )r  r   r   r+  r:  s     r   r;  z1BaseLoopSockSendfileTests.MyProto.connection_lost  s"    DKHH%!DNr   c                 8   K   | j                    d {    y 7 wr   rN  r   s    r   r  z-BaseLoopSockSendfileTests.MyProto.wait_closed  s     ((NNs   N)rM   rN   rO   r!  r.  r3  r;  r  r   r   r   r  r    s    	"	'	#	"
	r   r  c                     t         j                  | _        dt         _        t        t        j
                  d      5 }|j                  | j                         d d d        t        | %          y # 1 sw Y   xY w)Ni @  wb)
r   !SENDFILE_FALLBACK_READBUFFER_SIZE'_BaseLoopSockSendfileTests__old_bufsizeopenr	   TESTFNr,  DATArT   
setUpClass)clsfpr]   s     r   r  z$BaseLoopSockSendfileTests.setUpClass  s[    %GG6?	3)""D) 	RHHSXX		 	s   A//A8c                     | j                   t        _        t        j                  t        j
                         t        |           y r   )r  r   r  r	   unlinkr  rT   tearDownClass)r  r]   s    r   r  z'BaseLoopSockSendfileTests.tearDownClass  s0    696G6G	3))*r   c                    ddl m}  |       | _        | j                  | j                         t	        t
        j                  d      | _        | j                  | j                  j                         t        | -          y )Nr   )BaseSelectorEventLooprb)asyncio.selector_eventsr  rW   r[   r  r	   r  filer*  rp   rT   rU   )r<   r  r]   s     r   rU   zBaseLoopSockSendfileTests.setUp  sS    A)+	DII&))40			(r   c                     t        j                   t         j                  t         j                        }|j                  |       | j	                  |j
                         |S r   )r    r   r   r=  r*  rp   )r<   blockingr  s      r   make_socketz%BaseLoopSockSendfileTests.make_socket  s?    }}V^^V-?-?@"

#r   c                 8    | j                   j                  |      S r   )rW   ru   r  s     r   rq  z"BaseLoopSockSendfileTests.run_loop  s    yy++D11r   c                      j                          j                   j                         j                   j                  j	                  fdt
        j                  dt        j                              j                  d   j                         }t        d      D ]/  }	  j                   j                  j                  |              n,  j                   j                  j                  |              fd} j!                  |       fS # t        $ r'  j                  t        j                  d             Y w xY w)Nc                       S r   r   )rX  s   r   rz   z3BaseLoopSockSendfileTests.prepare.<locals>.<lambda>  s    E r   r   r  rt  g      ?c                     j                          j                           j                  9 j                  j                          j                   j                                j                  j                                y r   )rp   r+  rq  r  )rX  r<   serverr  s   r   cleanupz2BaseLoopSockSendfileTests.prepare.<locals>.cleanup  sY    LLNJJL*%%'e//12MM&,,./r   )r  r  rW   rq  r  r
   HOSTr    r   r  getsocknamer  r}  rk  r   r   r*  )r<   rD  r  r  rX  r  r  s   `   @@@r   preparez!BaseLoopSockSendfileTests.prepare  s   !TYY'tyy66=--q  7  I J~~a ,,.r 
	>Adii44T4@A
 
	> MM$))00t<=	0 	 U{'  gmmC01s   )+D-EEc           	         | j                         \  }}| j                  t        j                  d      5  | j	                  | j
                  j                  || j                  dd              d d d        | j                  |j                  d       | j                  | j                  j                         d       y # 1 sw Y   PxY w)Nsendfile is not availabler   r   )r  r   r   SendfileNotAvailableErrorrq  rW   _sock_sendfile_nativer  r8   r2  tellr<   r  rX  s      r   "test__sock_sendfile_native_failurez<BaseLoopSockSendfileTests.test__sock_sendfile_native_failure  s    llne##G$E$E$?A 	DMM$))99$		:;TC D	D
 	S))1-	D 	D   8B;;Cc                    | j                         \  }}| j                  t        j                  d      5  | j	                  | j
                  j                  || j                  d             d d d        | j                  | j                  j                         d       | j                  |j                  d       y # 1 sw Y   PxY w)Nr  F)fallbackr   r   )r  r   r   r  rq  rW   sock_sendfiler  r8   r  r2  r  s      r   test_sock_sendfile_no_fallbackz8BaseLoopSockSendfileTests.test_sock_sendfile_no_fallback$  s    llne##G$E$E$?A 	CMM$))11$		;@ 2 B C	C
 	)1-S)	C 	Cr  c                    | j                         \  }}| j                  | j                  j                  || j                              }|j                          | j                  |j                                | j                  |t        | j                               | j                  | j                  j                         t        | j                               | j                  |j                  | j                         y r   )r  rq  rW   r  r  rp   r  r8   r  r  r  r2  r<   r  rX  rets       r   test_sock_sendfile_fallbackz5BaseLoopSockSendfileTests.test_sock_sendfile_fallback/  s    llnemmDII33D$))DE

e'')*c$))n-)3tyy>:TYY/r   c                    | j                         \  }}| j                  | j                  j                  || j                  dd            }|j                          | j                  |j                                | j                  |d       | j                  | j                  j                         d       | j                  |j                  | j                  dd        y )Ni  i  r  )r  rq  rW   r  r  rp   r  r8   r  r2  r  r  s       r   ,test_sock_sendfile_fallback_offset_and_countzFBaseLoopSockSendfileTests.test_sock_sendfile_fallback_offset_and_count:  s    llnemmDII33D$))48$@ A

e'')*d#)40TYYtD%9:r   c                    | j                   j                  d       | j                  d      }| j                  t        d      5  | j                  | j                   j                  || j                               d d d        y # 1 sw Y   y xY w)NT)r  zmust be non-blocking)rW   r   r  r   r+  rq  r  r  rq  s     r   test_blocking_socketz.BaseLoopSockSendfileTests.test_blocking_socketF  sr    		D!.##J0FG 	DMM$))11$		BC	D 	D 	Ds   6BBc                 0   | j                         }t        t        j                  d      5 }| j	                  t
        d      5  | j                  | j                  j                  ||             d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nzutf-8)encodingzbinary mode)	r  r  r	   r  r   r+  rq  rW   r  )r<   r  r.   s      r   test_nonbinary_filez-BaseLoopSockSendfileTests.test_nonbinary_fileL  s    !)""W5 	@''
MB @dii55dA>?@	@ 	@@ @	@ 	@s#   B,B /B B		BBc                    t        j                   t         j                  t         j                        }|j                  d       | j	                  |j
                         | j                  t        d      5  | j                  | j                  j                  || j                               d d d        y # 1 sw Y   y xY w)NFzonly SOCK_STREAM type)r    r   r   r=  r*  rp   r   r+  rq  rW   r  r  rq  s     r   test_nonstream_socketz/BaseLoopSockSendfileTests.test_nonstream_socketR  s    }}V^^V->->?

###J0GH 	DMM$))11$		BC	D 	D 	Ds   56B44B=c           	          | j                         }| j                  t        d      5  | j                  | j                  j                  || j                  dd             d d d        y # 1 sw Y   y xY w)N count must be a positive integerr   r  r  r   r   rq  rW   r  r  rq  s     r   test_notint_countz+BaseLoopSockSendfileTests.test_notint_countY  sb    !##I$FH 	PMM$))11$		1gNO	P 	P 	P   8A((A1c           	          | j                         }| j                  t        d      5  | j                  | j                  j                  || j                  dd             d d d        y # 1 sw Y   y xY w)Nr  r   r   r  r   r+  rq  rW   r  r  rq  s     r   test_negative_countz-BaseLoopSockSendfileTests.test_negative_count_  sb    !##J$FH 	KMM$))11$		1bIJ	K 	K 	Kr  c                     | j                         }| j                  t        d      5  | j                  | j                  j                  || j                  d             d d d        y # 1 sw Y   y xY w)N%offset must be a non-negative integeroffsetr  rq  s     r   test_notint_offsetz,BaseLoopSockSendfileTests.test_notint_offsete  s`    !##I$KM 	NMM$))11$		8LM	N 	N 	N   7A''A0c                     | j                         }| j                  t        d      5  | j                  | j                  j                  || j                  d             d d d        y # 1 sw Y   y xY w)Nr  r   r  rq  s     r   test_negative_offsetz.BaseLoopSockSendfileTests.test_negative_offsetk  s`    !##J$KM 	HMM$))11$		2FG	H 	H 	Hr  r   )rM   rN   rO   r  r   rr  r  classmethodr  r  rU   r  rq  r  r  r  r  r  r  r  r  r  r  r  r  r  r  s   @r   r  r    s    $D'"" 0      
2>	.	*	0
;D@DPKNHr   r  c                   R    e Zd Zd Z ej
                   eed      d      d        Zy)TestSelectorUtilsc                 *   |j                  t        j                  t        j                        }| j	                  |       t        j                  |       |j                  t        j                  t        j                        }| j                  |       y r   )r_  r    r   TCP_NODELAYrn   r   _set_nodelayrq   )r<   r  opts      r   check_set_nodelayz#TestSelectorUtils.check_set_nodelays  sb    oof00&2D2DE  &oof00&2D2DEr   r  zneed socket.TCP_NODELAYc                    t        j                   t         j                  t         j                  t         j                        }|5  | j	                  |       d d d        t        j                   t         j                  t         j                  t         j                        }|5  |j                  d       | j	                  |       d d d        y # 1 sw Y   yxY w# 1 sw Y   y xY w)N)r  r  rX  F)r    r   r   r   r  r=  rq  s     r   test_set_nodelayz"TestSelectorUtils.test_set_nodelay|  s     }}FNN9K9K#)#5#57 	)""4(	) }}FNN9K9K#)#5#57 	)U#""4(	) 	)	) 	)
	) 	)s   C##CCC$N)	rM   rN   rO   r  r  r  r!   r    r  r   r   r   r  r  r  s4     X724
)4
)r   r  __main__)+__doc__concurrent.futuresr   r  r  r    rD  r   r   r  r   r   r   r   test.test_asyncior   r%   r  r   test.support.script_helperr   test.supportr	   r
   r  r  r]  r   r*   r/   TestCaser1   rQ   rr  r  r0  r=  rJ  r  r  r  rM   r  r   r   r   <module>r     s        
        1  7 " & 88(":
^HZ(( ^HBZ1,, Z1z'g 'D'g.. '@v-Z%8%8 v-rx(( "qH
 3 3 qHh)
++ )4 zHMMO r   