Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_asyncio/__pycache__/test_base_events.cpython-35.pyc



��Yf���@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$Gdd�de	j�Z%e&dkr;e	j'�dS)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_	d|j
_|S)N�spec�AF_INET�AF_INET6�	AF_UNSPEC�IPPROTO_TCP�IPPROTO_UDP�SOCK_STREAM�
SOCK_DGRAM�
SOL_SOCKET�SO_REUSEADDR�	inet_ptonF)
rr
rrrrrrrr)rZ	MagicMock�socket�hasattr�setattr�getattr�delattrrZmock_nonblocking_socket�return_value�getaddrinfo�
_is_coroutine)�m_socket�name�r �G/opt/alt/python35/lib64/python3.5/test/test_asyncio/test_base_events.py�mock_socket_module#s
r"cCstjddt�|�S)Nzasyncio.base_events.socketZnew_callable)r�patchr")�fr r r!�patch_socket5sr%c@s:eZdZdd�Zdd�Zedd��ZdS)�BaseEventTestscCs�tj}tj}tj}tj}tj}tj}tj}|j|||dd	ft	j
dd|||��|j|||dd
ft	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|||ddft	j
dd|||��|j|||ddft	j
dd|||��|jt	j
dd|||��|jt	j
dd|||��ttd�r�|jdt	j
dd||tj
B|��dS)N��1.2.3.4�s1.2.3.4r�::3z::3%lo0�
SOCK_NONBLOCK)r(r))r(r))r(r))r(r))r(r))r(r))r*r))r*r))rrrr
rrrr�assertEqualr�_ipaddr_info�assertIsNonerr+)�selfZUNSPEC�INETZINET6�STREAMZDGRAM�TCPZUDPr r r!�test_ipaddr_info<sX							zBaseEventTests.test_ipaddr_infocCs#tj}tj}tj}|j|||ddftjdd|||��|j|||dd	ftjdd|||��|j|||dd
ftjdd|||��|j|||ddftjdd|||��|j|||ddftjdd|||��dS)
Nr'�1.2.3.4r�r)�1�1)r4r)r4r)r4r)r4r))r4r))rrrrr,rr-)r/r0r1r2r r r!�test_port_parameter_types~s$			z(BaseEventTests.test_port_parameter_typescCs5|`|jtjddtjtjtj��dS)Nz1.2.3.4r))rr.rr-rrrr)r/rr r r!�test_ipaddr_info_no_inet_pton�s
z,BaseEventTests.test_ipaddr_info_no_inet_ptonN)�__name__�
__module__�__qualname__r3r8r%r9r r r r!r&:sBr&cs�eZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zejd#�d$d%��Zd&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+�S)P�BaseEventLoopTestscsTt�j�tj�|_tj�|j_f|jjj_	|j
|j�dS)N)�super�setUpr�
BaseEventLoop�loopr�Mock�	_selector�selectr�set_event_loop)r/)�	__class__r r!r?�s

zBaseEventLoopTests.setUpc	Cstj�}|jt|jj||�|jt|jj||||�|jt|jj||�|jt|jjg�|jt|jj	�|jt|jj
||�|jt|jj||�|jj|||||||�}|jt��|j
d�WdQRXdS)N)rrB�assertRaises�NotImplementedErrorrAZ_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�genr r r!�test_not_implemented�s.$z'BaseEventLoopTests.test_not_implementedcCs�|j|jj��|jj�|j|jj��|jj�|jj�tjd|j�}|jt|jj	�|jt|jj
|�dS)NrA)�assertFalserAZ	is_closed�close�
assertTrue�asyncio�FuturerG�RuntimeError�run_forever�run_until_complete)r/r$r r r!�
test_close�s


zBaseEventLoopTests.test_closecCs[tjdd�f|j�}|jj|�|j|jj�|j||jj�dS)NcSsdS)NFr r r r r!�<lambda>�sz>BaseEventLoopTests.test__add_callback_handle.<locals>.<lambda>)rS�HandlerA�
_add_callbackrP�
_scheduled�assertIn�_ready)r/�hr r r!�test__add_callback_handle�sz,BaseEventLoopTests.test__add_callback_handlecCsbtjdd�f|j�}|j�|jj|�|j|jj�|j|jj�dS)NcSsdS)NFr r r r r!rY�szHBaseEventLoopTests.test__add_callback_cancelled_handle.<locals>.<lambda>)rSrZrA�cancelr[rPr\r^)r/r_r r r!�#test__add_callback_cancelled_handle�s

z6BaseEventLoopTests.test__add_callback_cancelled_handlecCs6tj�}|jj|�|j||jj�dS)N)rrBrA�set_default_executor�assertIsZ_default_executor)r/�executorr r r!�test_set_default_executor�sz,BaseEventLoopTests.test_set_default_executorcCs^tj�}tj�|j_|jj|�|jdtj|df|jjjd�dS)Nr)rrBrA�run_in_executorZgetnameinfor,r�	call_args)r/Zsockaddrr r r!�test_getnameinfo�sz#BaseEventLoopTests.test_getnameinfocCs^dd�}|jj|�}|j|j|�|j|tj�|j||jj�dS)NcSsdS)Nr r r r r!�cb�sz-BaseEventLoopTests.test_call_soon.<locals>.cb)	rA�	call_soonr,Z	_callback�assertIsInstancerSrZr]r^)r/rjr_r r r!�test_call_soon�s
z!BaseEventLoopTests.test_call_soonc	Cs>|jjd�|jtd��|jjd�WdQRXdS)NTza callable objectr))rA�	set_debug�assertRaisesRegex�	TypeErrorrk)r/r r r!�test_call_soon_non_callable�sz.BaseEventLoopTests.test_call_soon_non_callablecCsddd�}|jjd|�}|j|tj�|j||jj�|j||jj�dS)NcSsdS)Nr r r r r!rj�sz.BaseEventLoopTests.test_call_later.<locals>.cbg$@)	rA�
call_laterrlrS�TimerHandler]r\ZassertNotInr^)r/rjr_r r r!�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)�callsr r!rjsz>BaseEventLoopTests.test_call_later_negative_delays.<locals>.cbr)�a��b������)rrBrArJrrr�run_brieflyr,)r/rjr )rwr!�test_call_later_negative_delayssz2BaseEventLoopTests.test_call_later_negative_delayscs��fdd�}tj��j_d}�jj�|}�jj||��jj�}�jj��jj�|}�j||d|��j|d|�dS)Ncs�jj�dS)N)rA�stopr )r/r r!rjsz4BaseEventLoopTests.test_time_and_call_at.<locals>.cbg�������?g�������?g�������?)	rrBrArJ�time�call_atrVZassertGreaterEqual�assertLessEqual)r/rjZdelayZwhenZt0Zdtr )r/r!�test_time_and_call_ats
z(BaseEventLoopTests.test_time_and_call_atcCs�dd�}|j|�|r�d}|jt|��|j|�WdQRX|jt|��|jd|�WdQRX|jt|��|j|j�d|�WdQRXn7|j|�|jd|�|j|j�d|�dS)NcSsdS)Nr r r r r!rj$sz+BaseEventLoopTests.check_thread.<locals>.cbzMNon-thread-safe operation invoked on an event loop other than the current one�<)rnrorUrkrrr�r�)r/rA�debugrj�msgr r r!�check_thread#s
$
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)�waitrr@rSrEr�rQ�	Exception�call_soon_threadsafeZ
set_exception�
set_result)rA�eventr��create_loop�futZloop2�exc)r/r r!�check_in_thread7s


&z=BaseEventLoopTests.test_check_thread.<locals>.check_in_threadFcs�tj�}tjd|�}|j|j�|||||f}tjd�d|�}|j�|j|�|j	�dS)NrA�target�args)
�	threadingZEventrSrTrk�setZThread�startrW�join)rAr�r�r�r�r�Zthread)r�r r!�test_threadKs

z9BaseEventLoopTests.test_check_thread.<locals>.test_threadTr�)rrBrArJrK)r/r�r )r�r/r!�test_check_thread6s
z$BaseEventLoopTests.test_check_threadcCs�dd�}tjd|j�}tj�}||j_|jj|�|jjd|�}|j	||�tj�}||j_|jj||�}|j	||�|j
|jj�|j�dS)NcSsdS)Nr r r r r!rjfsz>BaseEventLoopTests.test_run_once_in_executor_plain.<locals>.cbrA)
rSrTrArrBZsubmitrrcrgrdrR�calledra)r/rjr$re�resr r r!�test_run_once_in_executor_plaines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)NTr r r r r!rYzsz3BaseEventLoopTests.test__run_once.<locals>.<lambda>g$@cSsdS)NTr r r r r!rY|srg#@g%@)rSrsr��	monotonicrArarrBrJr\ru�	_run_oncerCrDrhrRr,r�)r/Zh1Zh2�tr r r!�test__run_onceys

&z!BaseEventLoopTests.test__run_oncecCsP|jjd�|j|jj��|jjd�|j|jj��dS)NTF)rArnrRZ	get_debugrP)r/r r r!�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)�timeoutr r r!�slow_select�s
z>BaseEventLoopTests.test__run_once_logging.<locals>.slow_selectTrcSstjd�gS)Ng����MbP?)r�r�)r�r r r!�fast_select�s
z>BaseEventLoopTests.test__run_once_logging.<locals>.fast_select)rArnrCrDrrBrJr�r,�logging�INFO�logrh�DEBUG)r/�m_loggerr�r�r r r!�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)NTr r r r r!rY�szOBaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb.<locals>.<lambda>)rk)rA)�handle�	processedr r!rj�sz=BaseEventLoopTests.test__run_once_schedule_handle.<locals>.cbr))rSrsr�r�rArrBrJr\rur�rRr,�listr^)r/rjr_r )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)Nr r r r r!rj�szEBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.cbr)i�ryi�dcSsg|]}|j�qSr )Z
_cancelled)�.0�xr r r!�
<listcomp>s	zMBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.<listcomp>)rrBrArJrRrZ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONrr�rangerar�Z_MIN_SCHEDULED_TIMER_HANDLESr,Z_timer_cancelled_countr��lenr\�int�mathZceil�max�all)r/rjZnot_cancelled_countZcancelled_countr�r_Zadd_cancel_countZadd_not_cancel_countr r r!�&test__run_once_cancelled_event_cleanup�sN 




		



z9BaseEventLoopTests.test__run_once_cancelled_event_cleanupcCs|jt|jjd�dS)NZblah)rGrprArW)r/r r r!�"test_run_until_complete_type_error	s	z5BaseEventLoopTests.test_run_until_complete_type_errorcCsKtjd|j�}|j�}|j|j�|jt|j|�dS)NrA)	rSrTrAZ
new_test_loop�
addCleanuprQrG�
ValueErrorrW)r/�taskZ
other_loopr r r!�test_run_until_complete_loop
s
	z/BaseEventLoopTests.test_run_until_complete_loopcCstjddg}|jt|jj|jjtj�|jt|jj|jjtj|�|jt|jj|jjtjtjd�|jt|jj|jjtj|dd�|jt|jj|jjtj|dd�|jt|jj|jjtj|dd�dS)	Nz-c�pass�{�universal_newlinesT�shell�bufsizei)	�sys�
executablerGrprArWZsubprocess_execrS�SubprocessProtocol)r/r�r r r!�!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)	rGrprArWZsubprocess_shellrSr�r�r�)r/r r r!�"test_subprocess_shell_invalid_args1s	
				z5BaseEventLoopTests.test_subprocess_shell_invalid_argscsCtj��j_dd�}tjd��}}tjd�j�}�jj||�|j�fdd���jj	�|j
jtj
d�dtttf�WdQRXtjd���}tjd�j�}�jjd	||�|j�fd
d���jj	�|j
jtj
d�dtttf�WdQRXdS)NcSs|jd�dddS)NTr)r)r�)r�r r r!�
zero_errorHs
zHBaseEventLoopTests.test_default_exc_handler_callback.<locals>.zero_errorzasyncio.base_events.loggerrAcs
�jj�S)N)rAr)r�)r/r r!rYPszFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>zException in callback.*zero�exc_infog{�G�z�?cs
�jj�S)N)rAr)r�)r/r r!rYZs)rrBrArJr#rSrTrk�add_done_callbackrV�error�assert_called_withr�MockPattern�ZeroDivisionError�MOCK_ANYrr)r/r�r�r�r )r/r!�!test_default_exc_handler_callbackEs$
	
	z4BaseEventLoopTests.test_default_exc_handler_callbackc
s�tj��j_tj�fdd��}tjd���}tj|�d�j�}|j�fdd���jj	�d}t
j�tr�|j
jtjd�dtttf�n|j
jtjd	�dd
�WdQRXdS)Nc3s'tjdd�j�EdHdddS)Ng{�G�z�?rAr)r)rSr�rAr )r/r r!�zero_error_corocszIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_corozasyncio.base_events.loggerrAcs
�jj�S)N)rAr)r�)r/r r!rYkszBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>z.*exception was never retrievedr�z(.*exception was never retrieved.*ZeroDivF)rrBrArJrS�	coroutiner#�
ensure_futurer�rVr�
gc_collect�PY34r�r�rr�r�r�)r/r�r�r�r )r/r!�test_default_exc_handler_coro`s 

			z0BaseEventLoopTests.test_default_exc_handler_coroc	Cs.|jtd��|jjd�WdQRXdS)NzA callable object or None�spam)rorprA�set_exception_handler)r/r r r!�test_set_exc_handler_invalid|sz/BaseEventLoopTests.test_set_exc_handler_invalidc
sDdd����fdd�}�jjd�tj��j_�j�jj��tj�}�jj|��j�jj�|�|�}|j	�jdt
dtjd�d	|d
|j
i�|j��jjd�tjd��6}|�|jj	tjd�d
tt
t
f�WdQRX|js@t�dS)NcSsdddS)Nr)rr r r r r!r��szBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_errorcs#�jj��}�jj�|S)N)rArkr�)r�)r/r�r r!�run_loop�s
z@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopT�	exception�messagez!Exception in callback.*zero_errorr�Zsource_tracebackzasyncio.base_events.loggerzException in callback.*zeror�)rArnrrBrJr.Zget_exception_handlerr�rdr�r�rr�Z_source_traceback�
reset_mockr#r�r�r��AssertionError)r/r�Zmock_handlerr�r�r )r/r�r!�test_set_exc_handler_custom�s0		
		z.BaseEventLoopTests.test_set_exc_handler_customc
s��fdd�}dd�}tj��j_�jj|�tjd��6}|�|jjtj	d�dt
ttf�WdQRXdS)Ncs-dd�}�jj|��jj�dS)NcSsdddS)Nr)rr r r r r!r��szTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)rArkr�)r�)r/r r!r��sz@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loopcSstd��dS)Nr�)�AttributeError)rA�contextr r r!�handler�sz?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handlerzasyncio.base_events.loggerz$Unhandled error in exception handlerr�)rrBrArJr�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�WdQRXd	d
�}d��j
|�tjd��[}|�|jj	tjd�dd�|j
d��|jt�dd
�t�WdQRXdS)Ncs:eZdZej�Zej�Z�fdd�ZdS)z@BaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loopcs|�td��dS)Nr�)r�)r/r�)�_contextr r!�default_exception_handler�szZBaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loop.default_exception_handlerN)r:r;r<rrBrCrJr�r )r�r r!�Loop�sr�cs'dd�}�j|��j�dS)NcSsdddS)Nr)rr r r r r!r��szXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)rkr�)r�)rAr r!r��s
zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loopzasyncio.base_events.loggerz&Exception in default exception handlerr�TcSstd��dS)NZham)r�)rAr�r r r!�custom_handler�szJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handlerz9Exception in default exception.*while handling.*in customr�r�)rr@r�rQrSrErr#r�r�r�rr�r]rd�typer�)r/r�r�r�r�r )r�rAr!�test_default_exc_handler_broken�s,	
	
	z2BaseEventLoopTests.test_default_exc_handler_brokenc	CsD|jtd��|jjd�WdQRX|j|jj��dS)Nz'task factory must be a callable or Noner))rorprA�set_task_factoryr.�get_task_factory)r/r r r!�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)r:r;r<r r r r!�MyTask�sr�cSsdS)Nr r r r r!�coro�sz6BaseEventLoopTests.test_set_task_factory.<locals>.corocs�|d|�S)NrAr )rAr�)r�r r!rY�sz:BaseEventLoopTests.test_set_task_factory.<locals>.<lambda>)rrBrArJrS�Taskr�r.r�r�rd�create_taskrR�
isinstancerWrP)r/r��factoryr�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'r6sTrue)r�r�r�)r�rr,�rstrip)r/�code�sts�stdout�stderrr r r!�test_env_var_debug
s	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)r:r;r<r r r r!r�%sr�cSsdS)Nr r r r r!�test(sz1BaseEventLoopTests.test_create_task.<locals>.testcs%eZdZ��fdd�ZdS)z6BaseEventLoopTests.test_create_task.<locals>.EventLoopcs�|d��S)NrAr )r/r�)r�rAr r!r�-szBBaseEventLoopTests.test_create_task.<locals>.EventLoop.create_taskN)r:r;r<r�r )r�rAr r!�	EventLoop,srrAF)
rSr�r�rr@rEr�rlZ_log_destroy_pendingrQ)r/r�rr�r�r )r�rAr!�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)�KeyboardInterruptr r r r!�raise_keyboard_interrupt?szXBaseEventLoopTests.test_run_forever_keyboard_interrupt.<locals>.raise_keyboard_interrupt)rSr�rrBrArJZcall_exception_handlerrWrrQrr�rPr�)r/rr r r!�#test_run_forever_keyboard_interrupt;s


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)rr r r r!rRszZBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.raise_keyboard_interruptcs�jj�d�_dS)NT)rArr�r )�funcr/r r!r]s
zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcF)rSr�rrBrArJrWrr�rkrVrR)r/rr )rr/r!�%test_run_until_complete_baseexceptionOs
	
z8BaseEventLoopTests.test_run_until_complete_baseexceptioncs�t��d�d�����fdd�}���fdd����fdd��|�j_�f�jjj_xetdd	�D]T}�jd
|��8�jj�jj	��jj
��j�d�WdQRXq�WdS)Nrcs"�|kr�jj���dS)N)rArk)Z
event_list)�do_event�doer�event_sentinelr/r r!�proc_eventsoszZBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.proc_eventscs�d7��jj��dS)Nr))rArkr )�	callcount�clear_selectorr/r r!rts
zWBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.do_eventcs �j�f�jjj_dS)N)rarArCrDrr )rr/r r!rys
z]BaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.clear_selectorr)r	z	Loop %d/2)�objectrArJrCrDrr�ZsubTestrkrrVr,)r/r
�ir )rrrrr	r/r!�2test_single_selecter_event_callback_after_stoppinghs	
zEBaseEventLoopTests.test_single_selecter_event_callback_after_stoppingcs^d��fdd�}tj�|j_|jj|�tj|j�|j�d�dS)Nrcs�d7�dS)Nr)r r )�countr r!�callback�sz2BaseEventLoopTests.test_run_once.<locals>.callbackr))rrBrArJrkrZrun_oncer,)r/rr )rr!�
test_run_once�sz BaseEventLoopTests.test_run_oncecCsFtj�|j_|jj�|jj�|jjjjd�dS)Nr)	rrBrArJrrVrCrDZassert_called_once_with)r/r r r!�test_run_forever_pre_stopped�s

z/BaseEventLoopTests.test_run_forever_pre_stopped),r:r;r<r?rOrXr`rbrfrirmrqrtr~r�r�r�r�r�r�rr#r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr r )rFr!r=�sN		/L$0r=c@sUeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�ZdS)
�MyProtoNFcCs+d|_d|_|r'tj�|_dS)N�INITIALr)�state�nbytesrSrT�done)r/�
create_futurer r r!�__init__�s		zMyProto.__init__cCsA||_|jdks't|j��d|_|jd�dS)Nr�	CONNECTEDs%GET / HTTP/1.0
Host: example.com

)�	transportrr��write)r/rr r r!�connection_made�s		zMyProto.connection_madecCs7|jdkst|j��|jt|�7_dS)Nr)rr�rr�)r/�datar r r!�
data_received�szMyProto.data_receivedcCs+|jdkst|j��d|_dS)Nr�EOF)rr�)r/r r r!�eof_received�szMyProto.eof_receivedcCsD|jdkst|j��d|_|jr@|jjd�dS)Nrr!�CLOSED)rr!)rr�rr�)r/r�r r r!�connection_lost�s		zMyProto.connection_lost)	r:r;r<rrrr r"r$r r r r!r�src@sXeZdZdZdddd�Zdd�Zdd�Zd	d
�Zdd�ZdS)
�MyDatagramProtoNFcCs1d|_d|_|r-tjd|�|_dS)NrrrA)rrrSrTr)r/rrAr r r!r�s		zMyDatagramProto.__init__cCs4||_|jdks't|j��d|_dS)Nr�INITIALIZED)rrr�)r/rr r r!r�s	zMyDatagramProto.connection_madecCs7|jdkst|j��|jt|�7_dS)Nr&)rr�rr�)r/r�addrr r r!�datagram_received�sz!MyDatagramProto.datagram_receivedcCs"|jdkst|j��dS)Nr&)rr�)r/r�r r r!�error_received�szMyDatagramProto.error_receivedcCsD|jdkst|j��d|_|jr@|jjd�dS)Nr&r#)rr�rr�)r/r�r r r!r$�s		zMyDatagramProto.connection_lost)	r:r;r<rrrr(r)r$r r r r!r%�sr%cs�eZdZ�fdd�Zedd��Zedd��Zdd�Zd	d
�Zdd�Z	e
jee
d
�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zdd�Zedd ��Zed!d"��Zed#d$��Zd%d&�Zed'd(��Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!ed7d8��Z"ed9d:��Z#ed;d<��Z$ed=d>��Z%d?d@�Z&dAdB�Z'edCdD��Z(e
je)j*dE�dFdG��Z+edHdI��Z,dJdK�Z-edLdM��Z.dNdO�Z/dPdQ�Z0dRdS�Z1edTdU��Z2edVdW��Z3dXdY�Z4e5j6dZ�d[d\��Z7d]d^�Z8e5j6dZ�d_d`��Z9�S)a�BaseEventLoopWithSelectorTestscs0t�j�tj�|_|j|j�dS)N)r>r?rS�new_event_looprArE)r/)rFr r!r?�s
z$BaseEventLoopWithSelectorTests.setUpc
s�Gdd�dtj�}tjdd�����fdd�}d�dd	g���fd
d�}||_|�j_�jj|dd
�}�jt��}�jj	|�WdQRX�j
t|j�d�dS)Nc@seZdZdS)zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.MyProtoN)r:r;r<r r r r!r�srcsgEdHdd
gS)Nryr)�r'�107.6.106.82�P�r-r.)ryr)r,r'r/�r-r.)ryr)r,r'r0r )r��kwr r r!r�s	zZBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfocstj�||�d�j�S)NrA)rSr�rA)r��kwds)rr/r r!�getaddrinfo_task�sz_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_taskr)Zerr1Zerr2cs�d7�t����dS)Nr))�OSError)r�r1)�errors�idxr r!�_socket�s
zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socketzexample.comr.zMultiple exceptions: err1, err2r{)
rS�Protocolr�rrAr�create_connectionrGr4rWr,�strr�)r/rrr3r7r��cmr )r5rr6r/r!�&test_create_connection_multiple_errors�s	zEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errorscs�tj�}||j_�fdd�}|�j_tjj�jddtj	��Z�jj
tdd�}�jtj	���jj
|�WdQRX�j|jj�WdQRXdS)NcsDtjd�j�}tjtjdddf}|j|g�|S)NrArr'�	127.0.0.1r.)r=r.)rSrTrArrrr�)r�r1r�r')r/r r!rs
	zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfo�sock_connect�side_effectz	127.0.0.1r.)rrBrrrArr#r
rS�TimeoutErrorr9rrGrWrRrQr�)r/r�sockrr�r )r/r!�test_create_connection_timeouts
z=BaseEventLoopWithSelectorTests.test_create_connection_timeoutcCs>|jjtdddt��}|jt|jj|�dS)Nzexample.comr.rA)rAr9rr
rGr�rW)r/r�r r r!�%test_create_connection_host_port_socks	zDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sockcCsltjtjtj�}|�G|jjtd|�}|jtd��|jj|�WdQRXWdQRXdS)NrAzA Stream Socket was expected)	rrrrAr9rror�rW)r/rAr�r r r!�!test_create_connection_wrong_socks	
z@BaseEventLoopWithSelectorTests.test_create_connection_wrong_sockcCsltjtjtj�}|�G|jjtd|�}|jtd��|jj|�WdQRXWdQRXdS)NrAzA Stream Socket was expected)	rrrrA�
create_serverrror�rW)r/rAr�r r r!�test_create_server_wrong_sock"s	
z<BaseEventLoopWithSelectorTests.test_create_server_wrong_sockr+z$no socket.SOCK_NONBLOCK (linux only)cCs�tjtjtjtjB�}|�U|jjdd�d|�}|jj|�}|j�|jj|j��WdQRXdS)NcSsdS)Nr r r r r!rY0szRBaseEventLoopWithSelectorTests.test_create_server_stream_bittype.<locals>.<lambda>rA)	rrrr+rArErWrQZwait_closed)r/rAr�Zsrvr r r!�!test_create_server_stream_bittype*s
z@BaseEventLoopWithSelectorTests.test_create_server_stream_bittypecCsftjtj�}|�G|jjtd|�}|jtd��|jj|�WdQRXWdQRXdS)NrAzA UDP Socket was expected)rrrA�create_datagram_endpointrror�rW)r/rAr�r r r!�(test_create_datagram_endpoint_wrong_sock5s	
zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_wrong_sockcCs/|jjt�}|jt|jj|�dS)N)rAr9rrGr�rW)r/r�r r r!�(test_create_connection_no_host_port_sock=szGBaseEventLoopWithSelectorTests.test_create_connection_no_host_port_sockcsktjdd�����fdd�}|�j_�jjtdd�}�jt�jj|�dS)Ncs
gEdHdS)Nr )r�r1r r r!rBszYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfocstj�||�d�j�S)NrA)rSr�rA)r�r2)rr/r r!r3Fsz^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_taskzexample.comr.)	rSr�rArr9rrGr4rW)r/r3r�r )rr/r!�%test_create_connection_no_getaddrinfoAszDBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfocs�tjdd�����fdd�}|�j_tj��j_t�jj_�jj	t
dd�}�jt�jj|�dS)NcsgEdHdgS)	Nryr)r,r'�107.6.106.82r.�rLr.)ryr)r,r'rMr )r�r1r r r!rOs	zVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfocstj�||�d�j�S)NrA)rSr�rA)r�r2)rr/r r!r3Tsz[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_taskzexample.comr.)
rSr�rArrrBr>r4r?r9rrGrW)r/r3r�r )rr/r!�"test_create_connection_connect_errNszABaseEventLoopWithSelectorTests.test_create_connection_connect_errc	s�tjdd�����fdd�}|�j_tj��j_t�jj_�jj	t
dddtj�}�j
t���jj|�WdQRXdS)Nc_s
d	dgS)Nryr)r,r'�0.0.0.1r.�0.0.0.2�rOr.)ryr)r,r'rQ�rPr.)ryr)r,r'rRr )r�r1r r r!r`szSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfocstj�||�d�j�S)NrA)rSr�rA)r�r2)rr/r r!r3eszXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_taskzexample.comr.�family)rSr�rArrrBr>r4r?r9rrrrGrW)r/r3r�r )rr/r!�test_create_connection_multiple_s	z>BaseEventLoopWithSelectorTests.test_create_connection_multiplec
sdd�}||jj_tjdd�����fdd�}|�j_tj��j_	t
d��jj	_�jjt
dd	d
tjdd�}�jt
��}�jj|�WdQRX�jt|j�jd
���j|jjjj�dS)NcSs/|ddkr+td�}d|_|�dS)Nrz0.0.0.1�Err)r4�strerror)r'�errr r r!�bindts	z^BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.bindc_s
d	dgS)Nryr)r,r'�0.0.0.1r.�0.0.0.2�rYr.)ryr)r,r'r[�rZr.)ryr)r,r'r\r )r�r1r r r!r|szeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfocstj�||�d�j�S)NrA)rSr�rA)r�r2)rr/r r!r3�szjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_taskZErr2zexample.comr.rS�
local_addr�zMultiple exceptions: )Nr^)rrrXrSr�rArrrBr>r4r?r9rrrGrWrRr:r��
startswithrQr�)r/rrXr3r�r;r )rr/r!�1test_create_connection_multiple_errors_local_addrqs		zPBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addrcCs�|s|`tj|_|jj}tj�|j_d|jj_tj�|j_	d|jj	_|jj
tjdd�}|jj
|�\}}zT|jjd
�|jj\}}|j|d|j�|j|d|j�Wd|j�tj|j�Xtj|_|jj
tjdd�}|jj
|�\}}z�|jjd\}	|	dd�\}
}|j|
d	�|j|d�|jj\}}|j|d|j�|j|d|j�Wd|j�tj|j�XdS)NF�1.2.3.4r.rSr�z::1rryz	::(0\.)*1)rar.)rrrrrrBrA�_add_readerr�_add_writerr9rSr8rW�connectr�rhr,rrrQrr}r
rS�assertRegex)r/rZallow_inet_ptonrAr�r��p�_�kwargsZaddress�host�portr r r!�_test_create_connection_ip_addr�s<

z>BaseEventLoopWithSelectorTests._test_create_connection_ip_addrcCs|j|d�dS)NT)rk)r/rr r r!�test_create_connection_ip_addr�sz=BaseEventLoopWithSelectorTests.test_create_connection_ip_addrcCs|j|d�dS)NF)rk)r/rr r r!�#test_create_connection_no_inet_pton�szBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptonc
Csstj|_|jj}tj�|j_d|jj_tj�|j_d|jj_x�dD]�\}}|jj	t
jd|�}|jj|�\}}zZ|j
jd|f�|jj\}}	|j|	d|j�|j|	d|j�Wd|j�tj|j�XqaWxPd
D]H}|jj	t
jd|�}|jt��|jj|�WdQRXq#WdS)NF�httpr.�httpz	127.0.0.1rSr��nonsense�nonsense�rnr.�ror.)rrrs)rprq)rrrrrBrArbrrcr9rSr8rWrdr�rhr,rrrQrr}rGr4)
r/rrAZservicerjr�r�rfrgrhr r r!�#test_create_connection_service_name�s,

zBBaseEventLoopWithSelectorTests.test_create_connection_service_namec	sztjdd�����fdd�}|�j_�jjtdddtjdd
�}�jt	�jj
|�dS)Nc_s|dkrd	dgSgSdS)Nzexample.comryr)r,r'�107.6.106.82r.�rur.)ryr)r,r'rv�rur.)ryr)r,r'rwr )rir�r1r r r!r�szXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfocstj�||�d�j�S)NrA)rSr�rA)r�r2)rr/r r!r3�sz]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_taskzexample.comr.rSr]�)Nrx)rSr�rArr9rrrrGr4rW)r/r3r�r )rr/r!�$test_create_connection_no_local_addr�s		zCBaseEventLoopWithSelectorTests.test_create_connection_no_local_addrcsVd��fdd�}||_|j�}|jj|��}|jj|�dS)N�00:01:02:03:04:05r)cs4||f�kst�dddd�dffgS)Ni�r)r')r�)rirjr�r1)r'r r!r�szTBaseEventLoopWithSelectorTests.test_create_connection_bluetooth.<locals>.getaddrinfo)rzr))rrrAr>rW)r/rrrAr�r )r'r!� test_create_connection_bluetooth�s	z?BaseEventLoopWithSelectorTests.test_create_connection_bluetoothc	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)NrAr'�1.2.3.4r.)r|r.)rSrTrAr�rrrZSOL_TCP)r�r2r$)r/r r!�mock_getaddrinfoszkBaseEventLoopWithSelectorTests.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)rrB)r/�keyr r r!�get_extra_infosz�BaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.get_extra_infocSs|jj�dS)N)�_sockrQ)r/r r r!rQszwBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.close)r:r;r<r�rrQr r r r!�_SelectorTransportMocksr�cs#|jd���}||_|S)N)r�r�)rA�protocolZ
sslcontextZwaiterr2r)r�r r!�mock_make_ssl_transports
		zrBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_make_ssl_transportz
python.orgr.�sslTZserver_sideF�server_hostnamezperl.comr')rrBrArr?r>rrI�ANYr�r9rrWrQr�)r/r}r�r�r�rrgr )r�r/r!�2test_create_connection_ssl_server_hostname_defaultsF		
	
	
zQBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_defaultcCsr|jjtdddd�}|jt|jj|�|jjtdddd�}|jt|jj|�dS)Nz
python.orgr.r�r')rAr9rrGr�rW)r/r�r r r!�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'r.r�TrA)	rAr9rrGr�rWrr�rQ)r/r�rAr r r!�1test_create_connection_ssl_server_hostname_errorsIszPBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_errorscs�t��tj�fdd�����fdd�}|�j_�jjtdd�}�jt�jj	|��j
��dS)Nc?s|d�gEdHdS)Nrr )r�r1)rir r!rYs
zQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfocstj�||�d�j�S)NrA)rSr�rA)r�r2)rr/r r!r3_szVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_taskr'r)r
rSr�rArrErrGr4rWr.)r/r3r�r )rrir/r!�test_create_server_empty_hostUs	z<BaseEventLoopWithSelectorTests.test_create_server_empty_hostcCs>|jjtdddt��}|jt|jj|�dS)Nz0.0.0.0rrA)rArErr
rGr�rW)r/r�r r r!�!test_create_server_host_port_sockgs	z@BaseEventLoopWithSelectorTests.test_create_server_host_port_sockcCs/|jjt�}|jt|jj|�dS)N)rArErrGr�rW)r/r�r r r!�$test_create_server_no_host_port_socklszCBaseEventLoopWithSelectorTests.test_create_server_no_host_port_sockcCsTtj�}|j_g|_|jjtdd�}|jt|jj	|�dS)Nz
python.orgr)
rrBrArrrErrGr4rW)r/rr$r r r!�!test_create_server_no_getaddrinfops	z@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfocCs_tj|_|`tj�|j_|jjtdddd�}|j	t
|jj|�dS)Nz0.0.0.0r�
reuse_portT)rr�SO_REUSEPORTrrBrrArErrGr�rW)r/rr$r r r!� test_create_server_nosoreuseportws	z?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseportcCsbtj|_tj�|j_d|_|jjtdddd�}|j	t
|jj|�dS)Nr)z0.0.0.0rr�Tr{)rrrrBrr�rArErrGr�rW)r/rr$r r r!�+test_create_server_soreuseport_only_defined�s		zJBaseEventLoopWithSelectorTests.test_create_server_soreuseport_only_definedcCs�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)r:r;r<rVr r r r!rU�srUryr)r,r'�	127.0.0.1�t'Fz0.0.0.0r�r�r�)ryr)r,r'r�)r4rrrrrBrrXr?rArErrGrWrRrQr�)r/rrU�m_sockr�r r r!�test_create_server_cant_bind�sz;BaseEventLoopWithSelectorTests.test_create_server_cant_bindcCsMg|j_d|j_|jjtdd�}|jt|jj|�dS)NFr]�	localhostr)r�r)	rrrrArHr%rGr4rW)r/rr�r r r!�)test_create_datagram_endpoint_no_addrinfo�s	zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfocCsf|jjtdd�}|jt|jj|�|jjtdd�}|jt|jj|�dS)Nr]r�r)ryr	)r�r)ryr	)rArHr%rGr�rW)r/r�r r r!�(test_create_datagram_endpoint_addr_error�s		zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errorcCsYtj�|j_t|jj_|jjtjdd�}|j	t|jj
|�dS)N�remote_addr�	127.0.0.1r)r�r)rrBrAr>r4r?rHrS�DatagramProtocolrGrW)r/r�r r r!�)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)NrSr]�	127.0.0.1r)r�r)rrr4r?rArHrSr�rrGrW)r/rr�r r r!�(test_create_datagram_endpoint_socket_err�s		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)rArHrSr�rGr�rW)r/r�r r r!�0test_create_datagram_endpoint_no_matching_family�s
		zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_matching_familycCsft|jjj_|jjtjdtj	�}|j
t|jj|�|j|jjj
j�dS)NrS)r4rrZsetblockingr?rArHrSr�rrGrWrRrQr�)r/rr�r r r!�(test_create_datagram_endpoint_setblk_err�s	zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_setblk_errcCs2|jjtj�}|jt|jj|�dS)N)rArHrSr�rGr�rW)r/r�r r r!�-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)r:r;r<r r r r!rU�srUr]�	127.0.0.1rrS)r�r)r4rrrrBrrXr?rArHr%rrGrWrRrQr�)r/rrUr�r�r r r!�'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)NrTrA)r%rAr )r/r r!rY�szSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>rAr#)r�r)rrrrXrArHrWrQrr,r)r/rAr�rr�r )r/r!�"test_create_datagram_endpoint_sock�s
		
zABaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockcCs�Gdd�d�}|jjtddd|��}|jt|jj|�|jjtddd|��}|jt|jj|�|jjtdd	d|��}|jt|jj|�|jjtd
d	d|��}|jt|jj|�|jjtdd	d|��}|jt|jj|�|jjtdd
d|��}|jt|jj|�|jjtdd
d|��}|jt|jj|�|jjtdd
d|��}|jt|jj|�dS)Nc@seZdZejZdS)z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockopts.<locals>.FakeSockN)r:r;r<rrr�r r r r!�FakeSock�sr�r]�	127.0.0.1rrAr�rSr)�proto�flags�
reuse_addressTr��allow_broadcast)r�r)r�r)rArHr%rGr�rW)r/r�r�r r r!�+test_create_datagram_endpoint_sock_sockopts�s2								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���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���j
|jt	jt	j��|j��jj|j��jd
|j�dS)Ncstddd�j�S)NrTrA)r%rAr )r/r r!rY%szWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>r]�	127.0.0.1rr�posix�cygwinr�r#cstddd�j�S)NrTrA)r%rAr )r/r r!rYCsr�Tr�r�)r�r)r�r)rArHrWr�osrr��platformrrrRZ
getsockoptrrrPr�ZSO_BROADCASTrQrr,r)r/r�rr�rAZreuse_address_default_on�reuseport_supportedr )r/r!�&test_create_datagram_endpoint_sockoptssZ		
		
zEBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockoptscse|`tj�|j_�jj�fdd�dd
dddd	�}�jt�jj	|�dS)Ncstd�j�S)NrA)r%rAr )r/r r!rY`sz\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>r]�	127.0.0.1rr�Fr�T)r�r)
r�rrBrrrArHrGr�rW)r/rr�r )r/r!�+test_create_datagram_endpoint_nosoreuseportZs		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)Zfail)r�r1)r/r r!riszYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfoFr�cstd�j�S)NrA)r%rAr )r/r r!rYsszVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>r]�1.2.3.4rr�r�rSr�r�)r�r)r�r)rrrBrrrXrArbrrrHrWr�rrrrQrr})r/rrrXr�r�r�rfr )r/r!�%test_create_datagram_endpoint_ip_addrgs&			
	
zDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addrcCsEtj�}t�|j_|jjt|�|j|j	j
�dS)N)rrB�BlockingIOError�acceptr?rA�_accept_connectionrrPrQr�)r/rAr r r!�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
|ddtj�dS)N�
zToo many open files)rrB�filenorr4�errnoZEMFILEr�r?rAZ_remove_readerrrr�rrRr�r�rPrQr�rZACCEPT_RETRY_DELAYr�)r/Zm_logrAr r r!� test_accept_connection_exception�sz?BaseEventLoopWithSelectorTests.test_accept_connection_exceptionc'Cs8tjdd��}|jjd�|}|�}|j|j�x�||fD]�}|jt��|jj|�WdQRX|jt��|jj	|�WdQRX|jt��|jj
d|�WdQRX|jt��%|jj|jj�d|�WdQRX|jt��|jj
d|�WdQRXqQWdS)NcSsdS)Nr r r r r!�simple_coroutine�szLBaseEventLoopWithSelectorTests.test_call_coroutine.<locals>.simple_coroutineTr�)rSr�rArnr�rQrGrprkr�rrr�r�rg)r/r�Z	coro_funcZcoro_objrr r r!�test_call_coroutine�s 	'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)rAr r r!�stop_loop_cb�szLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cbcssfEdH|j�dS)N)r)rAr r r!�stop_loop_coro�s	zNBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_coroTgrz4^Executing <Handle.*stop_loop_cb.*> took .* seconds$rAz4^Executing <Task.*stop_loop_coro.*> took .* seconds$)
rSr�rErArnZslow_callback_durationrkrVZwarningrhre�tupler�)r/r�r�r�Zfmtr�r r r!�test_log_slow_callbacks�s

z6BaseEventLoopWithSelectorTests.test_log_slow_callbacks):r:r;r<r?r%r<rBrCrDrF�unittestZ
skipUnlessrrrGrIrJrKrNrTr`rkrlrmrtryr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�rZIPV6_ENABLEDr�r�r�r�r�r�r�r�r�r�rr#r�r�r�r r )rFr!r*�s^!

 )=	

	!$;
r*c@seZdZdd�ZdS)�RunningLoopTestscCsztjdd��}tj�}tj�}z1|jtd��|j||��WdQRXWd|j�|j�XdS)NcSs|j�dS)N)rV)rAr r r!�runner�sz@RunningLoopTests.test_running_loop_within_a_loop.<locals>.runnerzwhile another loop is running)rSr�r+rorUrWrQ)r/r�rAZ
outer_loopr r r!�test_running_loop_within_a_loop�s	

z0RunningLoopTests.test_running_loop_within_a_loopN)r:r;r<r�r r r r!r��sr��__main__)(�__doc__r�r�r�r�rr�r�r�r�rrSrrrr�r�ImportErrorrZtest.support.script_helperrZtest.script_helperZasyncio.test_supportr�r��version_infor�r"r%ZTestCaser&r=r8rr�r%r*r�r:�mainr r r r!�<module>sT


	g������