Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/test_asyncio/__pycache__/test_base_events.cpython-34.pyc

�
f f	��@s)dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl	m
Z
ddlZddlmZddlm
Z
ddlmZyddlmZWn"ek
r�ddlmZYnXydd	lmZWnKek
rXydd	lmZWn"ek
rSdd	lmZYnXYnXe
jZejd
dfkZdd
�Zdd�ZGdd�dej�ZGdd�dej�ZGdd�dej �Z!Gdd�dej"�Z#Gdd�dej�Z$e%dkr%e	j&�ndS)zTests for base_events.py�N)�mock)�base_events)�	constants)�
test_utils)�support)�test_support)�assert_python_ok��c
Cs�tjdt�}xFdD]>}tt|�rJt||tt|��qt||�qWtj�|_tj�|j_	|S)
N�spec�AF_INET�AF_INET6�	AF_UNSPEC�IPPROTO_TCP�IPPROTO_UDP�SOCK_STREAM�
SOCK_DGRAM�
SOL_SOCKET�SO_REUSEADDR�	inet_pton)
zAF_INETzAF_INET6z	AF_UNSPECzIPPROTO_TCPzIPPROTO_UDPzSOCK_STREAMz
SOCK_DGRAMz
SOL_SOCKETzSO_REUSEADDRz	inet_pton)
rZ	MagicMock�socket�hasattr�setattr�getattr�delattrrZmock_nonblocking_socket�return_value)�m_socket�name�r�G/opt/alt/python34/lib64/python3.4/test/test_asyncio/test_base_events.py�mock_socket_module#s
r cCstjddt�|�S)Nzasyncio.base_events.socketZnew_callable)r�patchr )�frrr�patch_socket4sr#csjeZdZ�fdd�Z�fdd�Zdd�Zedd��Zd	d
�Zdd�Z	�S)
�BaseEventTestscst�j�tjj�dS)N)�super�setUpr�_ipaddr_info�cache_clear)�self)�	__class__rrr&;s
zBaseEventTests.setUpcstjj�t�j�dS)N)rr'r(r%�tearDown)r))r*rrr+?s
zBaseEventTests.tearDowncCsItj}tj}tj}tj}tj}tj}tj}|j|||ddft	j
dd|||��|j|||ddft	j
dd|||��|j|||dd	ft	j
dd|||��|j|||dd
ft	j
dd||d��|j|||ddft	j
dd||d��|jt	j
dd|dd��|jt	j
dd|||��|j|||ddft	j
dd|||��|j|||dd
ft	j
dd|||��|jt	j
dd|||��|j|||ddft	j
dd|||��dS)N��1.2.3.4�r�::3�::3%lo0)r-r.)r-r.)r-r.)r-r.)r-r.)r/r.)r/r.)r0r.)rrrr
rrrr�assertEqualrr'�assertIsNone)r)ZUNSPECZINETZINET6ZSTREAMZDGRAMZTCPZUDPrrr�test_ipaddr_infoCsJ							zBaseEventTests.test_ipaddr_infocCs|`|j�dS)N)rr3)r)rrrr�test_ipaddr_info_no_inet_pton{sz,BaseEventTests.test_ipaddr_info_no_inet_ptoncCs�tjtj�}|�tj|d�WdQXtjtj�}|�Ktj|d�tj|d�|jt��tj|d	�WdQXWdQXdS)
N�1.2.3.4r.�::3�::3%lo0�foo)r5r.)r6r.)r7r.)r8r.)rrr�_check_resolved_addressr
�assertRaises�
ValueError)r)�sockrrr�test_check_resolved_address�sz*BaseEventTests.test_check_resolved_addresscCs�ttd�rKtjdtjtjB�}|�tj|d�WdQXnttd�r�tjdtjtjB�}|�tj|d�WdQXndS)N�
SOCK_NONBLOCK�type�1.2.3.4r.�SOCK_CLOEXEC)r@r.)r@r.)rrrr>rr9rA)r)r<rrr�test_check_resolved_sock_type�sz,BaseEventTests.test_check_resolved_sock_type)
�__name__�
__module__�__qualname__r&r+r3r#r4r=rBrr)r*rr$9s8r$c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zejd%�d&d'��Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Z d:d;�Z!d<d=�Z"d>d?�Z#d@dA�Z$dBdC�Z%dDdE�Z&dFdG�Z'dHdI�Z(dJdK�Z)dLdM�Z*dNdO�Z+dPdQ�Z,dRS)S�BaseEventLoopTestscCsGtj�|_tj�|j_f|jjj_|j|j�dS)N)	r�
BaseEventLoop�loopr�Mock�	_selector�selectr�set_event_loop)r)rrrr&�szBaseEventLoopTests.setUpc	Cstj�}|jt|jj||�|jt|jj||||�|jt|jj||�|jt|jjg�|jt|jj	�|jt|jj
||�|jt|jj||�|jj|||||||�}|jt��|j
d�WdQXdS)N)rrIr:�NotImplementedErrorrHZ_make_socket_transport�_make_ssl_transportZ_make_datagram_transport�_process_events�_write_to_selfZ_make_read_pipe_transportZ_make_write_pipe_transportZ_make_subprocess_transport�send)r)�m�genrrr�test_not_implemented�s.$z'BaseEventLoopTests.test_not_implementedcCs�|j|jj��|jj�|j|jj��|jj�|jj�tjd|j�}|jt|jj	�|jt|jj
|�dS)NrH)�assertFalserHZ	is_closed�close�
assertTrue�asyncio�Futurer:�RuntimeError�run_forever�run_until_complete)r)r"rrr�
test_close�s


zBaseEventLoopTests.test_closecCs[tjdd�f|j�}|jj|�|j|jj�|j||jj�dS)NcSsdS)NFrrrrr�<lambda>�sz>BaseEventLoopTests.test__add_callback_handle.<locals>.<lambda>)rX�HandlerH�
_add_callbackrU�
_scheduled�assertIn�_ready)r)�hrrr�test__add_callback_handle�sz,BaseEventLoopTests.test__add_callback_handlecCsbtjdd�f|j�}|j�|jj|�|j|jj�|j|jj�dS)NcSsdS)NFrrrrrr^�szHBaseEventLoopTests.test__add_callback_cancelled_handle.<locals>.<lambda>)rXr_rH�cancelr`rUrarc)r)rdrrr�#test__add_callback_cancelled_handle�s

z6BaseEventLoopTests.test__add_callback_cancelled_handlecCs6tj�}|jj|�|j||jj�dS)N)rrIrH�set_default_executor�assertIsZ_default_executor)r)�executorrrr�test_set_default_executor�sz,BaseEventLoopTests.test_set_default_executorcCs^tj�}tj�|j_|jj|�|jdtj|df|jjjd�dS)Nr)rrIrH�run_in_executorZgetnameinfor1r�	call_args)r)Zsockaddrrrr�test_getnameinfo�sz#BaseEventLoopTests.test_getnameinfocCs^dd�}|jj|�}|j|j|�|j|tj�|j||jj�dS)NcSsdS)Nrrrrr�cb�sz-BaseEventLoopTests.test_call_soon.<locals>.cb)	rH�	call_soonr1Z	_callback�assertIsInstancerXr_rbrc)r)rordrrr�test_call_soon�s
z!BaseEventLoopTests.test_call_sooncCsddd�}|jjd|�}|j|tj�|j||jj�|j||jj�dS)NcSsdS)Nrrrrrro�sz.BaseEventLoopTests.test_call_later.<locals>.cbg$@)	rH�
call_laterrqrX�TimerHandlerbraZassertNotInrc)r)rordrrr�test_call_later�s
z"BaseEventLoopTests.test_call_latercs�g��fdd�}tj�|j_|jjd|d�|jjd|d�tj|j�|j�ddg�dS)	Ncs�j|�dS)N)�append)�arg)�callsrrro�sz>BaseEventLoopTests.test_call_later_negative_delays.<locals>.cbr.�a��b������)rrIrHrOrsr�run_brieflyr1)r)ror)rxr�test_call_later_negative_delays�sz2BaseEventLoopTests.test_call_later_negative_delayscs��fdd�}tj��j_d}�jj�|}�jj||��jj�}�jj��jj�|}�j||d|��j|d|�dS)Ncs�jj�dS)N)rH�stopr)r)rrrosz4BaseEventLoopTests.test_time_and_call_at.<locals>.cbg�������?g�������?g�������?)	rrIrHrO�time�call_atr[ZassertGreaterEqual�assertLessEqual)r)roZdelayZwhenZt0Zdtr)r)r�test_time_and_call_ats
z(BaseEventLoopTests.test_time_and_call_atcCs�dd�}|j|�|r�d}|jt|��|j|�WdQX|jt|��|jd|�WdQX|jt|��|j|j�d|�WdQXn7|j|�|jd|�|j|j�d|�dS)NcSsdS)Nrrrrrrosz+BaseEventLoopTests.check_thread.<locals>.cbzMNon-thread-safe operation invoked on an event loop other than the current one�<)�	set_debug�assertRaisesRegexrZrprsr�r�)r)rH�debugro�msgrrr�check_threads
#
zBaseEventLoopTests.check_threadcs��fdd��d�fdd�}tj��j_tj��j_|�jd�|�jd�|�jddd�|�jddd�dS)Ncs�|j�ye|r^tj�}z!tj|��j||�Wdtjd�|j�Xn�j||�Wn8tk
r�}z|j|j	|�WYdd}~XnX|j|j
d�dS)N)�waitrrGrXrLr�rV�	Exception�call_soon_threadsafeZ
set_exception�
set_result)rH�eventr��create_loop�futZloop2�exc)r)rr�check_in_thread)s


&z=BaseEventLoopTests.test_check_thread.<locals>.check_in_threadFcs�tj�}tjd|�}|j|j�|||||f}tjd�d|�}|j�|j|�|j	�dS)NrH�target�args)
�	threadingZEventrXrYrp�setZThread�startr\�join)rHr�r�r�r�r�Zthread)r�rr�test_thread=s

z9BaseEventLoopTests.test_check_thread.<locals>.test_threadTr�)rrIrHrOrP)r)r�r)r�r)r�test_check_thread(s
z$BaseEventLoopTests.test_check_threadc	Csrdd�}|jt|jjdtj|f|j�d�|jt|jjdtjd|f|j��dS)NcSsdS)NrrrrrroXsz?BaseEventLoopTests.test_run_once_in_executor_handle.<locals>.cbr,�
)r,)r:�AssertionErrorrHrlrXr_rt)r)rorrr� test_run_once_in_executor_handleWsz3BaseEventLoopTests.test_run_once_in_executor_handlecCs�dd�}tj|f|j�}|j�|jjd|�}|j|tj�|j|j��|j	|j
��dS)NcSsdS)NrrrrrrocszBBaseEventLoopTests.test_run_once_in_executor_cancelled.<locals>.cb)rXr_rHrfrlrqrYrW�doner2�result)r)rordr"rrr�#test_run_once_in_executor_cancelledbs
z6BaseEventLoopTests.test_run_once_in_executor_cancelledcCs�dd�}tj|f|j�}tjd|j�}tj�}||j_|jj|�|jj	d|�}|j
||�tj�}||j_|jj	||�}|j
||�|j|jj�|j
�dS)NcSsdS)Nrrrrrronsz>BaseEventLoopTests.test_run_once_in_executor_plain.<locals>.cbrH)rXr_rHrYrrIZsubmitrrhrlrirW�calledrf)r)rordr"rj�resrrr�test_run_once_in_executor_plainmsz2BaseEventLoopTests.test_run_once_in_executor_plaincCstjtj�ddd�f|j�}tjtj�ddd�f|j�}|j�tj�|j_|jj	j
|�|jj	j
|�|jj�|jjj
jdd}|jd|ko�dkn|�|j|g|jj	�|j|jjj�dS)	Ng@cSsdS)NTrrrrrr^�sz3BaseEventLoopTests.test__run_once.<locals>.<lambda>g$@cSsdS)NTrrrrrr^�srg#@g%@)rXrtr��	monotonicrHrfrrIrOrarv�	_run_oncerJrKrmrWr1r�)r)Zh1Zh2�trrr�test__run_once�s

&z!BaseEventLoopTests.test__run_oncecCsP|jjd�|j|jj��|jjd�|j|jj��dS)NTF)rHr�rWZ	get_debugrU)r)rrr�test_set_debug�sz!BaseEventLoopTests.test_set_debugzasyncio.base_events.loggercCs�dd�}|jjd�||jj_tj�|j_|jj�|jt	j
|jjdd�dd�}||jj_|jj�|jt	j
|jjdd�dS)NcSstjd�gS)Ng�������?)r��sleep)�timeoutrrr�slow_select�s
z>BaseEventLoopTests.test__run_once_logging.<locals>.slow_selectTrcSstjd�gS)Ng����MbP?)r�r�)r�rrr�fast_select�s
z>BaseEventLoopTests.test__run_once_logging.<locals>.fast_select)rHr�rJrKrrIrOr�r1�logging�INFO�logrm�DEBUG)r)�m_loggerr�r�rrr�test__run_once_logging�s
!
z)BaseEventLoopTests.test__run_once_loggingcs�d�d���fdd�}tjtj�d||jf|j�}tj�|j_|jjj	|�|jj
�|j��|j�gt
|jj��dS)NFcsd�|jdd���dS)NTcSsdS)NTrrrrrr^�szOBaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb.<locals>.<lambda>)rp)rH)�handle�	processedrrro�sz=BaseEventLoopTests.test__run_once_schedule_handle.<locals>.cbr.)rXrtr�r�rHrrIrOrarvr�rWr1�listrc)r)rordr)r�r�r�test__run_once_schedule_handle�s

z1BaseEventLoopTests.test__run_once_schedule_handlecCsstj�|j_|jdtjko2dkn�dd�}d}|jjd|�d}x3td�D]%}|jjd|�}|j	�qpW|d7}x3td�D]%}|jjd	|�}|j	�q�W|j
||tj�|j|jj
|�|jj�|d8}|j|jj
|�|jt|jj�||�ttjtjtj��d}ttj|d�}||7}x't|�D]}|jjd|�q�W||7}x3t|�D]%}|jjd|�}|j	�q�W|jt|jj�||�|jj�|jt|jj�|�|jtd
d�|jjD���dS)Nrg�?cSsdS)Nrrrrrro�szEBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.cbr.i�rzi�dcSsg|]}|j�qSr)Z
_cancelled)�.0�xrrr�
<listcomp>s	zMBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.<listcomp>)rrIrHrOrWrZ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONrs�rangerfr�Z_MIN_SCHEDULED_TIMER_HANDLESr1Z_timer_cancelled_countr��lenra�int�mathZceil�max�all)r)roZnot_cancelled_countZcancelled_countr�rdZadd_cancel_countZadd_not_cancel_countrrr�&test__run_once_cancelled_event_cleanup�sN 




		



z9BaseEventLoopTests.test__run_once_cancelled_event_cleanupcCs|jt|jjd�dS)NZblah)r:�	TypeErrorrHr\)r)rrr�"test_run_until_complete_type_errors	z5BaseEventLoopTests.test_run_until_complete_type_errorcCsKtjd|j�}|j�}|j|j�|jt|j|�dS)NrH)	rXrYrHZ
new_test_loop�
addCleanuprVr:r;r\)r)�taskZ
other_looprrr�test_run_until_complete_loops
	z/BaseEventLoopTests.test_run_until_complete_loopcCstjddg}|jt|jj|jjtj�|jt|jj|jjtj|�|jt|jj|jjtjtjd�|jt|jj|jjtjdd|�|jt|jj|jjtjdd|�|jt|jj|jjtjdd|�dS)	Nz-c�pass�{�universal_newlinesT�shell�bufsizei)	�sys�
executabler:r�rHr\Zsubprocess_execrX�SubprocessProtocol)r)r�rrr�!test_subprocess_exec_invalid_argss&	
	
				z4BaseEventLoopTests.test_subprocess_exec_invalid_argscCs�|jt|jj|jjtjd�|jt|jj|jjtjtjddg�|jt|jj|jjtjddd�|jt|jj|jjtjddd�|jt|jj|jjtjddd	�dS)
Nr�z-cr�zexit 0r�Tr�r�i)	r:r�rHr\Zsubprocess_shellrXr�r�r�)r)rrr�"test_subprocess_shell_invalid_args:s	
				z5BaseEventLoopTests.test_subprocess_shell_invalid_argscsAtj��j_dd�}tjd��}}tjd�j�}�jj||�|j�fdd���jj	�|j
jtj
d�dtttf�WdQXtjd���}tjd�j�}�jjd	||�|j�fd
d���jj	�|j
jtj
d�dtttf�WdQXdS)NcSs|jd�dddS)NTr.r)r�)r�rrr�
zero_errorQs
zHBaseEventLoopTests.test_default_exc_handler_callback.<locals>.zero_errorzasyncio.base_events.loggerrHcs
�jj�S)N)rHr�)r�)r)rrr^YszFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>zException in callback.*zero�exc_infog{�G�z�?cs
�jj�S)N)rHr�)r�)r)rrr^cs)rrIrHrOr!rXrYrp�add_done_callbackr[�error�assert_called_withr�MockPattern�ZeroDivisionError�MOCK_ANYrs)r)r�r�r�r)r)r�!test_default_exc_handler_callbackNs$
	
	z4BaseEventLoopTests.test_default_exc_handler_callbackc
s�tj��j_tj�fdd��}tjd���}tj|�d�j�}|j�fdd���jj	�d}t
r�|jjt
jd�dtttf�n|jjt
jd	�dd
�WdQXdS)Nc3s'tjdd�j�DdHdddS)Ng{�G�z�?rHr.r)rXr�rHr)r)rr�zero_error_corolszIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_corozasyncio.base_events.loggerrHcs
�jj�S)N)rHr�)r�)r)rrr^tszBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>z.*exception was never retrievedr�z(.*exception was never retrieved.*ZeroDivF)rrIrHrOrX�	coroutiner!�
ensure_futurer�r[�PY34r�r�rr�r�r�)r)r�r�r�r)r)r�test_default_exc_handler_corois
			z0BaseEventLoopTests.test_default_exc_handler_coroc	Cs-|jtd��|jjd�WdQXdS)NzA callable object or None�spam)r�r�rH�set_exception_handler)r)rrr�test_set_exc_handler_invalid�sz/BaseEventLoopTests.test_set_exc_handler_invalidc
sdd����fdd�}�jjd�tj��j_tj�}�jj|�|�}|j�jitd6tj	d�d6|d	6|j
d
6�|j��jjd�tjd��6}|�|j
jtj	d�d
tttf�WdQX|jst�dS)NcSsdddS)Nr.rrrrrrr��szBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_errorcs#�jj��}�jj�|S)N)rHrpr�)r�)r)r�rr�run_loop�s
z@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopT�	exceptionz!Exception in callback.*zero_error�messager�Zsource_tracebackzasyncio.base_events.loggerzException in callback.*zeror�)rHr�rrIrOr�r�r�rr�Z_source_traceback�
reset_mockr!r�r�r�r�)r)r�Zmock_handlerr�r�r)r)r�r�test_set_exc_handler_custom�s,	

		z.BaseEventLoopTests.test_set_exc_handler_customc
s��fdd�}dd�}tj��j_�jj|�tjd��6}|�|jjtj	d�dt
ttf�WdQXdS)Ncs-dd�}�jj|��jj�dS)NcSsdddS)Nr.rrrrrrr��szTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)rHrpr�)r�)r)rrr��sz@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loopcSstd��dS)Nr�)�AttributeError)rH�contextrrr�handler�sz?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handlerzasyncio.base_events.loggerz$Unhandled error in exception handlerr�)rrIrHrOr�r!r�r�rr�r�r�)r)r�r�r�r)r)r�test_set_exc_handler_broken�s		z.BaseEventLoopTests.test_set_exc_handler_brokencs!d�G�fdd�dtj�}|��|j�j�tj���fdd�}tjd��$}|�|jj	ddd�WdQXd	d
�}d��j
|�tjd��[}|�|jj	tjd�dd�|j
d��|jt�dd
�t�WdQXdS)Ncs:eZdZej�Zej�Z�fdd�ZdS)z@BaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loopcs|�td��dS)Nr�)r;)r)r�)�_contextrr�default_exception_handler�szZBaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loop.default_exception_handlerN)rCrDrErrIrJrOr�r)r�rr�Loop�sr�cs'dd�}�j|��j�dS)NcSsdddS)Nr.rrrrrrr��szXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)rpr�)r�)rHrrr��s
zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loopzasyncio.base_events.loggerz&Exception in default exception handlerr�TcSstd��dS)NZham)r;)rHr�rrr�custom_handler�szJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handlerz9Exception in default exception.*while handling.*in customr�r�)rrGr�rVrXrLrr!r�r�r�rr�rbrir?r�)r)r�r�r�r�r)r�rHr�test_default_exc_handler_broken�s,	
	

	z2BaseEventLoopTests.test_default_exc_handler_brokenc	CsC|jtd��|jjd�WdQX|j|jj��dS)Nz'task factory must be a callable or Noner.)r�r�rH�set_task_factoryr2�get_task_factory)r)rrr�test_set_task_factory_invalid�s
z0BaseEventLoopTests.test_set_task_factory_invalidcsJtj�|j_Gdd�dtj��tjdd��}�fdd�}|j|jj��|jj	|�|j
|jj�|�|jj|��}|jt
|���|jj|�|jj	d�|j|jj��|jj|��}|jt
|tj��|jt
|���|jj|�dS)Nc@seZdZdS)z8BaseEventLoopTests.test_set_task_factory.<locals>.MyTaskN)rCrDrErrrr�MyTask�sr�cSsdS)Nrrrrr�coro�sz6BaseEventLoopTests.test_set_task_factory.<locals>.corocs�|d|�S)NrHr)rHr�)r�rrr^sz:BaseEventLoopTests.test_set_task_factory.<locals>.<lambda>)rrIrHrOrX�Taskr�r2r�r�ri�create_taskrW�
isinstancer\rU)r)r�Zfactoryr�r)r�r�test_set_task_factory�s z(BaseEventLoopTests.test_set_task_factorycCs�djd�}tdd|�\}}}|j|j�d�td|dd	�\}}}|j|j�d�td|dd
�\}}}|j|j�d�tdd|dd
�\}}}|j|j�d�dS)
N�
�import asyncio�loop = asyncio.get_event_loop()�print(loop.get_debug())z-Ez-csFalseZPYTHONASYNCIODEBUGr,�1sTrue)r�r�r�)r�rr1�rstrip)r)�code�sts�stdout�stderrrrr�test_env_var_debugs	z%BaseEventLoopTests.test_env_var_debugcs�Gdd�dtj��tjdd��}G��fdd�dtj�}|��|j��|�}tj|d��}|j|��d|_|j	�dS)	Nc@seZdZdS)z3BaseEventLoopTests.test_create_task.<locals>.MyTaskN)rCrDrErrrrr�+sr�cSsdS)Nrrrrr�test.sz1BaseEventLoopTests.test_create_task.<locals>.testcs%eZdZ��fdd�ZdS)z6BaseEventLoopTests.test_create_task.<locals>.EventLoopcs�|d��S)NrHr)r)r�)r�rHrrr�3szBBaseEventLoopTests.test_create_task.<locals>.EventLoop.create_taskN)rCrDrEr�r)r�rHrr�	EventLoop2srrHF)
rXr�r�rrGrLr�rqZ_log_destroy_pendingrV)r)rrr�r�r)r�rHr�test_create_task*s"	
		z#BaseEventLoopTests.test_create_taskcCs�tjdd��}tj�|j_tj�|j_y|jj|��Wntk
rdYnX|jj	�t
j�|j|jjj
�dS)NcSs
t�dS)N)�KeyboardInterruptrrrr�raise_keyboard_interruptEszXBaseEventLoopTests.test_run_forever_keyboard_interrupt.<locals>.raise_keyboard_interrupt)rXr�rrIrHrOZcall_exception_handlerr\rrVrZ
gc_collectrUr�)r)r	rrr�#test_run_forever_keyboard_interruptAs


z6BaseEventLoopTests.test_run_forever_keyboard_interruptcs�tjdd��}tj��j_y�jj|��Wntk
rRYnX��fdd��d�_y!�jj	���jj
�Wntk
r�YnX�j�j�dS)NcSs
t�dS)N)rrrrrr	XszZBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.raise_keyboard_interruptcs�jj�d�_dS)NT)rHr�r�r)�funcr)rrrcs
zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcF)rXr�rrIrHrOr\rr�rpr[rW)r)r	r)rr)r�%test_run_until_complete_baseexceptionUs
	
z8BaseEventLoopTests.test_run_until_complete_baseexceptioncs�t��d�d�����fdd�}���fdd����fdd��|�j_�f�jjj_xdtdd	�D]S}�jd
|��8�jj�jj	��jj
��j�d�WdQXq�WdS)Nrcs%�|kr!�jj���ndS)N)rHrp)Z
event_list)�do_event�doer�event_sentinelr)rr�proc_eventsuszZBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.proc_eventscs�d7��jj��dS)Nr.)rHrpr)�	callcount�clear_selectorr)rrr
zs
zWBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.do_eventcs �j�f�jjj_dS)N)rfrHrJrKrr)rr)rrrs
z]BaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.clear_selectorr.r	z	Loop %d/2)�objectrHrOrJrKrr�ZsubTestrpr�r[r1)r)r�ir)rrr
rrr)r�2test_single_selecter_event_callback_after_stoppingns	
zEBaseEventLoopTests.test_single_selecter_event_callback_after_stoppingcs^d��fdd�}tj�|j_|jj|�tj|j�|j�d�dS)Nrcs�d7�dS)Nr.rr)�countrr�callback�sz2BaseEventLoopTests.test_run_once.<locals>.callbackr.)rrIrHrOrprZrun_oncer1)r)rr)rr�
test_run_once�sz BaseEventLoopTests.test_run_oncecCsFtj�|j_|jj�|jj�|jjjjd�dS)Nr)	rrIrHrOr�r[rJrKZassert_called_once_with)r)rrr�test_run_forever_pre_stopped�s

z/BaseEventLoopTests.test_run_forever_pre_stoppedN)-rCrDrEr&rTr]rergrkrnrrrurr�r�r�r�r�r�r�r�rr!r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr
rrrrrrrrrF�sP		/L"0rFc@sUeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�ZdS)
�MyProtoNFcCs.d|_d|_|r*tj�|_ndS)N�INITIALr)�state�nbytesrXrYr�)r)�
create_futurerrr�__init__�s		zMyProto.__init__cCsA||_|jdks't|j��d|_|jd�dS)Nr�	CONNECTEDs%GET / HTTP/1.0
Host: example.com

)�	transportrr��write)r)r!rrr�connection_made�s		zMyProto.connection_madecCs7|jdkst|j��|jt|�7_dS)Nr )rr�rr�)r)�datarrr�
data_received�szMyProto.data_receivedcCs+|jdkst|j��d|_dS)Nr �EOF)rr�)r)rrr�eof_received�szMyProto.eof_receivedcCsG|jdkst|j��d|_|jrC|jjd�ndS)Nr r&�CLOSED)z	CONNECTEDzEOF)rr�r�r�)r)r�rrr�connection_lost�s		zMyProto.connection_lost)	rCrDrEr�rr#r%r'r)rrrrr�src@sXeZdZdZdddd�Zdd�Zdd�Zd	d
�Zdd�ZdS)
�MyDatagramProtoNFcCs4d|_d|_|r0tjd|�|_ndS)NrrrH)rrrXrYr�)r)rrHrrrr�s		zMyDatagramProto.__init__cCs4||_|jdks't|j��d|_dS)Nr�INITIALIZED)r!rr�)r)r!rrrr#�s	zMyDatagramProto.connection_madecCs7|jdkst|j��|jt|�7_dS)Nr+)rr�rr�)r)r$�addrrrr�datagram_received�sz!MyDatagramProto.datagram_receivedcCs"|jdkst|j��dS)Nr+)rr�)r)r�rrr�error_received�szMyDatagramProto.error_receivedcCsG|jdkst|j��d|_|jrC|jjd�ndS)Nr+r()rr�r�r�)r)r�rrrr)�s		zMyDatagramProto.connection_lost)	rCrDrEr�rr#r-r.r)rrrrr*�sr*csweZdZdd�Z�fdd�Zedd��Zedd��Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zedd��Z
dd�Zedd��Zedd��Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zed+d,��Zed-d.��Zed/d0��Zd1d2�Zd3d4�Zed5d6��Zej e!j"d7�d8d9��Z#ed:d;��Z$d<d=�Z%ed>d?��Z&d@dA�Z'dBdC�Z(dDdE�Z)edFdG��Z*edHdI��Z+dJdK�Z,e-j.dL�dMdN��Z/dOdP�Z0e-j.dL�dQdR��Z1�S)S�BaseEventLoopWithSelectorTestscCs#tj�|_|j|j�dS)N)rXZnew_event_looprHrL)r)rrrr&�sz$BaseEventLoopWithSelectorTests.setUpcstjj�t�j�dS)N)rr'r(r%r+)r))r*rrr+�s
z'BaseEventLoopWithSelectorTests.tearDownc	s�Gdd�dtj�}tjdd�����fdd�}d�dd	g���fd
d�}||_|�j_�jj|dd
�}�jt��}�jj	|�WdQX�j
t|j�d�dS)Nc@seZdZdS)zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.MyProtoN)rCrDrErrrrr�srcsgDdHdd
gS)Nrzr.�r,�107.6.106.82�P�r1r2)rzr.r0r,r3�r1r2)rzr.r0r,r4r)r��kwrrr�getaddrinfo�s	zZBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfocstj�||�d�j�S)NrH)rXr�rH)r��kwds)r6r)rr�getaddrinfo_task�sz_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_taskr.Zerr1Zerr2cs�d7�t����dS)Nr.)�OSError)r�r5)�errors�idxrr�_socket�s
zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socketzexample.comr2zMultiple exceptions: err1, err2r|)
rX�Protocolr�rrHr6�create_connectionr:r9r\r1�strr�)r)rrr8r<r��cmr)r:r6r;r)r�&test_create_connection_multiple_errors�s	zEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errorscs�tj�}||j_�fdd�}|�j_tjj�jddtj	��Y�jj
tdd�}�jtj	���jj
|�WdQX�j|jj�WdQXdS)NcsDtjd�j�}tjtjdddf}|j|g�|S)NrHrr,�	127.0.0.1r2)rBr2)rXrYrHrrrr�)r�r5r�r,)r)rrr6s
	zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfo�sock_connect�side_effectz	127.0.0.1r2)rrIrrrHr6r!rrX�TimeoutErrorr>rr:r\rWrVr�)r)rr<r6r�r)r)r�test_create_connection_timeout
s
z=BaseEventLoopWithSelectorTests.test_create_connection_timeoutcCs>|jjtdddt��}|jt|jj|�dS)Nzexample.comr2r<)rHr>rrr:r;r\)r)r�rrr�%test_create_connection_host_port_socks	zDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sockcCs/|jjt�}|jt|jj|�dS)N)rHr>rr:r;r\)r)r�rrr�(test_create_connection_no_host_port_sock$szGBaseEventLoopWithSelectorTests.test_create_connection_no_host_port_sockcsktjdd�����fdd�}|�j_�jjtdd�}�jt�jj|�dS)Ncs
gDdHdS)Nr)r�r5rrrr6)szYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfocstj�||�d�j�S)NrH)rXr�rH)r�r7)r6r)rrr8-sz^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_taskzexample.comr2)	rXr�rHr6r>rr:r9r\)r)r8r�r)r6r)r�%test_create_connection_no_getaddrinfo(szDBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfocs�tjdd�����fdd�}|�j_tj��j_t�jj_�jj	t
dd�}�jt�jj|�dS)NcsgDdHdgS)	Nrzr.r0r,�107.6.106.82r2�rJr2)rzr.r0r,rKr)r�r5rrrr66s	zVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfocstj�||�d�j�S)NrH)rXr�rH)r�r7)r6r)rrr8;sz[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_taskzexample.comr2)
rXr�rHr6rrIrCr9rDr>rr:r\)r)r8r�r)r6r)r�"test_create_connection_connect_err5szABaseEventLoopWithSelectorTests.test_create_connection_connect_errc	s�tjdd�����fdd�}|�j_tj��j_t�jj_�jj	t
dddtj�}�j
t���jj|�WdQXdS)Nc_s
d	dgS)Nrzr.r0r,�0.0.0.1r2�0.0.0.2�rMr2)rzr.r0r,rO�rNr2)rzr.r0r,rPr)r�r5rrrr6GszSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfocstj�||�d�j�S)NrH)rXr�rH)r�r7)r6r)rrr8LszXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_taskzexample.comr2�family)rXr�rHr6rrIrCr9rDr>rrrr:r\)r)r8r�r)r6r)r�test_create_connection_multipleFs	z>BaseEventLoopWithSelectorTests.test_create_connection_multiplec	sdd�}||jj_tjdd�����fdd�}|�j_tj��j_	t
d��jj	_�jjt
dd	d
tjdd�}�jt
��}�jj|�WdQX�jt|j�jd
���j|jjjj�dS)NcSs2|ddkr.td�}d|_|�ndS)Nrz0.0.0.1�Err)r9�strerror)r,�errrrr�bind[s	z^BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.bindc_s
d	dgS)Nrzr.r0r,�0.0.0.1r2�0.0.0.2�rWr2)rzr.r0r,rY�rXr2)rzr.r0r,rZr)r�r5rrrr6cszeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfocstj�||�d�j�S)NrH)rXr�rH)r�r7)r6r)rrr8hszjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_taskZErr2zexample.comr2rQ�
local_addr�zMultiple exceptions: )Nr\)rrrVrXr�rHr6rrIrCr9rDr>rrr:r\rWr?r��
startswithrVr�)r)rrVr8r�r@r)r6r)r�1test_create_connection_multiple_errors_local_addrXs		zPBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addrcs�|s|`n�fdd�}||_|jj}tj��j_d�jj_tj��j_	d�jj	_�jj
tjdd�}�jj
|�\}}z<|jjd
�|jjd|jd|jd|j�Wd|j�tj�j�Xtj|_�jj
tjd	d�}�jj
|�\}}z<|jjd�|jjd|jd|jd|j�Wd|j�tj�j�XdS)Ncs�jd�dS)Nz"should not have called getaddrinfo)�fail)r�r5)r)rrr6}szSBaseEventLoopWithSelectorTests._test_create_connection_ip_addr.<locals>.getaddrinfoF�1.2.3.4r2rQ�protor?�::2)r`r2)rbr2)rr6rrrrIrH�
add_reader�
_is_coroutineZ
add_writerr>rXr=r\Zconnectr�rrrrVrr~r
rQ)r)rZallow_inet_ptonr6r<r�r��pr)r)r�_test_create_connection_ip_addrxs8			
	
z>BaseEventLoopWithSelectorTests._test_create_connection_ip_addrcCs|j|d�dS)NT)rf)r)rrrr�test_create_connection_ip_addr�sz=BaseEventLoopWithSelectorTests.test_create_connection_ip_addrcCs|j|d�dS)NF)rf)r)rrrr�#test_create_connection_no_inet_pton�szBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptonc	sztjdd�����fdd�}|�j_�jjtdddtjdd
�}�jt	�jj
|�dS)Nc_s|dkrd	dgSgSdS)Nzexample.comrzr.r0r,�107.6.106.82r2�rir2)rzr.r0r,rj�rir2)rzr.r0r,rkr)�hostr�r5rrrr6�szXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfocstj�||�d�j�S)NrH)rXr�rH)r�r7)r6r)rrr8�sz]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_taskzexample.comr2rQr[�)Nrm)rXr�rHr6r>rrrr:r9r\)r)r8r�r)r6r)r�$test_create_connection_no_local_addr�s		zCBaseEventLoopWithSelectorTests.test_create_connection_no_local_addrc	stj��j_�fdd�}|�jj_tj��j_f�jj_tj��j_Gdd�d���fdd�}|�jj_tj}�jjj	��jj
tddd	d
�}�jj|�\}}|j
��jjj||||ddd
d��jjj	��jj
tddd	d
d
d�}�jj|�\}}|j
��jjj||||ddd
d��jjj	��jj
tddd	d
d
d�}�jj|�\}}|j
��jjj||||ddd
d�dS)NcsAtjd�j�}|jtjtjtjddfg�|S)NrHr,�1.2.3.4r2)ror2)rXrYrHr�rrrZSOL_TCP)r�r7r")r)rr�mock_getaddrinfo�szkBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_getaddrinfoc@s.eZdZdZdd�Zdd�ZdS)zqBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMockNcSs
tj�S)N)rrI)r)�keyrrr�get_extra_info�sz�BaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.get_extra_infocSs|jj�dS)N)�_sockrV)r)rrrrV�szwBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.close)rCrDrErsrrrVrrrr�_SelectorTransportMock�srtcs#|jd���}||_|S)N)r�rs)r<�protocolZ
sslcontextZwaiterr7r!)rtrr�mock_make_ssl_transport�s
		zrBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_make_ssl_transportz
python.orgr2�sslTZserver_sideF�server_hostnamezperl.comr,)rrIrHr6rDrCrrN�ANYr�r>rr\rVr�)r)rprvryr�r!�_r)rtr)r�2test_create_connection_ssl_server_hostname_default�sF		
	
	
zQBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_defaultcCsr|jjtdddd�}|jt|jj|�|jjtdddd�}|jt|jj|�dS)Nz
python.orgr2rxr,)rHr>rr:r;r\)r)r�rrr�4test_create_connection_no_ssl_server_hostname_errors�s		zSBaseEventLoopWithSelectorTests.test_create_connection_no_ssl_server_hostname_errorscCs�|jjtdddd�}|jt|jj|�|jjtdddd�}|jt|jj|�tj�}|jjtddddd|�}|j|j�|jt|jj|�dS)Nr,r2rwTr<)	rHr>rr:r;r\rr�rV)r)r�r<rrr�1test_create_connection_ssl_server_hostname_errorsszPBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_errorscs�t��tj�fdd�����fdd�}|�j_�jjtdd�}�jt�jj	|��j
��dS)Nc?s|d�gDdHdS)Nrr)r�r5)rlrrr6s
zQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfocstj�||�d�j�S)NrH)rXr�rH)r�r7)r6r)rrr8szVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_taskr,r)rrXr�rHr6�
create_serverrr:r9r\r2)r)r8r�r)r6rlr)r�test_create_server_empty_hosts	z<BaseEventLoopWithSelectorTests.test_create_server_empty_hostcCs>|jjtdddt��}|jt|jj|�dS)Nz0.0.0.0rr<)rHr~rrr:r;r\)r)r�rrr�!test_create_server_host_port_socks	z@BaseEventLoopWithSelectorTests.test_create_server_host_port_sockcCs/|jjt�}|jt|jj|�dS)N)rHr~rr:r;r\)r)r�rrr�$test_create_server_no_host_port_sock#szCBaseEventLoopWithSelectorTests.test_create_server_no_host_port_sockcCsTtj�}|j_g|_|jjtdd�}|jt|jj	|�dS)Nz0.0.0.0r)
rrIrHr6rr~rr:r9r\)r)r6r"rrr�!test_create_server_no_getaddrinfo's	z@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfocCs_tj|_|`tj�|j_|jjtdddd�}|j	t
|jj|�dS)Nz0.0.0.0r�
reuse_portT)rr6�SO_REUSEPORTrrIrrHr~rr:r;r\)r)rr"rrr� test_create_server_nosoreuseport.s	z?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseportcCs�Gdd�dt�}d
g|j_d	|j_tj�}|j_||j_|j	j
td
d�}|jt|j	j
|�|j|jj�dS)Nc@seZdZdZdS)zHBaseEventLoopWithSelectorTests.test_create_server_cant_bind.<locals>.Errr�N)rCrDrErTrrrrrS<srSrzr.r0r,�	127.0.0.1�t'Fz0.0.0.0r�r�r�)rzr.r0r,r�)r9r6rrdrrIrrVrDrHr~rr:r\rWrVr�)r)rrS�m_sockr�rrr�test_create_server_cant_bind9sz;BaseEventLoopWithSelectorTests.test_create_server_cant_bindcCsMg|j_d|j_|jjtdd�}|jt|jj|�dS)NFr[�	localhostr)r�r)	r6rrdrH�create_datagram_endpointr*r:r9r\)r)rr�rrr�)test_create_datagram_endpoint_no_addrinfoIs	zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfocCsf|jjtdd�}|jt|jj|�|jjtdd�}|jt|jj|�dS)Nr[r�r.rzr	)z	localhostr.rzr	)rHr�r*r:r�r\)r)r�rrr�(test_create_datagram_endpoint_addr_errorSs		zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errorcCsYtj�|j_t|jj_|jjtjdd�}|j	t|jj
|�dS)N�remote_addr�	127.0.0.1r)r�r)rrIrHrCr9rDr�rX�DatagramProtocolr:r\)r)r�rrr�)test_create_datagram_endpoint_connect_err]s	zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_connect_errcCs�tj|_t|j_|jjtjdtj�}|j	t|jj
|�|jjtjdd�}|j	t|jj
|�dS)NrQr[�	127.0.0.1r)r�r)rr6r9rDrHr�rXr�rr:r\)r)rr�rrr�(test_create_datagram_endpoint_socket_errfs		zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_socket_errzIPv6 not supported or enabledcCs>|jjtjdddd�}|jt|jj|�dS)Nr��	127.0.0.1rr[�::1)r�r)r�r)rHr�rXr�r:r;r\)r)r�rrr�0test_create_datagram_endpoint_no_matching_familyus
		zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_matching_familycCsft|jjj_|jjtjdtj	�}|j
t|jj|�|j|jjj
j�dS)NrQ)r9rrZsetblockingrDrHr�rXr�rr:r\rWrVr�)r)rr�rrr�(test_create_datagram_endpoint_setblk_err}s	zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_setblk_errcCs2|jjtj�}|jt|jj|�dS)N)rHr�rXr�r:r;r\)r)r�rrr�-test_create_datagram_endpoint_noaddr_nofamily�s	zLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_noaddr_nofamilycCs�Gdd�dt�}tj|_tj�}|j_||j_|jj	t
dddtj�}|j||jj
|�|j|jj�dS)Nc@seZdZdS)zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bind.<locals>.ErrN)rCrDrErrrrrS�srSr[�	127.0.0.1rrQ)r�r)r9rr6rrIrrVrDrHr�r*rr:r\rWrVr�)r)rrSr�r�rrr�'test_create_datagram_endpoint_cant_bind�s	zFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bindcs�tjtjtj�}|jd��jj�fdd�d|�}�jj|�\}}|j��jj|j��j	d|j
�dS)N�	127.0.0.1rcstddd�j�S)NrTrH)r*rHr)r)rrr^�szSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>r<r()r�r)rrrrVrHr�r\rVr�r1r)r)r<r�r!rur)r)r�"test_create_datagram_endpoint_sock�s
		
zABaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockcCs�|jjtdddt��}|jt|jj|�|jjtdddt��}|jt|jj|�|jjtdddt��}|jt|jj|�|jjtdddt��}|jt|jj|�|jjtd	ddt��}|jt|jj|�|jjtd
ddt��}|jt|jj|�|jjtdddt��}|jt|jj|�|jjtd
ddt��}|jt|jj|�dS)Nr[�	127.0.0.1rr<r�rQr.ra�flags�
reuse_addressTr��allow_broadcast)r�r)r�r)rHr�r*rr:r;r\)r)r�rrr�+test_create_datagram_endpoint_sock_sockopts�s0								zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockoptsc
s-�jj�fdd�dd�}�jj|�\}}|jd�}tjdkoftjdk}tt	d	�}|r��j
|jt	jt	j
��n�j|jt	jt	j
��|r��j|jt	jt	j��n�j|jt	jt	j��|j��jj|j��jd
|j��jj�fdd�dddd
d|dd
�}�jj|�\}}|jd�}�j
|jt	jt	j
��|r��j
|jt	jt	j��n�j
|jt	jt	j��|j��jj|j��jd
|j�dS)Ncstddd�j�S)NrTrH)r*rHr)r)rrr^�szWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>r[�	127.0.0.1rr�posix�cygwinr�r(cstddd�j�S)NrTrH)r*rHr)r)rrr^�sr�Tr�r�)r�r)r�r)rHr�r\rr�osrr��platformrrrWZ
getsockoptrrrUr�ZSO_BROADCASTrVr�r1r)r)r�r!rur<Zreuse_address_default_on�reuseport_supportedr)r)r�&test_create_datagram_endpoint_sockopts�sZ		
		
zEBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockoptscse|`tj�|j_�jj�fdd�dd
dddd	�}�jt�jj	|�dS)Ncstd�j�S)NrH)r*rHr)r)rrr^	sz\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>r[�	127.0.0.1rr�Fr�T)r�r)
r�rrIrrrHr�r:r;r\)r)rr�r)r)r�+test_create_datagram_endpoint_nosoreuseports		zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseportc
s�fdd�}||_tj�|jj_}tj��j_d�jj_t	td�}�jj
�fdd�ddd
dd|�}�jj|�\}}z9|jd�|jjd|j
d
|jd|j�Wd|j�tj�j�XdS)Ncs�jd�dS)Nz"should not have called getaddrinfo)r_)r�r5)r)rrr6szYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfoFr�cstd�j�S)NrH)r*rHr)r)rrr^szVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>r[�1.2.3.4rr�r�rQrar?)r�r)r�r)r6rrIrrrVrHrcrdrr�r\r�rrrrVrr~)r)rr6rVr�r�r�rer)r)r�%test_create_datagram_endpoint_ip_addrs&			
	
zDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addrcCsEtj�}t�|j_|jjt|�|j|j	j
�dS)N)rrI�BlockingIOError�acceptrDrH�_accept_connectionrrUrVr�)r)r<rrr�test_accept_connection_retry+sz;BaseEventLoopWithSelectorTests.test_accept_connection_retryzasyncio.base_events.loggercCs�tj�}d|j_ttjd�|j_tj�|j	_
tj�|j	_|j	jt
|�|j|jj�|j|jj�|j	j
jd�|j	jjtjtjt
|dd�dS)Nr�zToo many open files)rrI�filenorr9�errnoZEMFILEr�rDrHZ
remove_readerrsr�rrWr�r�rUrVr�rZACCEPT_RETRY_DELAYry)r)Zm_logr<rrr� test_accept_connection_exception2sz?BaseEventLoopWithSelectorTests.test_accept_connection_exceptionc#Cs#tjdd��}|}|�}|j|j�x�||fD]�}|jt��|jj|�WdQX|jt��|jj|�WdQX|jt��|jj	d|�WdQX|jt��%|jj
|jj�d|�WdQX|jt��|jjd|�WdQXqAWdS)NcSsdS)Nrrrrr�simple_coroutineDszLBaseEventLoopWithSelectorTests.test_call_coroutine.<locals>.simple_coroutiner�)
rXr�r�rVr:r�rHrpr�rsr�r�rl)r)r�Z	coro_funcZcoro_objrrrr�test_call_coroutineCs	&z2BaseEventLoopWithSelectorTests.test_call_coroutinecCsdd�}tjdd��}tj|j�|jjd�d|j_|jj||j�|jj�|jj	d^}}|j
|t|�d�tj||j�d	|j�|jj�|jj	d^}}|j
|t|�d
�dS)NcSs|j�dS)N)r�)rHrrr�stop_loop_cbYszLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cbcssfDdH|j�dS)N)r�)rHrrr�stop_loop_coro\s	zNBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_coroTgrz4^Executing <Handle.*stop_loop_cb.*> took .* seconds$rHz4^Executing <Task.*stop_loop_coro.*> took .* seconds$)
rXr�rLrHr�Zslow_callback_durationrpr[ZwarningrmZassertRegex�tupler�)r)r�r�r�Zfmtr�rrr�test_log_slow_callbacksWs

z6BaseEventLoopWithSelectorTests.test_log_slow_callbacks)2rCrDrEr&r+r#rArFrGrHrIrLrRr^rfrgrhrnr{r|r}rr�r�r�r�r�r�r�r�r��unittestZ
skipUnlessrZIPV6_ENABLEDr�r�r�r�r�r�r�r�r�r�rr!r�r�r�rr)r*rr/�sP!
 '=	

	!!;
r/�__main__)'�__doc__r�r�r�r�rr�r�r�r�rrXrrrrr�ImportErrorrZtest.support.script_helperrZtest.script_helperZasyncio.test_supportryr��version_infor�r r#ZTestCaser$rFr=rr�r*r/rC�mainrrrr�<module>sR


	`������