
    z%i+<                    ^   	 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	j0                  Zd
 Zd Zd Z G d dej:                        Z G d dej:                        Z G d de
j@                        Z! G d de
jD                        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jR                          yy)    N)mock)base_events)	constants)utils)support)assert_python_ok)	os_helper)socket_helperc                  .    t        j                  d        y N)asyncioset_event_loop_policy     V/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/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. xZ/S )-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                    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                 P     fd}t        j                          j                  _        d} j                  j	                         |z   } j                  j                  ||        j                  j	                         } j                  j                           j                  j	                         |z
  } j                  ||dz
  |        j                  |d|        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   皙?g?g?zwhen cannot be Noner   )r   rX   rW   rd   timecall_atrt   assertGreaterEqualassertLessEqualr_   r   )r<   r   delaywhent0dts   `     r   test_time_and_call_atz(BaseEventLoopTests.test_time_and_call_at  s    	 %)IIK		!yy~~%'		$#YY^^		YY^^" 	EEM26 	Rb)y.CD 	(IIdB'	( 	( 	(s   6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>.cb%  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_thread$  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   )waitr   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_thread8  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_threadL  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_thread7  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>g  r{   r   r   r   c                       yr   r   r   r   r   rz   z3BaseEventLoopTests.test__run_once.<locals>.<lambda>i  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_oncef  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_debugx  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   r   _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   ShowStopperr"        r   r$  c                 J   K   t        j                  |        d {    y 7 wr   r   sleep)r   s    r   foozUBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.foo  s     --&&&s   #!#c                       r   r   )r$  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<   r)  r+  r$  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 )
Nr1  r/  r0  zexit 0T)r2  )r3  r5  )r4  )	r_   r   rW   ru   subprocess_shellr   r9  r6  r7  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>7      diinn.> r   Exception in callback.*zeroexc_info{Gz?c                 8    j                   j                         S r   r   rD  s    r   rz   zFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>A  rE  r   )r   rX   rW   rd   r-   rr   r   add_done_callbackrt   errorassert_called_withr%   MockPatternZeroDivisionErrorMOCK_ANYr   )r<   rA  logr   s   `   r   !test_default_exc_handler_callbackz4BaseEventLoopTests.test_default_exc_handler_callback,  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)NrI  r6   r   r'  r   r   r   zero_error_corozIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_coroJ  s$     --%%%aC &s   (&(rB  rW   c                  8    j                   j                         S r   r   )r   r<   s    r   rz   zBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>Q  s    		0@ r   z.*exception was never retrievedrG  )r   rX   rW   rd   r-   r   ensure_futurerK  rt   r   
gc_collectrL  rM  r%   rN  rO  rP  )r<   rU  rQ  r   s   `   r   test_default_exc_handler_coroz0BaseEventLoopTests.test_default_exc_handler_coroG  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_invalidZ  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   rA  zBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_error_  s	    aCr   c                  r    j                   j                        } j                   j                          | S r   rW   r   r   )r   r<   rA  s    r   run_loopz@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopb  s,    YY((4FII!Mr   Tz!Exception in callback.*zero_error)	exceptionmessager   source_tracebackrB  rF  rG  )rW   r   r   rX   rd   r:   get_exception_handlerr]  r   rM  rP  r%   rN  _source_traceback
reset_mockr-   rL  rO  rn   r   )r<   rd  mock_handlerr   rQ  rA  s   `    @r   test_set_exc_handler_customz.BaseEventLoopTests.test_set_exc_handler_custom^  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 ra  r   r   r   r   rA  zTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_error  	    !r   rc  )rA  r<   s    r   rd  z@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop  s*    II
+II!r   c                     t        d      Nr\  )AttributeErrorrW   contexts     r   handlerz?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handler  s     ((r   rB  z$Unhandled error in exception handlerrG  )r   rX   rW   rd   r]  r-   rL  rM  r%   rN  rs  rP  )r<   rd  rv  rQ  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      rr  r  )r<   ru  _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   Looprz    s"    !		I'diikO)r   r  c                  N    d } j                  |        j                          y )Nc                      ddz   y ra  r   r   r   r   rA  zXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error  rp  r   )r   r   )rA  rW   s    r   rd  zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop  s    NN:&NNr   rB  z&Exception in default exception handlerTrG  c                     t        d      )Nhamr|  rt  s     r   custom_handlerzJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handler  s    U##r   z9Exception in default exception.*while handling.*in customru  re  )r   rV   r  rp   r   r[   r   r-   rL  rM  r]  r%   rN  r   r   typerO  )r<   r  rd  rQ  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>.MyTaskNr#  r   r   r   MyTaskr    r%  r   r  c                     K   y wr   r   r   r   r   coroz6BaseEventLoopTests.test_set_task_factory.<locals>.coro  	        c                      ||       S NrV  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>.MyTaskNr#  r   r   r   r  r  	  r%  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  rV  F)	r   r  r   rV   r[   rX  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)recordrV  r   )
r   new_event_looprp   warningscatch_warningsr_   rs   rX  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>.test*  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_factory)  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_factory6  s    <<400r   c                     K   y wr   r   r   r   r   r  zKBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.test9  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_factory5  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_interruptI       ##   	)r   rX   rW   rd   call_exception_handlerru   r  rp   r   rY  rn   r   )r<   r  s     r   #test_run_forever_keyboard_interruptz6BaseEventLoopTests.test_run_forever_keyboard_interruptE  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_interrupt[  r  r  c                  H    j                   j                          d _        y r   )rW   r   r   )funcr<   s   r   r  zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcc  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_baseexceptionX  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_eventsr  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_eventw  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_stoppingk  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   rY  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_executorrY  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)0rM   rN   rO   rU   rl   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r-  r:  r=  rR  rZ  r^  rl  rw  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+#
	+
,(*/&-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  r(  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!  r&  r)  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 Nr4  r#  )r<   r%  addrs      r   datagram_receivedz!MyDatagramProto.datagram_received  s"    =)s4y r   c                 &    | j                  d       y r6  )r  r-  s     r   error_receivedzMyDatagramProto.error_received  s    =)r   c                     | j                  d       d| _        | j                  r| j                  j                  d        y y )Nr4  r+  r,  r-  s     r   r.  zMyDatagramProto.connection_lost   s5    =)
99II  & r   )FN)
rM   rN   rO   r  r  r  r!  r8  r:  r.  r   r   r   r0  r0    s&    D-S#
!*'r   r0  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.setUp)  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>0  r{   r   )abcr1  rB  )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>.MyProtoNr#  r   r   r   r  rK  7  r%  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>.getaddrinfo:  s     779 9   c                  F    j                   j                   | i |      S r   rW   r  r   kwdsrS  r<   s     r   getaddrinfo_taskz_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_task>  "    99((d)Cd)CDDr   r   err1err2c                  *    dz  t                 r  )OSError)r   rR  errorsidxs     r   _socketzVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socketD  s    1HC&+&&r   example.comrP  zMultiple exceptions: err1, err2T
all_errors)r   Protocolr    rW   rS  create_connectionr_   r^  ru   r8   strre  ExceptionGroupr   
exceptions)r<   r(   r  rY  ra  r  cmer_  rS  r`  s   `       @@@r   &test_create_connection_multiple_errorszEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors4  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.1rP  )rW   rr   r    r   r   r   )r   rR  r   r7  r<   s       r   rS  zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfob  sE    ))))+CNNF$6$62%'DNND6"Jr   sock_connect)rD  ro  rP  )r   rX   r    r'   rW   rS  r-   r  r   TimeoutErrorrf  r  r_   ru   rq   rp   r   )r<   r(   sockrS  r  s   `    r   test_create_connection_timeoutz=BaseEventLoopWithSelectorTests.test_create_connection_timeout\  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 )Nrb  rP  rr  )rW   rf  r  r  r_   r  ru   r<   r  s     r   %test_create_connection_host_port_sockzDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sockq  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Nru  zA Stream Socket was expected)	r    r   r   rW   rf  r  r   r  ru   r<   rr  r  s      r   !test_create_connection_wrong_sockz@BaseEventLoopWithSelectorTests.test_create_connection_wrong_sockv  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ry  )	r    r   r   rW   create_serverr  r   r  ru   rz  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Nrb  rP  r6   )ssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)rW   r~  r  r   r  ru   rv  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   ru  )	r    r   r   r  rW   r~  ru   rp   wait_closed)r<   rr  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   r^  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)Nru  zA UDP Socket was expected)r    r   rW   create_datagram_endpointr  r   r  ru   rz  s      r   (test_create_datagram_endpoint_wrong_sockzGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_wrong_sock  s    }}V^^, 	39955gD5ID''
(CE 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   rf  r  r_   r  ru   rv  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   rQ  s     r   rS  zYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo  s     Is   c                  F    j                   j                   | i |      S r   rV  rW  s     r   rY  z^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_task  rZ  r   rb  rP  )rW   rS  rf  r  r_   r^  ru   r<   rY  r  rS  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rM  r   rQ  s     r   rS  zVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo  s     788s   c                  F    j                   j                   | i |      S r   rV  rW  s     r   rY  z[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_task  rZ  r   rb  rP  Trc  r6   r   )rW   rS  r   rX   rp  r^  rD  rf  r  r_   ru   rh  r   re  r8   r	  ri  )r<   rY  r  rj  rS  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   rO  r3   )0.0.0.1rP  )r  r6   rO  r3   )z0.0.0.2rP  r   rQ  s     r   rS  zSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo       224 4rT  c                  F    j                   j                   | i |      S r   rV  rW  s     r   rY  zXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_task  rZ  r   rb  rP  familyT)r  rd  )rW   rS  r   rX   rp  r^  rD  rf  r  r    r   r_   ru   rh  r   re  ri  )r<   rY  r  rj  rk  rS  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)r^  strerror)r7  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   rQ  s     r   rS  zeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo   r  rT  c                  F    j                   j                   | i |      S r   rV  rW  s     r   rY  zjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_task  rZ  r   Err2rb  rP  Ni  r  
local_addrzMultiple exceptions: T)r  r  rd  )r    r'   r  rW   rS  r   rX   rp  r^  rD  rf  r  r   r_   ru   rq   rg  re  
startswithrp   r   rh  r   ri  )r<   r(   r  rY  r  rj  rk  rS  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   rP  r5   rP  r  r  r  r   r  z	::(0\.)*1)r   r    rS  r'   r   rX   rW   _add_reader_add_writerrf  r   re  ru   connectrM  r   r8   r   r   rp   r%   r   r
   r;   r   r  assertRegex)r<   r(   allow_inet_ptonrr  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%1rP  )zfe80::1rP  r   r6   r  r  )r    rS  r'   r   r  r   rX   rW   r  r  rf  r   re  ru   r  rM  r   r8   r   rp   r%   r   )r<   r(   rr  r  r   r  r  r   s           r   !test_create_connection_ipv6_scopez@BaseEventLoopWithSelectorTests.test_create_connection_ipv6_scopeG  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_addr^  s    ,,Xt<r   c                 (    | j                  |d       y ry   r  rK   s     r   #test_create_connection_no_inet_ptonzBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptonb  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))httprP  )s   httprP  ro  r  r  )nonsenses   nonsense)r    rS  r'   r   rX   rW   r  r  rf  r   re  ru   r  rM  r   r8   r   r   rp   r%   r   r_   r^  )
r<   r(   rr  servicer  r  r   r  r  r   s
             r   #test_create_connection_service_namezBBaseEventLoopWithSelectorTests.test_create_connection_service_namef  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)Nrb  rN  r   )r  r   rR  s      r   rS  zXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo  s%     }$;;= = 	s   c                  F    j                   j                   | i |      S r   rV  rW  s     r   rY  z]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_task  rZ  r   rb  rP  r  r  )	rW   rS  rf  r  r    r   r_   r^  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   rR  r7  r<   s       r   rS  zTBaseEventLoopWithSelectorTests.test_create_connection_bluetooth.<locals>.getaddrinfo  s/    dD\40!S"tQi011r   )rS  r    rW   rp  ru   )r<   r(   rS  rr  r  r7  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   rX  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  )rr  protocol
sslcontextwaiterrX  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.orgrP  T)sslr  ssl_shutdown_timeoutF)server_sideserver_hostnamer  r  zperl.com)r  r  r  r  r3   )r   rX   rW   rS  rD  rp  rr   r'   r   rb   ANYr  rj  rf  r  ru   rp   rM  )
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  rP  r3   )r  r  rv  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   rP  T)r  )r  rr  )	rW   rf  r  r_   r  ru   r    r  rp   )r<   r  rr  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   rf  r  r   r  ru   rv  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   rR  r  s     r   rS  zQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo  s     7DIs   c                  F    j                   j                   | i |      S r   rV  rW  s     r   rY  zVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_task  rZ  r   r3   r   )	r  rW   rS  r~  r  r_   r^  ru   r:   )r<   rY  r   rS  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   ru  )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_sock'  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   rS  rr   r'   r   r~  r  r_   r^  ru   )r<   rS  r.   s      r   !test_create_server_no_getaddrinfoz@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfo+  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    rS  SO_REUSEPORTr   rX   r'   rW   r~  r  r_   r  ru   r<   r(   r.   s      r    test_create_server_nosoreuseportz?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseport3  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    rS  r   rX   r'   r  rW   r~  r  r_   r  ru   r  s      r   +test_create_server_soreuseport_only_definedzJBaseEventLoopWithSelectorTests.test_create_server_soreuseport_only_defined>  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>.ErrrL  N)rM   rN   rO   r  r   r   r   r  r  L  s    Hr   r  )r  r6   rO  r3   )ro  it'  r  r   )r^  rS  r'   r   rX   r    r  rD  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_bindI  s    	' 	 0-1)04		;-"%ii%%gy!<'499#?#?E++,r   c                     g |j                   _        | j                  j                  t        d      }| j                  t        | j                  j                  |       y )N)	localhostr   r  )rS  r'   rW   r  r0  r_   r^  ru   r<   r(   r  s      r   )test_create_datagram_endpoint_no_addrinfozHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfoX  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  r0  r_   r   ru   rv  s     r   (test_create_datagram_endpoint_addr_errorzGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errora  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ro  r   )remote_addr)r   rX   rW   rp  r^  rD  r  r   DatagramProtocolr_   ru   rv  s     r   )test_create_datagram_endpoint_connect_errzHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_connect_errk  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>z  s    H r   r!  )r"  allow_broadcastr+  )r0  rW   r   rX   rp  r'   r  ru   rn   r   rp   r  r8   r  )r<   rp  r  r  r  r  s        @r   -test_create_datagram_endpoint_allow_broadcastzLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcastt  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    rS  r^  rD  rW   r  r   r#  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   r#  r_   r  ru   rv  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  )r^  r    r'   setblockingrD  rW   r  r   r#  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-  rv  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>.ErrNr#  r   r   r   r  r6    r%  r   r  r!  )r  r  )r^  r    rS  r   rX   r'   r  rD  rW   r  r0  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 NTr&  r0  rW   r   s   r   rz   zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>      O$TYYG r   ru  r+  )r    r   r   r  rW   r  ru   rp   r  r8   r  )r<   rr  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 r:  r;  r   s   r   rz   zXBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unix.<locals>.<lambda>  r<  r   r  r+  )rW   r  r    r>  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 r:  r;  r   s   r   rz   zaBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unix.<locals>.<lambda>  s    dK r   r  )r%   unix_socket_pathr    r>  r   r  rp   rW   r  ru   r  )r<   pathrr  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   FakeSockrI    s    $$Dr   rJ  r!  )r  rr  )r"  rr  r6   )r  rr  )protorr  )flagsrr  T)r  rr  )r(  rr  )rW   r  r0  r_   r  ru   )r<   rJ  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 r:  r;  r   s   r   rz   zWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>  r<  r   r!  r  r    r  r+  c                  2    t        d j                        S r:  r;  r   s   r   rz   zWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>  r<  r   T)r  r  r(  )rW   r  ru   r  r!   r    rn   
getsockoptr   r  SO_BROADCASTrp   r  r8   r  r   rq   )r<   r  r  r  rr  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  r;  r   s   r   rz   z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>6      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_nosoreuseport0  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   rR  r<   s     r   rS  zYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfo>  s    II:;r   r  c                  0    t         j                        S r  r;  r   s   r   rz   zVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>G  rX  r   rF   rY  )r  rK  r  )rS  r   rX   r    r'   r  rW   r  r!   r  ru   rM  r   r   r   rp   r%   r   )r<   r(   rS  r  rT  r  r   r  s   `       r   %test_create_datagram_endpoint_ip_addrzDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr<  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acceptrD  rW   _accept_connectionr  rn   rp   r   r<   rr  s     r   test_accept_connection_retryz;BaseEventLoopWithSelectorTests.test_accept_connection_retryU  sH    yy{"1"3		$$Wd3**+r   rB  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'   r^  r  EMFILErb  rD  rW   _remove_readerr   rc  r  rq   rL  r   rn   rp   rM  r   ACCEPT_RETRY_DELAYr  )r<   m_logrr  s      r    test_accept_connection_exceptionz?BaseEventLoopWithSelectorTests.test_accept_connection_exception\  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_coroutineo  r  r  Tr   )rW   r   r  rp   r_   r   r   r   r   r   r   ru   r  )r<   rp  	coro_funccoro_objr  s        r   test_call_coroutinez2BaseEventLoopWithSelectorTests.test_call_coroutinen  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   rV  s    r   stop_loop_cbzLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cb  s    IIKr   c                 ,   K   | j                          y wr   rv  rV  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$rV  z4^Executing <Task.*stop_loop_coro.*> took .* seconds$)r   r[   rW   r   slow_callback_durationr   rt   warningr   r  tuplerX  )r<   m_loggerrw  ry  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-   rH  r/   rl  rs  rw  r{  r  r  unittest
skipUnlessr!   r    r  r
   r;   r  r  r  r  r  r  r  r  skipIfr6  platformr  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r$  r)  r+  r.  r1  r3  r7  r=  rA  skip_unless_bind_unix_socketrF  rM  rU  rZ  r_  re  rm  rs  r  r	  r
  s   @r   r=  r=  '  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   r=  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   rV  s    r   runnerz@RunningLoopTests.test_running_loop_within_a_loop.<locals>.runner  s     rz  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	bytearrayr%  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   )r%  extendr$  s     r   r&  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   r@  r   s    r   r  z-BaseLoopSockSendfileTests.MyProto.wait_closed  s     ((NNs   N)rM   rN   rO   r  r!  r&  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   r0  r  rp   )r<   blockingrr  s      r   make_socketz%BaseLoopSockSendfileTests.make_socket  s?    }}V^^V-?-?@"

#r   c                 8    | j                   j                  |      S r   )rW   ru   rv  s     r   rd  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   )rK  s   r   rz   z3BaseLoopSockSendfileTests.prepare.<locals>.<lambda>  s    E r   r   r  rg  g      ?c                     j                          j                           j                  9 j                  j                          j                   j                                j                  j                                y r   )rp   r  rd  r  )rK  r<   serverrr  s   r   cleanupz2BaseLoopSockSendfileTests.prepare.<locals>.cleanup   sY    LLNJJL*%%'e//12MM&,,./r   )r  r  rW   rd  r~  r
   HOSTr    r   r  getsocknamer  rp  r^  r   r(  r  )r<   r7  r  r  rK  r  rr  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   SendfileNotAvailableErrorrd  rW   _sock_sendfile_nativer  r8   r%  tellr<   rr  rK  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  rd  rW   sock_sendfiler  r8   r  r%  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  rd  rW   r  r  rp   r  r8   r	  r  r  r%  r<   rr  rK  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  rd  rW   r  r  rp   r  r8   r  r%  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  rd  r  r  rd  s     r   test_blocking_socketz.BaseLoopSockSendfileTests.test_blocking_socket9  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  rd  rW   r  )r<   rr  r.   s      r   test_nonbinary_filez-BaseLoopSockSendfileTests.test_nonbinary_file?  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   r0  r  rp   r   r  rd  rW   r  r  rd  s     r   test_nonstream_socketz/BaseLoopSockSendfileTests.test_nonstream_socketE  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   rd  rW   r  r  rd  s     r   test_notint_countz+BaseLoopSockSendfileTests.test_notint_countL  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  rd  rW   r  r  rd  s     r   test_negative_countz-BaseLoopSockSendfileTests.test_negative_countR  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  rd  s     r   test_notint_offsetz,BaseLoopSockSendfileTests.test_notint_offsetX  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  rd  s     r   test_negative_offsetz.BaseLoopSockSendfileTests.test_negative_offset^  s`    !##J$KM 	HMM$))11$		2FG	H 	H 	Hr  r   )rM   rN   rO   r  r   re  r  classmethodr  r  rU   r  rd  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   )rR  r    r   TCP_NODELAYrn   r   _set_nodelayrq   )r<   rr  opts      r   check_set_nodelayz#TestSelectorUtils.check_set_nodelayf  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  rK  F)r    r   r   r   r  r0  rd  s     r   test_set_nodelayz"TestSelectorUtils.test_set_nodelayo  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  e  s4     X724
)4
)r   r  __main__)*concurrent.futuresr   r  r  r    r6  r   r   r  r   r   r   r   test.test_asyncior   r%   r  r   test.support.script_helperr   test.supportr	   r
   r  r  rP  r   r*   r/   TestCaser1   rQ   re  r  r#  r0  r=  r  r  r  rM   r  r   r   r   <module>r     s        
        1  7 " & 88(":
^HZ(( ^HBM1,, M1`'g 'D'g.. '@v-Z%8%8 v-rx(( "qH
 3 3 qHh)
++ )4 zHMMO r   