Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/test_asyncio/__pycache__/test_base_events.cpython-39.pyc

a

XC?h�9�@sndZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl	m
Z
ddlZddlmZddlm
Z
ddlmZddlmZddlmZdd	lmZe
jZejd
kZdd�Zd
d�Zdd�ZGdd�dej�ZGdd�dej�Z Gdd�dej!�Z"Gdd�dej#�Z$Gdd�dej�Z%Gdd�de	j�Z&Gdd�dej�Z'Gdd �d ej�Z(e)d!k�rje	�*�dS)"zTests for base_events.py�N)�mock)�base_events)�	constants)�utils)�support)�assert_python_ok)�
socket_helper)��cCst�d�dS�N)�asyncioZset_event_loop_policy�r
r
�G/opt/alt/python39/lib64/python3.9/test/test_asyncio/test_base_events.py�tearDownModulesrcCs`tjtd�}dD],}tt|�r2t||tt|��qt||�qt��|_t��|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)rZ	MagicMock�socket�hasattr�setattr�getattr�delattr�
test_utilsZmock_nonblocking_socket�return_value�getaddrinfo�
_is_coroutine)�m_socket�namer
r
r�mock_socket_modules

r&cCstjdtd�|�S)Nzasyncio.base_events.socket)Znew_callable)r�patchr&)�fr
r
r�patch_socket0s
��r)c@s(eZdZdd�Zdd�Zedd��ZdS)�BaseEventTestsc
Cs�tj}tj}tj}tj}tj}tj}tj}|�|||ddft	�
dd|||��|�|||ddft	�
dd|||��|�|||ddft	�
dd|||��|�|||ddft	�
dd|||��|�|||ddft	�
dd||d��|�|||ddft	�
dd||d��|�t	�
dd|dd��tj
�r�|�t	�
dd|||��|�|||ddft	�
dd|||��|�|||ddft	�
dd|||��|�t	�
dd|||��|�t	�
d	d|||��dS)
N���1.2.3.4�r-r.s1.2.3.4r)�::3r.rrr/z::3%lo0)rrrrrrrr�assertEqualr�_ipaddr_info�assertIsNoner�IPV6_ENABLED)�selfZUNSPEC�INETZINET6�STREAMZDGRAM�TCPZUDPr
r
r�test_ipaddr_info7sh������������zBaseEventTests.test_ipaddr_infoc
Cs�tj}tj}tj}|�|||ddft�dd|||��|�|||ddft�dd|||��|�|||ddft�dd|||��|�|||ddft�dd|||��|�|||ddft�dd|||��dS)Nr+�r-rr-�r,�1�1)rrrrr0rr1)r4r5r6r7r
r
r�test_port_parameter_typesss.�����z(BaseEventTests.test_port_parameter_typesc	Cs&|`|�t�ddtjtjtj��dS)Nr-r.)rr2rr1rrrr�r4r$r
r
r�test_ipaddr_info_no_inet_pton�s�z,BaseEventTests.test_ipaddr_info_no_inet_ptonN)�__name__�
__module__�__qualname__r8r=r)r?r
r
r
rr*5s<r*csleZdZ�fdd�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$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-�Z.S)W�BaseEventLoopTestscs<t���t��|_t��|j_d|jjj_	|�
|j�dS�Nr
)�super�setUpr�
BaseEventLoop�loopr�Mock�	_selector�selectr!�set_event_loop�r4��	__class__r
rrF�s


zBaseEventLoopTests.setUpc	Cs�t��}|�t|jj||�|�t|jj||||�|�t|jj||�|�t|jjg�|�t|jj	�|�t|jj
||�|�t|jj||�|j�|||||||�}|�t��|�
d�Wd�n1s�0YdSr)rrI�assertRaises�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)r4�m�genr
r
r�test_not_implemented�s<
��
�
��
�
�z'BaseEventLoopTests.test_not_implementedcCsn|�|j���|j��|�|j���|j��|j��|j��}|�t|jj�|�t|jj	|�dSr)
�assertFalserHZ	is_closed�close�
assertTrue�
create_futurerP�RuntimeError�run_forever�run_until_complete)r4r(r
r
r�
test_close�s



zBaseEventLoopTests.test_closecCsDt�dd�d|jd�}|j�|�|�|jj�|�||jj�dS)NcSsdS�NFr
r
r
r
r�<lambda>�r:z>BaseEventLoopTests.test__add_callback_handle.<locals>.<lambda>r
)r�HandlerH�
_add_callbackrY�
_scheduled�assertIn�_ready�r4�hr
r
r�test__add_callback_handle�sz,BaseEventLoopTests.test__add_callback_handlecCsJt�dd�d|jd�}|��|j�|�|�|jj�|�|jj�dS)NcSsdSrar
r
r
r
rrb�r:zHBaseEventLoopTests.test__add_callback_cancelled_handle.<locals>.<lambda>r
)rrcrH�cancelrdrYrergrhr
r
r�#test__add_callback_cancelled_handle�s
z6BaseEventLoopTests.test__add_callback_cancelled_handlecCsRGdd�dtjj�}t��|j_t��|j_|�}|j�|�|�	||jj
�dS)Nc@seZdZdd�ZdS)zCBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutorc_std��dS)Nz#cannot submit into a dummy executor)rQ)r4�fn�args�kwargsr
r
r�submit�s�zJBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutor.submitN)r@rArBrpr
r
r
r�
DummyExecutor�srq)�
concurrentZfuturesZThreadPoolExecutorrrIrHrSrT�set_default_executor�assertIs�_default_executor)r4rq�executorr
r
r�test_set_default_executor�sz,BaseEventLoopTests.test_set_default_executorcCsJt��}|�t��|j�|�Wd�n1s40Yd|j_dSr)rrI�assertWarns�DeprecationWarningrHrsru)r4rvr
r
r�.test_set_default_executor_deprecation_warnings�s*zABaseEventLoopTests.test_set_default_executor_deprecation_warningscCsDdd�}|j�|�}|�|j|�|�|tj�|�||jj�dS)NcSsdSrr
r
r
r
r�cb�sz-BaseEventLoopTests.test_call_soon.<locals>.cb)	rH�	call_soonr0Z	_callback�assertIsInstancerrcrfrg�r4r{rir
r
r�test_call_soon�s
z!BaseEventLoopTests.test_call_sooncCsH|j�d�|�td��|j�d�Wd�n1s:0YdS)NTza callable objectr.)rH�	set_debug�assertRaisesRegex�	TypeErrorr|rMr
r
r�test_call_soon_non_callable�sz.BaseEventLoopTests.test_call_soon_non_callablecCsHdd�}|j�d|�}|�|tj�|�||jj�|�||jj�dS)NcSsdSrr
r
r
r
rr{�sz.BaseEventLoopTests.test_call_later.<locals>.cb�$@)	rH�
call_laterr}r�TimerHandlerfreZassertNotInrgr~r
r
r�test_call_later�s
z"BaseEventLoopTests.test_call_latercs\g��fdd�}t��|j_|j�d|d�|j�d|d�t�|j�|��ddg�dS)Ncs��|�dSr)�append)�arg�Zcallsr
rr{sz>BaseEventLoopTests.test_call_later_negative_delays.<locals>.cb����a����b)rrIrHrSr�r �run_brieflyr0)r4r{r
r�r�test_call_later_negative_delayssz2BaseEventLoopTests.test_call_later_negative_delayscs~�fdd�}t���j_d}�j��|}�j�||��j��}�j���j��|}��||d|���|d|�dS)Ncs�j��dSr�rH�stopr
rMr
rr{sz4BaseEventLoopTests.test_time_and_call_at.<locals>.cb皙�����?g�������?g�������?)	rrIrHrS�time�call_atr^ZassertGreaterEqual�assertLessEqual)r4r{�delayZwhenZt0Zdtr
rMr�test_time_and_call_ats

z(BaseEventLoopTests.test_time_and_call_atcCs�dd�}|�|�|r�d}|�t|��|�|�Wd�n1sF0Y|�t|��|�d|�Wd�n1s~0Y|�t|��$|�|��d|�Wd�q�1s�0Yn*|�|�|�d|�|�|��d|�dS)NcSsdSrr
r
r
r
rr{"sz+BaseEventLoopTests.check_thread.<locals>.cbzMNon-thread-safe operation invoked on an event loop other than the current one�<)r�r�r]r|r�r�r�)r4rH�debugr{�msgr
r
r�check_thread!s
(*4
zBaseEventLoopTests.check_threadcsn�fdd��d�fdd�	}t���j_t���j_|�jd�|�jd�|�jddd�|�jddd�dS)	Nc
s�|��z`|rZt��}z,t�|���||�Wt�d�|��qft�d�|��0n��||�Wn2ty�}z|�|j	|�WYd}~nd}~00|�|j
d�dSr)�waitrrGrrLr�rZ�	Exception�call_soon_threadsafeZ
set_exception�
set_result)rH�eventr��create_loop�futZloop2�excrMr
r�check_in_thread5s


�
$z=BaseEventLoopTests.test_check_thread.<locals>.check_in_threadFcsVt��}|��}|�|j�|||||f}tj�|d�}|��|�|�|��dS)N)�targetrn)	�	threadingZEventr\r|�setZThread�startr_�join)rHr�r�r�r�rn�thread)r�r
r�test_threadIs
z9BaseEventLoopTests.test_check_thread.<locals>.test_threadT)r�)F)rrIrHrSrT)r4r�r
)r�r4r�test_check_thread4s
z$BaseEventLoopTests.test_check_threadcCs�t�t��ddd�d|jd�}t�t��ddd�d|jd�}|��t��|j_|jj	�
|�|jj	�
|�|j��|jjj
jdd}|�d|ko�d	kn|�|�|g|jj	�|�|jjj�dS)
Ng@cSsdS�NTr
r
r
r
rrbdr:z3BaseEventLoopTests.test__run_once.<locals>.<lambda>r
r�cSsdSr�r
r
r
r
rrbfr:rg#@g%@)rr�r��	monotonicrHrkrrIrSrer��	_run_oncerJrK�	call_argsr[r0�called)r4Zh1Zh2�tr
r
r�test__run_oncecs��
 z!BaseEventLoopTests.test__run_oncecCs<|j�d�|�|j���|j�d�|�|j���dS)NTF)rHr�r[Z	get_debugrYrMr
r
r�test_set_debugusz!BaseEventLoopTests.test_set_debugcs~d�d���fdd�}t�t��d||jf|jd�}t��|j_|jj�	|�|j�
�|���|��gt
|jj��dS)NFcsd�|�dd���dS)NTcSsdSr�r
r
r
r
rrb�r:zOBaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb.<locals>.<lambda>)r|�rH��handleZ	processedr
rr{sz=BaseEventLoopTests.test__run_once_schedule_handle.<locals>.cbr.)rr�r�r�rHrrIrSrer�r�r[r0�listrgr~r
r�r�test__run_once_schedule_handle{s�

z1BaseEventLoopTests.test__run_once_schedule_handlecCs�t��|j_|�dtjko$dkn�dd�}d}|j�d|�d}td�D]}|j�d|�}|�	�qR|d7}td�D]}|j�d	|�}|�	�q~|�
||tj�|�|jj
|�|j��|d8}|�|jj
|�|�t|jj�||�tt�tjtj��d}ttj|d�}||7}t|�D]}|j�d|��q0||7}t|�D]}|j�d|�}|�	��qV|�t|jj�||�|j��|�t|jj�|�|�td
d�|jjD���dS)Nrg�?cSsdSrr
r
r
r
rr{�szEBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.cbr.��i�dcSsg|]}|j�qSr
)Z
_cancelled)�.0�xr
r
r�
<listcomp>�r:zMBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.<listcomp>)rrIrHrSr[rZ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr��rangerkr�Z_MIN_SCHEDULED_TIMER_HANDLESr0Z_timer_cancelled_countr��lenre�int�mathZceil�max�all)r4r{Znot_cancelled_countZcancelled_countr�riZadd_cancel_countZadd_not_cancel_countr
r
r�&test__run_once_cancelled_event_cleanup�sd�


�
�������
z9BaseEventLoopTests.test__run_once_cancelled_event_cleanupcCs|�t|jjd�dS)NZblah)rPr�rHr_rMr
r
r�"test_run_until_complete_type_error�s�z5BaseEventLoopTests.test_run_until_complete_type_errorcCs2|j��}|��}|�|j�|�t|j|�dSr)rHr\Z
new_test_loop�
addCleanuprZrP�
ValueErrorr_)r4�taskZ
other_loopr
r
r�test_run_until_complete_loop�s
�z/BaseEventLoopTests.test_run_until_complete_loopcs�Gdd�dt��dd�}�fdd�}t��|j_|j�|�|���� |j�|d��Wd�n1sl0Y|j�|d��dS)	Nc@seZdZdS)z]BaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.ShowStopperN�r@rArBr
r
r
r�ShowStopper�sr�c�st�|�IdHdSr�r�sleep)r�r
r
r�foo�szUBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.foocs��dSrr
r
�r�r
r�throw�szWBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.throwr�g�������?)�
SystemExitrrIrHrSr|rPr_)r4r�r�r
r�r�5test_run_until_complete_loop_orphan_future_close_loop�s.zHBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loopcCs�tjddg}|�t|jj|jjtj�|�t|jj|jjtj|�|�t|jj|jjtjtjd�|jt|jj|jjtjg|�Rddi�|jt|jj|jjtjg|�Rddi�|jt|jj|jjtjg|�Rddi�dS)	N�-c�pass�{�universal_newlinesT�shell�bufsize�)	�sys�
executablerPr�rHr_Zsubprocess_execr�SubprocessProtocol)r4rnr
r
r�!test_subprocess_exec_invalid_args�sJ��
����������z4BaseEventLoopTests.test_subprocess_exec_invalid_argsc	Cs�|�t|jj|jjtjd�|�t|jj|jjtjtjddg�|jt|jj|jjtjddd�|jt|jj|jjtjddd�|jt|jj|jjtjddd	�dS)
Nr�r�r�zexit 0T)r�)r�r�)r�)	rPr�rHr_Zsubprocess_shellrr�r�r�rMr
r
r�"test_subprocess_shell_invalid_argss(�����z5BaseEventLoopTests.test_subprocess_shell_invalid_argscst���j_dd�}t�d��`}�j��}�j�||�|��fdd���j��|j	j
t�d�t
ttfd�Wd�n1s�0Yt�d��b}�j��}�j�d||�|��fd	d���j��|j	j
t�d�t
ttfd�Wd�n1�s0YdS)
NcSs|�d�dddS)NTr.r)r��r�r
r
r�
zero_error,s
zHBaseEventLoopTests.test_default_exc_handler_callback.<locals>.zero_error�asyncio.base_events.loggercs
�j��Srr�r�rMr
rrb4r:zFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>�Exception in callback.*zero��exc_info�{�G�z�?cs
�j��Srr�r�rMr
rrb>r:)rrIrHrSr'r\r|�add_done_callbackr^�error�assert_called_withr �MockPattern�ZeroDivisionError�MOCK_ANYr�)r4r��logr�r
rMr�!test_default_exc_handler_callback)s(

�$

�z4BaseEventLoopTests.test_default_exc_handler_callbackcs�t���j_dd�}t�d���}tj|��jd�}|��fdd���j��d}t	�
�tr||jj
t�d�tttfd�n|jj
t�d	�d
d�Wd�n1s�0YdS)Nc�st�d�IdHdddS)Nr�r.rr�r
r
r
r�zero_error_coroGszIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_coror�r�cs
�j��Srr��rnrMr
rrbNr:zBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>z.*exception was never retrievedr�z(.*exception was never retrieved.*ZeroDivF)rrIrHrSr'r�
ensure_futurer�r^r�
gc_collect�PY34r�r�r r�r�r�)r4r�r�r�r
rMr�test_default_exc_handler_coroDs&
���z0BaseEventLoopTests.test_default_exc_handler_corocCs<|�td��|j�d�Wd�n1s.0YdS)NzA callable object or None�spam)r�r�rH�set_exception_handlerrMr
r
r�test_set_exc_handler_invalid_sz/BaseEventLoopTests.test_set_exc_handler_invalidcs�dd����fdd�}�j�d�t���j_���j���t��}�j�|����j��|�|�}|�	�jt
t�d�||j
d��|���j�d�t�d��2}|�|jj	t�d	�tt
t
fd
�Wd�n1s�0Y|jr�J�dS)NcSsdddS�Nr.rr
r
r
r
rr�dszBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_errorcs�j���}�j��|Sr�rHr|r�)r��r4r�r
r�run_loopgs
z@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopTz!Exception in callback.*zero_error)�	exception�messager�Zsource_tracebackr�r�r�)rHr�rrIrSr2Zget_exception_handlerr�rtr�r�r r�Z_source_traceback�
reset_mockr'r�r�r�)r4r�Zmock_handlerr�r�r
r�r�test_set_exc_handler_customcs8����$z.BaseEventLoopTests.test_set_exc_handler_customcs|�fdd�}dd�}t���j_�j�|�t�d��2}|�|jjt�	d�t
ttfd�Wd�n1sn0YdS)Ncs"dd�}�j�|��j��dS)NcSsdddSr�r
r
r
r
rr��szTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_errorr��r�rMr
rr��sz@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loopcSstd��dS�Nr�)�AttributeError�rH�contextr
r
r�handler�sz?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handlerr�z$Unhandled error in exception handlerr�)rrIrHrSr�r'r�r�r r�rr�)r4r�rr�r
rMr�test_set_exc_handler_broken�s��z.BaseEventLoopTests.test_set_exc_handler_brokencsd�G�fdd�dtj�}|��|��j�t����fdd�}t�d��&}|�|jj	ddd�Wd�n1sx0Yd	d
�}d���
|�t�d��P}|�|jj	t�d�dd�|�
d��|�t�dd
�t�Wd�n1s�0YdS)Ncs(eZdZe��Ze��Z�fdd�ZdS)z@BaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loopcs|�td��dSr�r�)r4r��_contextr
r�default_exception_handler�szZBaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loop.default_exception_handlerN)r@rArBrrIrJrSrr
r
r
r�Loop�sr
csdd�}��|����dS)NcSsdddSr�r
r
r
r
rr��szXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)r|r�rr�r
rr��s
zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loopr�z&Exception in default exception handlerTr�cSstd��dS)NZhamr	rr
r
r�custom_handler�szJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handlerz9Exception in default exception.*while handling.*in customrr�)rrGr�rZrrLrr'r�r�r�r r�rfrt�typer�)r4r
r�r�rr
)rrHr�test_default_exc_handler_broken�s2
�$
��z2BaseEventLoopTests.test_default_exc_handler_brokencCsL|�td��|j�d�Wd�n1s.0Y|�|j���dS)Nz'task factory must be a callable or Noner.)r�r�rH�set_task_factoryr2�get_task_factoryrMr
r
r�test_set_task_factory_invalid�s
�*z0BaseEventLoopTests.test_set_task_factory_invalidcs�t��|j_Gdd�dtj��dd�}�fdd�}|�|j���|j�|�|�	|j��|�|j�
|��}|�t|���|j�
|�|j�d�|�|j���|j�
|��}|�t|tj��|�t|���|j�
|�dS)Nc@seZdZdS)z8BaseEventLoopTests.test_set_task_factory.<locals>.MyTaskNr�r
r
r
r�MyTask�src�sdSrr
r
r
r
r�coro�sz6BaseEventLoopTests.test_set_task_factory.<locals>.corocs�||d�S�Nr�r
�rHr�rr
rrb�r:z:BaseEventLoopTests.test_set_task_factory.<locals>.<lambda>)rrIrHrSr�Taskr2rrrt�create_taskr[�
isinstancer_rY)r4r�factoryr�r
rr�test_set_task_factory�s z(BaseEventLoopTests.test_set_task_factorycCs�d�d�}tdd|�\}}}|�|��d�td|ddd�\}}}|�|��d�td|ddd�\}}}|�|��d	�tdd|dd
�\}}}|�|��d�tdddd|�\}}}|�|��d	�dS)
N�
)zimport asynciozloop = asyncio.get_event_loop()zprint(loop.get_debug())z-Er�sFalser+)�PYTHONASYNCIODEBUGZ
PYTHONDEVMODEr;sTrue)rz-XZdev)r�rr0�rstrip)r4�code�sts�stdout�stderrr
r
r�test_env_var_debug�s*
����
z%BaseEventLoopTests.test_env_var_debugcstGdd�dtj��dd�}G��fdd�dtj�}|��|���|�}tj|�d�}|�|��d|_|��dS)	Nc@seZdZdS)z3BaseEventLoopTests.test_create_task.<locals>.MyTaskNr�r
r
r
rrsrc�sdSrr
r
r
r
r�testsz1BaseEventLoopTests.test_create_task.<locals>.testcseZdZ��fdd�ZdS)z6BaseEventLoopTests.test_create_task.<locals>.EventLoopcs�|�d�Srr
�r4r�rrHr
rrszBBaseEventLoopTests.test_create_task.<locals>.EventLoop.create_taskN)r@rArBrr
r(r
r�	EventLoopsr)r�F)	rrrrGrLr�r}Z_log_destroy_pendingrZ)r4r&r)rr�r
r(r�test_create_task
s
z#BaseEventLoopTests.test_create_taskc	Cs`dd�}t��}|j|�dd�}z&|�|��d�W|�|�|��n|�|�|��0dS)Nc�sdSrr
r
r
r
rr&$szLBaseEventLoopTests.test_create_named_task_with_default_factory.<locals>.test�	test_task�r%)r�new_event_looprr0�get_namer_rZ)r4r&rHr�r
r
r�+test_create_named_task_with_default_factory#s

�
z>BaseEventLoopTests.test_create_named_task_with_default_factoryc	Csrdd�}dd�}t��}|�|�|j|�dd�}z&|�|��d�W|�|�|��n|�|�|��0dS)NcSstj||d�Sr)rrrr
r
r�task_factory0szSBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.task_factoryc�sdSrr
r
r
r
rr&3szKBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.testr+r,)rr-rrr0r.r_rZ)r4r0r&rHr�r
r
r�*test_create_named_task_with_custom_factory/s


�
z=BaseEventLoopTests.test_create_named_task_with_custom_factorycCsldd�}t��|j_t��|j_z|j�|��WntyDYn0|j��t�	�|�
|jjj�dS)Nc�st�dSr��KeyboardInterruptr
r
r
r�raise_keyboard_interruptCszXBaseEventLoopTests.test_run_forever_keyboard_interrupt.<locals>.raise_keyboard_interrupt)rrIrHrSZcall_exception_handlerr_r3rZrr�rYr��r4r4r
r
r�#test_run_forever_keyboard_interrupt?s
z6BaseEventLoopTests.test_run_forever_keyboard_interruptcs�dd�}t���j_z�j�|��Wnty8Yn0��fdd��d�_z�j����j��WntyzYn0��	�j�dS)Nc�st�dSrr2r
r
r
rr4UszZBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.raise_keyboard_interruptcs�j��d�_dSr�)rHr�r�r
��funcr4r
rr8_s
zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcF)
rrIrHrSr_r3r�r|r^r[r5r
r7r�%test_run_until_complete_baseexceptionRsz8BaseEventLoopTests.test_run_until_complete_baseexceptionc	s�t��d�d�����fdd�}���fdd����fdd��|�j_�f�jjj_tdd	�D]X}��d
|��6�j��jj	��j�
����d�Wd�q^1s�0Yq^dS)Nrcs�|vr�j����dSr�rHr|)Z
event_list)�do_event�doer�event_sentinelr4r
r�proc_eventsqszZBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.proc_eventscs�d7��j���dS�Nr.r:r
)�	callcount�clear_selectorr4r
rr;vszWBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.do_eventcs���d�jjj_dSrD)rkrHrJrKr!r
)r<r4r
rrA{sz]BaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.clear_selectorr.r	z	Loop %d/2)�objectrHrSrJrKr!r�ZsubTestr|r�r^r0)r4r>�ir
)r@rAr;r<r=r4r�2test_single_selecter_event_callback_after_stoppingjs
zEBaseEventLoopTests.test_single_selecter_event_callback_after_stoppingcsDd��fdd�}t��|j_|j�|�t�|j�|��d�dS)Nrcs�d7�dSr?r
r
��countr
r�callback�sz2BaseEventLoopTests.test_run_once.<locals>.callbackr.)rrIrHrSr|r Zrun_oncer0)r4rGr
rEr�
test_run_once�sz BaseEventLoopTests.test_run_oncecCs4t��|j_|j��|j��|jjj�d�dS�Nr)	rrIrHrSr�r^rJrKZassert_called_once_withrMr
r
r�test_run_forever_pre_stopped�s

z/BaseEventLoopTests.test_run_forever_pre_stoppedc�sFdddd���fdd�}|�}|������fdd��t�����S)NF)�started�stopped�	finalizedc	s4d�d<zdD]
}|VqWd�d<n
d�d<0dS)NTrK)ZZEROZONEZTWO�THREEZFOURrMr
��item)�statusr
r�agen�s

z;BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.agenc�sLz���IdH}Wnty&YdS0|dkr<d�d<dSt����dS)NrNTrL)�	__anext__�StopAsyncIterationrrrO�Zai�iter_onerQr
rrV�sz?BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.iter_one)�	__aiter__rr)r4rRZagr
rUr�leave_unfinalized_asyncgen�s�
z-BaseEventLoopTests.leave_unfinalized_asyncgencCs�t��|j_t��|j_t����|j�|���}|dsHt	�
|j�q2|�|d�|�|d�|�|d�t�
�t	�
|j�|�|d�Wd�n1s�0YdS)NrLrKrM)rrIrHrSrTr�
disable_gcr_rXr r�r[rYr��r4rQr
r
r� test_asyncgen_finalization_by_gc�s
z3BaseEventLoopTests.test_asyncgen_finalization_by_gccCs�t��|j_t��|j_|j�d�t����|j�|�	��}|dsTt
�|j�q>|�|d�|�|d�|�
|d�|j�|j�dtj��t
�|j�|�|d�Wd�n1s�0YdS)NTrLrKrM)rrIrHrSrTr�rrYr_rXr r�r[rY�run_in_executorr�rZr
r
r�0test_asyncgen_finalization_by_gc_in_other_thread�s
�zCBaseEventLoopTests.test_asyncgen_finalization_by_gc_in_other_thread)/r@rArBrFrXr`rjrlrwrzrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr%r*r/r1r6r9rDrHrJrXr[r]�
__classcell__r
r
rNrrC�sV
			/L$0"rCc@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MyProtoNFcCs"d|_d|_|rt����|_dS�N�INITIALr)�state�nbytesrZget_running_loopr\�done)r4r\r
r
r�__init__�szMyProto.__init__cCs.||_|jdksJ|j��d|_|�d�dS)Nra�	CONNECTEDs%GET / HTTP/1.0
Host: example.com

)�	transportrb�write�r4rgr
r
r�connection_made�szMyProto.connection_madecCs*|jdksJ|j��|jt|�7_dS)Nrf�rbrcr��r4�datar
r
r�
data_received�szMyProto.data_receivedcCs|jdksJ|j��d|_dS)Nrf�EOF�rbrMr
r
r�eof_received�szMyProto.eof_receivedcCs0|jdvsJ|j��d|_|jr,|j�d�dS)N)rfro�CLOSED�rbrdr��r4r�r
r
r�connection_lost�szMyProto.connection_lost)F)	r@rArBrdrerjrnrqrur
r
r
rr_�s
r_c@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MyDatagramProtoNFcCsd|_d|_|r|��|_dSr`)rbrcr\rd)r4r\rHr
r
rreszMyDatagramProto.__init__cCs$||_|jdksJ|j��d|_dS)Nra�INITIALIZED)rgrbrir
r
rrjszMyDatagramProto.connection_madecCs*|jdksJ|j��|jt|�7_dS�Nrwrk)r4rm�addrr
r
r�datagram_receivedsz!MyDatagramProto.datagram_receivedcCs|jdksJ|j��dSrxrprtr
r
r�error_receivedszMyDatagramProto.error_receivedcCs0|jdksJ|j��d|_|jr,|j�d�dS)Nrwrrrsrtr
r
rruszMyDatagramProto.connection_lost)FN)	r@rArBrdrerjrzr{rur
r
r
rrvs
rvcs�eZdZ�fdd�Ze�d�dd��Zedd��Zedd	��Z	d
d�Z
dd
�Zdd�Zdd�Z
e�eed�d�dd��Ze�ejd�dd��Zdd�Zdd�Zdd�Zdd �Zd!d"�Zed#d$��Zd%d&�Ze�ejd�e�ej� d'�d(�ed)d*����Z!ed+d,��Z"ed-d.��Z#ed/d0��Z$d1d2�Z%ed3d4��Z&d5d6�Z'd7d8�Z(d9d:�Z)d;d<�Z*d=d>�Z+d?d@�Z,dAdB�Z-dCdD�Z.edEdF��Z/edGdH��Z0edIdJ��Z1edKdL��Z2dMdN�Z3dOdP�Z4dQdR�Z5edSdT��Z6e�ejdU�dVdW��Z7edXdY��Z8dZd[�Z9ed\d]��Z:d^d_�Z;e�eed`�da�dbdc��Z<ej=ddde��Z>dfdg�Z?dhdi�Z@djdk�ZAdldm�ZBedndo��ZCedpdq��ZDdrds�ZEe�dt�dudv��ZFdwdx�ZGe�dt�dydz��ZH�ZIS){�BaseEventLoopWithSelectorTestscs$t���t��|_|�|j�dSr)rErFrZSelectorEventLooprHrLrMrNr
rrF s

z$BaseEventLoopWithSelectorTests.setUpzsocket.getnameinfocCs.dd�|_|j�|j�d��}|�|d�dS)NcWsdS)N�*r
r�r
r
rrb'r:zABaseEventLoopWithSelectorTests.test_getnameinfo.<locals>.<lambda>)�abcr�r})�side_effectrHr_Zgetnameinfor0)r4Zm_gai�rr
r
r�test_getnameinfo%s
z/BaseEventLoopWithSelectorTests.test_getnameinfocs�Gdd�dtj�}dd����fdd�}d�dd	g���fd
d�}||_|�j_�j�|dd
�}��t��}�j�|�Wd�n1s�0Y��	t
|j�d�dS)Nc@seZdZdS)zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.MyProtoNr�r
r
r
rr_.sr_c�sddgS�N�r�r.�r+)z107.6.106.82�Pr
�rn�kwr
r
rr"1s�zZBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfocs�j��|i|���Sr�rHr�rn�kwds�r"r4r
r�getaddrinfo_task5sz_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_taskr�Zerr1Zerr2cs�d7�t����dSr?)�OSErrorr�)�errors�idxr
r�_socket;szVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socket�example.comr�zMultiple exceptions: err1, err2)r�ProtocolrrHr"�create_connectionrPr�r_r0�strr�)r4r$r_r�r�r�cmr
)r�r"r�r4r�&test_create_connection_multiple_errors+s*zEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errorsc	s�t��}||j_�fdd�}|�j_tjj�jdtj	d��f�j�
tdd�}��tj	���j�
|�Wd�n1sz0Y��|jj�Wd�n1s�0YdS)Ncs,�j��}tjtjdddf}|�|g�|S)Nrr+)�	127.0.0.1r�)rHr\rrrr�)rnr�r�ryrMr
rr"Ps
�zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfo�sock_connect)rr�r�)rrIrr!rHr"r'rBr�TimeoutErrorr�r_rPr_r[rZr�)r4r$�sockr"rr
rMr�test_create_connection_timeoutJs�*z=BaseEventLoopWithSelectorTests.test_create_connection_timeoutcCs,|jjtddt�d�}|�t|jj|�dS)Nr�r��r�)rHr�r_rBrPr�r_r'r
r
r�%test_create_connection_host_port_sock_s
�zDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sockc	Cs�t�tjtj�}|�X|jjt|d�}|�td��|j�|�Wd�n1sT0YWd�n1sr0YdS�Nr�zA Stream Socket was expected)	rrrrHr�r_r�r�r_�r4r�rr
r
r�!test_create_connection_wrong_sockds�z@BaseEventLoopWithSelectorTests.test_create_connection_wrong_sockc	Cs�t�tjtj�}|�X|jjt|d�}|�td��|j�|�Wd�n1sT0YWd�n1sr0YdSr�)	rrrrH�
create_serverr_r�r�r_r�r
r
r�test_create_server_wrong_sockls�z<BaseEventLoopWithSelectorTests.test_create_server_wrong_sockcCsP|jjtdddd�}|�td��|j�|�Wd�n1sB0YdS�Nr�r�r.)�ssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)rHr�r_r�r�r_r'r
r
r�/test_create_server_ssl_timeout_for_plain_socketts��zNBaseEventLoopWithSelectorTests.test_create_server_ssl_timeout_for_plain_socket�
SOCK_NONBLOCKz$no socket.SOCK_NONBLOCK (linux only)cCsvt�tjtjtjB�}|�H|jjdd�|d�}|j�|�}|��|j�|���Wd�n1sh0YdS)NcSsdSrr
r
r
r
rrb�r:zRBaseEventLoopWithSelectorTests.test_create_server_stream_bittype.<locals>.<lambda>r�)	rrrr�rHr�r_rZ�wait_closed)r4r�r�srvr
r
r�!test_create_server_stream_bittype|s�z@BaseEventLoopWithSelectorTests.test_create_server_stream_bittypezno IPv6 supportc
sl�fdd�}z�j�|��WnHtyf}z0ttd�rP|jtjkrP��d�n�WYd}~n
d}~00dS)Nc�s���t��.tjdd�dd�jd�IdH}Wd�n1s>0Yz,��t|j�d�W|��|�	�IdHn|��|�	�IdH0dS)NcSsdSrr
r
r
r
rrb�r:zVBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main.<locals>.<lambda>�::1rr�)
rxryrZstart_serverrHZ
assertGreaterr��socketsrZr�)r�rMr
r�main�s�*�zDBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main�
EADDRNOTAVAILzfailed to bind to ::1)rHr_r�r�errnor�ZskipTest)r4r�Zexr
rMr�test_create_server_ipv6�s


�z6BaseEventLoopWithSelectorTests.test_create_server_ipv6c	Cs|t�tj�}|�X|jjt|d�}|�td��|j�|�Wd�n1sP0YWd�n1sn0YdS)Nr�zA UDP Socket was expected)rrrH�create_datagram_endpointr_r�r�r_r�r
r
r�(test_create_datagram_endpoint_wrong_sock�s�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_wrong_sockcCs"|j�t�}|�t|jj|�dSr�rHr�r_rPr�r_r'r
r
r�(test_create_connection_no_host_port_sock�szGBaseEventLoopWithSelectorTests.test_create_connection_no_host_port_sockcsDdd����fdd�}|�j_�j�tdd�}��t�jj|�dS)Nc�sgSrr
r�r
r
rr"�szYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfocs�j��|i|���Srr�r�r�r
rr��sz^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_taskr�r�)rHr"r�r_rPr�r_�r4r�rr
r�r�%test_create_connection_no_getaddrinfo�s
�zDBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfocsZdd����fdd�}|�j_t���j_t�jj_�j�tdd�}��	t�jj
|�dS)Nc�sdgSr�r
r�r
r
rr"�szVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfocs�j��|i|���Srr�r�r�r
rr��sz[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_taskr�r�)rHr"rrIr�r�rr�r_rPr_r�r
r�r�"test_create_connection_connect_err�s

�zABaseEventLoopWithSelectorTests.test_create_connection_connect_errcs�dd����fdd�}|�j_t���j_t�jj_�jjtddt	j
d�}��t���j�|�Wd�n1sv0YdS)Nc�sddgS�N)r�r.r�r+)�0.0.0.1r�)r�r.r�r+)z0.0.0.2r�r
r�r
r
rr"�s�zSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfocs�j��|i|���Srr�r�r�r
rr��szXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_taskr�r���family)
rHr"rrIr�r�rr�r_rrrPr_r�r
r�r�test_create_connection_multiple�s

�z>BaseEventLoopWithSelectorTests.test_create_connection_multiplecs�dd�}||jj_dd����fdd�}|�j_t���j_td��jj_	�jj
tdd	tjd
d�}��
t��}�j�|�Wd�n1s�0Y��t|j��d����|jjjj�dS)
NcSs"|ddkrtd�}d|_|�dS)Nrr��Err)r��strerror)ry�errr
r
r�bind�sz^BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.bindc�sddgSr�r
r�r
r
rr"�s�zeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfocs�j��|i|���Srr�r�r�r
rr��szjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_taskZErr2r�r��Ni��r��
local_addrzMultiple exceptions: )rr!r�rHr"rrIr�r�rr�r_rrPr_r[r�r��
startswithrZr�)r4r$r�r�rr�r
r�r�1test_create_connection_multiple_errors_local_addr�s

�*zPBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addrc	Cs�|s|`tj|_|jj}t��|j_d|jj_t��|j_	d|jj	_|j�
tjdd�}|j�
|�\}}zT|j�d�|jj\}}|�|d|j�|�|d|j�W|��t�|j�n|��t�|j�0tj�r�tj|_|j�
tjdd�}|j�
|�\}}z~|jjd\}	|	dd	�\}
}|�|
d
�|�|d�|jj\}}|�|d|j�|�|d|j�W|��t�|j�n|��t�|j�0dS)NFr-r��r-r�r�rr�rr�z	::(0\.)*1)rrr"r!rrIrH�_add_readerr#�_add_writerr�rr�r_�connectr�r�r0rrrZr r�rr3rr��assertRegex)r4r$Zallow_inet_ptonr�rr��p�_roZaddress�host�portr
r
r�_test_create_connection_ip_addr�sF

��z>BaseEventLoopWithSelectorTests._test_create_connection_ip_addrZaixzDbpo-25545: IPv6 scope id and getaddrinfo() behave differently on AIXc	Cs�tj|_|jj}tj|_t��|j_d|jj_	t��|j_
d|jj
_	|j�tj
dd�}|j�|�\}}zT|j�d�|jj\}}|�|d|j�|�|d|j�W|��t�|j�n|��t�|j�0dS)NFz	fe80::1%1r�)zfe80::1r�rr.r�r)rr"r!rr�rrIrHr�r#r�r�rr�r_r�r�r�r0rrZr r�)r4r$r�rr�r�r�ror
r
r�!test_create_connection_ipv6_scopes$

�z@BaseEventLoopWithSelectorTests.test_create_connection_ipv6_scopecCs|�|d�dSr��r�r>r
r
r�test_create_connection_ip_addr7sz=BaseEventLoopWithSelectorTests.test_create_connection_ip_addrcCs|�|d�dSrar�r>r
r
r�#test_create_connection_no_inet_pton;szBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptonc

Cs4tj|_|jj}t��|j_d|jj_t��|j_d|jj_dD]�\}}|j�	t
jd|�}|j�|�\}}zX|j
�d|f�|jj\}}	|�|	d|j�|�|	d|j�W|��t�|j�q@|��t�|j�0q@dD]N}|j�	t
jd|�}|�t��|j�|�Wd�q�1�s$0Yq�dS)NF))Zhttpr�)shttpr�r�r�r)Znonsensesnonsense)rr"r!rrIrHr�r#r�r�rr�r_r�r�r�r0rrrZr r�rPr�)
r4r$r�Zservicer�rr�r�r�ror
r
r�#test_create_connection_service_name?s4


��
�zBBaseEventLoopWithSelectorTests.test_create_connection_service_namecsLdd����fdd�}|�j_�jjtddtjdd�}��t�jj|�dS)	Nc�s|dkrddgSgSdS)Nr�r�r
)r�rnr�r
r
rr"_s
�zXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfocs�j��|i|���Srr�r�r�r
rr�fsz]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_taskr�r�r�r�)	rHr"r�r_rrrPr�r_r�r
r�r�$test_create_connection_no_local_addr^s
�
�zCBaseEventLoopWithSelectorTests.test_create_connection_no_local_addrcs<d��fdd�}||_|��}|j�|��}|j�|�dS)N)z00:01:02:03:04:05r.cs$||f�ksJ�dddd�dffgS)Ni�r.r+r
)r�r�rnr��ryr
rr"vszTBaseEventLoopWithSelectorTests.test_create_connection_bluetooth.<locals>.getaddrinfo)r"rrHr�r_)r4r$r"r�rr
r�r� test_create_connection_bluetoothpsz?BaseEventLoopWithSelectorTests.test_create_connection_bluetoothc	s�t���j_�fdd�}|�jj_t���j_�j���jj_�jjj�d�t���j_	Gdd�d���fdd�}|�jj	_tj
}t�}�jj	���jj
tddd	|d
�}�j�|�\}}|���jj	j||||dd|d��jj	���jj
tddd	d
|d�}�j�|�\}}|���jj	j||||dd
|d��jj	���jj
tddd	d|d�}�j�|�\}}|���jj	j||||dd|d�dS)Ncs*�j��}|�tjtjtjddfg�|S)Nr+r�)rHr\r�rrrZSOL_TCP)rnr�r(rMr
r�mock_getaddrinfo�s

�zkBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_getaddrinfoc@s eZdZdZdd�Zdd�ZdS)zqBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMockNcSst��Sr)rrI)r4�keyr
r
r�get_extra_info�sz�BaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.get_extra_infocSs|j��dSr)�_sockrZrMr
r
rrZ�szwBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.close)r@rArBr�r�rZr
r
r
r�_SelectorTransportMock�sr�cs|�d���}||_|Sr)r�r�)r��protocolZ
sslcontextZwaiterr�rg)r�r
r�mock_make_ssl_transport�s
zrBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_make_ssl_transport�
python.orgr�T)�sslr�F)Zserver_side�server_hostnamer�zperl.com)r�r�r�r+)rrIrHr"rr�r\r!r�rR�ANYrBrr�r_r_rZr�)r4r�r�r�Zhandshake_timeoutrrgr�r
)r�r4r�2test_create_connection_ssl_server_hostname_defaultsj
	
������zQBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_defaultcCsP|jjtdddd�}|�t|jj|�|jjtdddd�}|�t|jj|�dS)Nr�r�r+)r�r�r'r
r
r�4test_create_connection_no_ssl_server_hostname_errors�s��zSBaseEventLoopWithSelectorTests.test_create_connection_no_ssl_server_hostname_errorscCs�|jjtdddd�}|�t|jj|�|jjtdddd�}|�t|jj|�t��}|jjtddd|d�}|�|j�|�t|jj|�dS)Nr+r�T)r�)r�r�)	rHr�r_rPr�r_rr�rZ)r4rr�r
r
r�1test_create_connection_ssl_server_hostname_errors�s�zPBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_errorscCsP|jjtdddd�}|�td��|j�|�Wd�n1sB0YdSr�)rHr�r_r�r�r_r'r
r
r�3test_create_connection_ssl_timeout_for_plain_socket�s��zRBaseEventLoopWithSelectorTests.test_create_connection_ssl_timeout_for_plain_socketcsXt���fdd����fdd�}|�j_�j�tdd�}��t�jj|�����dS)Nc�s|d�gSrIr
r�)r�r
rr"�szQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfocs�j��|i|���Srr�r�r�r
rr��szVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_taskr+r)	rBrHr"r�r_rPr�r_r2)r4r�r�r
)r"r�r4r�test_create_server_empty_host�sz<BaseEventLoopWithSelectorTests.test_create_server_empty_hostcCs,|jjtddt�d�}|�t|jj|�dS)N�0.0.0.0rr�)rHr�r_rBrPr�r_�r4r�r
r
r�!test_create_server_host_port_sock�s
�z@BaseEventLoopWithSelectorTests.test_create_server_host_port_sockcCs"|j�t�}|�t|jj|�dSr)rHr�r_rPr�r_r�r
r
r�$test_create_server_no_host_port_sock�szCBaseEventLoopWithSelectorTests.test_create_server_no_host_port_sockcCsNt��}|j_|j��|_|j�d�|j�tdd�}|�	t
|jj|�dS)Nr�r)rrIrHr"r\r!r�r�r_rPr�r_)r4r"r(r
r
r�!test_create_server_no_getaddrinfo�s
z@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfocCsBtj|_|`t��|j_|jjtdddd�}|�	t
|jj|�dS)Nr�rT��
reuse_port)rr"�SO_REUSEPORTrrIr!rHr�r_rPr�r_�r4r$r(r
r
r� test_create_server_nosoreuseports�z?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseportcCsDtj|_t��|j_d|_|jjtdddd�}|�	t
|jj|�dS)Nr�r�rTr�)rr"rrIr!r�rHr�r_rPr�r_r�r
r
r�+test_create_server_soreuseport_only_defineds�zJBaseEventLoopWithSelectorTests.test_create_server_soreuseport_only_definedcCsnGdd�dt�}dg|j_d|j_t��}|j_||j_|j	�
tdd�}|�t|j	j
|�|�|jj�dS)Nc@seZdZdZdS)zHBaseEventLoopWithSelectorTests.test_create_server_cant_bind.<locals>.Errr�N)r@rArBr�r
r
r
rr� sr�)r�r.r�r+)r�it'Fr�r)r�r"r!r#rrIrr�rrHr�r_rPr_r[rZr��r4r$r�Zm_sockr�r
r
r�test_create_server_cant_binds�z;BaseEventLoopWithSelectorTests.test_create_server_cant_bindcCs6g|j_d|j_|jjtdd�}|�t|jj|�dS)NF)�	localhostr�r�)	r"r!r#rHr�rvrPr�r_�r4r$rr
r
r�)test_create_datagram_endpoint_no_addrinfo-s�
�zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfocCsH|jjtdd�}|�t|jj|�|jjtdd�}|�t|jj|�dS)Nr�r�)r�r.r�r	)rHr�rvrPr�r_r'r
r
r�(test_create_datagram_endpoint_addr_error7s�
��
�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errorcCs>t��|j_t|jj_|jjtjdd�}|�	t|jj
|�dS)N�r�r)�remote_addr)rrIrHr�r�rr�r�DatagramProtocolrPr_r'r
r
r�)test_create_datagram_endpoint_connect_errAs
�
�zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_connect_errcs�td|jd��t��|j_}g|_|jj�fdd�ddd�}|j�|�\}}|�|j	�|�
�|j��j�|�d�j
�dS)NT�r\rHcs�Srr
r
�r�r
rrbPr:z^BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcast.<locals>.<lambda>r�)r��allow_broadcastrr)rvrHrrIr�r!r�r_rYr�rZrdr0rb)r4r�rrgr�r
r�r�-test_create_datagram_endpoint_allow_broadcastJs
�zLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcastcCs^tj|_t|j_|jjtjtjd�}|�	t|jj
|�|jjtjdd�}|�	t|jj
|�dS)Nr�r�r�)rr"r�rrHr�rr�rrPr_r�r
r
r�(test_create_datagram_endpoint_socket_err[s�
��
�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_socket_errzIPv6 not supported or enabledcCs*|jjtjddd�}|�t|jj|�dS)Nr�)r�r)r�r��rHr�rr�rPr�r_r'r
r
r�0test_create_datagram_endpoint_no_matching_familyjs�
�zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_matching_familycCsHt|jjj_|jjtjtj	d�}|�
t|jj|�|�|jjj
j�dS)Nr�)r�rr!�setblockingrrHr�rr�rrPr_r[rZr�r�r
r
r�(test_create_datagram_endpoint_setblk_errrs�
�
�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_setblk_errcCs$|j�tj�}|�t|jj|�dSrrr'r
r
r�-test_create_datagram_endpoint_noaddr_nofamily}s�zLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_noaddr_nofamilycCshGdd�dt�}tj|_t��}|j_||j_|jj	t
dtjd�}|�||jj
|�|�|jj�dS)Nc@seZdZdS)zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bind.<locals>.ErrNr�r
r
r
rr��sr�r�)r�r�)r�rr"rrIr!r�rrHr�rvrrPr_r[rZr�r�r
r
r�'test_create_datagram_endpoint_cant_bind�s�zFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bindcsjt�tjtj�}|�d��jj�fdd�|d�}�j�|�\}}|���j�|j���	d|j
�dS)Nr�cstd�jd�S�NTr��rvrHr
rMr
rrb�r:zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>r�rr)rrrr�rHr�r_rZrdr0rb)r4r�r�rgr�r
rMr�"test_create_datagram_endpoint_sock�s

�zABaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock�AF_UNIXzNo UNIX Socketscsd�jj�fdd�tjd�}�j�|�\}}|jjtjks<J�|���j�|j���	d|j
�dS)Ncstd�jd�Srr	r
rMr
rrb�r:zXBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unix.<locals>.<lambda>r�rr)rHr�rrr_r�r�rZrdr0rb)r4r�rgr�r
rMr�'test_create_datagram_endpoint_sock_unix�s
�zFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unixcs�t���v}tjtjtjd�}|�|�|���jj�fdd�|tjd�}�j�	|�\}}|���j�	|j
�Wd�n1s�0YdS)N)rcstd�jd�Srr	r
rMr
rrb�r:zaBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unix.<locals>.<lambda>r�)r Zunix_socket_pathrrrr�rZrHr�r_rd)r4�pathr�rrgr�r
rMr�0test_create_datagram_endpoint_existing_sock_unix�s


�zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unixcCsGdd�d�}|jjtd|�d�}|�t|jj|�|jjtd|�d�}|�t|jj|�|jjtd|�d�}|�t|jj|�|jjtd|�d�}|�t|jj|�|jjtd|�d	�}|�t|jj|�|jjtd
|�d�}|�t|jj|�|jjtd
|�d�}|�t|jj|�dS)
Nc@seZdZejZdS)z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockopts.<locals>.FakeSockN)r@rArBrrrr
r
r
r�FakeSock�srr�)r�r�)r�r�r.)r�r�)�protor�)�flagsr�T)r�r�)r�r�)rHr�rvrPr�r_)r4rr�r
r
r�+test_create_datagram_endpoint_sock_sockopts�s:�������zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockoptscs4�jj�fdd�dd�}�j�|�\}}|�d�}ttd�}|rV��|�tjtj	����|�tjtj
��|���j�|j���
d|j��jj�fdd�d|d	d
�}�j�|�\}}|�d�}��|�tjtj��|r���|�tjtj	����|�tjtj
��|���j�|j���
d|j�dS)Ncstd�jd�Srr	r
rMr
rrb�r:zWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>r�r�rr�rrcstd�jd�Srr	r
rMr
rrb�r:T)r�r�r�)rHr�r_r�rrrY�
getsockoptrr�ZSO_BROADCASTrZrdr0rbrr[)r4rrgr�r��reuseport_supportedr
rMr�&test_create_datagram_endpoint_sockopts�s`
�

����
�
������zEBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockoptscsT�jj�fdd�ddd�}��t���j�|�Wd�n1sF0YdS)Ncstd�jd�Srr	r
rMr
rrb	r:zbBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_error.<locals>.<lambda>r�T�r�Z
reuse_address)rHr�rPr�r_r'r
rMr�1test_create_datagram_endpoint_reuse_address_errors
�zPBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_errorcs|�jj�fdd�ddd�}��t��D�j�|�\}}|���j�|j���d|j�Wd�n1sn0YdS)Ncstd�jd�Srr	r
rMr
rrbr:zdBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warning.<locals>.<lambda>r�Frrr)	rHr�rxryr_rZrdr0rb)r4rrgr�r
rMr�3test_create_datagram_endpoint_reuse_address_warnings
�zRBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warningcs@|`t��|j_�jj�fdd�ddd�}��t�jj	|�dS)Ncst�jd�Srr	r
rMr
rrb$r:z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>r�T�r�r�)
r�rrIrr!rHr�rPr�r_r�r
rMr�+test_create_datagram_endpoint_nosoreuseports
�zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseportc	s��fdd�}||_t��|jj_}t���j_d�jj_t	td�}�jj
�fdd�d|d�}�j�|�\}}z:|�d�|jj|j
|j|jd	�W|��t��j�n|��t��j�0dS)
Ncs��d�dS)Nz"should not have called getaddrinfo)Zfailr�rMr
rr",szYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfoFr�cst�jd�Srr	r
rMr
rrb6r:zVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>r9r)r�rr)r"rrIrr!r�rHr�r#rr�r_r�rrrrZr r�)r4r$r"r�rrr�r�r
rMr�%test_create_datagram_endpoint_ip_addr*s,


�

��zDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addrcCs2t��}t�|j_|j�t|�|�|j	j
�dSr)rrI�BlockingIOError�acceptrrH�_accept_connectionr_rYrZr��r4r�r
r
r�test_accept_connection_retryDs
z;BaseEventLoopWithSelectorTests.test_accept_connection_retryr�c
Cs�t��}d|j_ttjd�|j_t��|j	_
t��|j	_|j	�t
|�|�|jj�|�|jj�|j	j
�d�|j	j�tjtjt
|ddtjtj�dS)N�
zToo many open files)rrI�filenor!r�r�ZEMFILErrrHZ_remove_readerr�rr_r[r�r�rYrZr�rZACCEPT_RETRY_DELAYr�)r4Zm_logr�r
r
r� test_accept_connection_exceptionKs�z?BaseEventLoopWithSelectorTests.test_accept_connection_exceptionc	Cs�|�t��tjdd��}Wd�n1s.0Y|j�d�|}|�}|�|j�||fD�]0}|�t	��|j�
|�Wd�n1s�0Y|�t	��|j�|�Wd�n1s�0Y|�t	��|j�d|�Wd�n1�s0Y|�t	��(|j�
|j��d|�Wd�n1�sH0Y|�t	��&|j�|j�d|��Wd�qb1�s�0YqbdS)NcSsdSrr
r
r
r
r�simple_coroutine_szLBaseEventLoopWithSelectorTests.test_call_coroutine.<locals>.simple_coroutineTr�)rxryr�	coroutinerHr�r�rZrPr�r|r�r�r�r�r_r\)r4r$Z	coro_funcZcoro_objr8r
r
r�test_call_coroutine]s((**.8�z2BaseEventLoopWithSelectorTests.test_call_coroutinecCs�dd�}dd�}t�|j�|j�d�d|j_|j�||j�|j��|jjd^}}|�	|t
|�d�tj||j�|jd	�|j��|jjd^}}|�	|t
|�d
�dS)NcSs|��dSr�r�r�r
r
r�stop_loop_cbvszLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cbc�s|��dSrr'r�r
r
r�stop_loop_coroyszNBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_coroTgrz4^Executing <Handle.*stop_loop_cb.*> took .* seconds$r�z4^Executing <Task.*stop_loop_coro.*> took .* seconds$)rrLrHr�Zslow_callback_durationr|r^Zwarningr�r��tupler�)r4Zm_loggerr(r)Zfmtrnr
r
r�test_log_slow_callbacksts"
�
�z6BaseEventLoopWithSelectorTests.test_log_slow_callbacks)Jr@rArBrFrr'r�r)r�r�r�r�r�r��unittest�
skipUnlessrrr�rr3r�r�r�r�r�r�r�r�ZskipIfr��platformr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr
rZskip_unless_bind_unix_socketrrrrrrrr r#r&r+r^r
r
rNrr|s�


�
	

+�



I	





	
	








 /


r|c@seZdZdd�ZdS)�RunningLoopTestscCs~dd�}t��}t��}zN|�td��|�||��Wd�n1sJ0YW|��|��n|��|��0dS)Nc�s|��dSr)r^r�r
r
r�runner�sz@RunningLoopTests.test_running_loop_within_a_loop.<locals>.runnerzwhile another loop is running)rr-r�r]r_rZ)r4r0rHZ
outer_loopr
r
r�test_running_loop_within_a_loop�s�.
�z0RunningLoopTests.test_running_loop_within_a_loopN)r@rArBr1r
r
r
rr/�sr/cs�eZdZddZGdd�dej�Ze�fdd��Ze�fdd��Z	�fd	d
�Z
d(dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Z�ZS))�BaseLoopSockSendfileTestss�12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcdeic@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)z!BaseLoopSockSendfileTests.MyProtocCs(d|_d|_t�|_|��|_d|_dSra)rK�closed�	bytearrayrmr\r�rg)r4rHr
r
rre�s

z*BaseLoopSockSendfileTests.MyProto.__init__cCsd|_||_dSr�)rKrgrir
r
rrj�sz1BaseLoopSockSendfileTests.MyProto.connection_madecCs|j�|�dSr)rm�extendrlr
r
rrn�sz/BaseLoopSockSendfileTests.MyProto.data_receivedcCsd|_|j�d�d|_dSr�)r3r�r�rgrtr
r
rru�sz1BaseLoopSockSendfileTests.MyProto.connection_lostc�s|jIdHdSrr�rMr
r
rr��sz-BaseLoopSockSendfileTests.MyProto.wait_closedN)r@rArBrerjrnrur�r
r
r
rr_�s
r_csTtj|_dt_ttjd��}|�|j�Wd�n1s<0Yt��	�dS)Ni@�wb)
r�!SENDFILE_FALLBACK_READBUFFER_SIZE�'_BaseLoopSockSendfileTests__old_bufsize�openr�TESTFNrh�DATArE�
setUpClass)�cls�fprNr
rr<�s
*z$BaseLoopSockSendfileTests.setUpClasscs"|jt_t�tj�t���dSr)r8rr7r�unlinkr:rE�
tearDownClass)r=rNr
rr@�sz'BaseLoopSockSendfileTests.tearDownClasscsJddlm}|�|_|�|j�ttjd�|_|�|jj	�t
���dS)Nr)�BaseSelectorEventLoop�rb)Zasyncio.selector_eventsrArHrLr9rr:�filer�rZrErF)r4rArNr
rrF�szBaseLoopSockSendfileTests.setUpFcCs*t�tjtj�}|�|�|�|j�|Sr)rrrrr�rZ)r4�blockingr�r
r
r�make_socket�s
z%BaseLoopSockSendfileTests.make_socketcCs|j�|�Sr)rHr_r'r
r
rr��sz"BaseLoopSockSendfileTests.run_loopc	s��������j�����jj�fdd�tjdtjd����j	d�
�}td�D]H}z���j��|��Wn&t
y���t�d��YqPYqP0q�qP���j��|������fdd�}��|���fS)	Ncs�Srr
r
)rr
rrb�r:z3BaseLoopSockSendfileTests.prepare.<locals>.<lambda>rr�r!g�?csD�������������jdur@�j��������dSr)rZr�r�rgr
�rr4Zserverr�r
r�cleanup�s

z2BaseLoopSockSendfileTests.prepare.<locals>.cleanup)rEr_rHr�r�rZHOSTrrr�Zgetsocknamer�r�r�rr�r�)r4ryr�rGr
rFr�prepare�s"
�

z!BaseLoopSockSendfileTests.preparec	Csx|��\}}|�tjd��*|�|j�||jdd��Wd�n1sJ0Y|�|j	d�|�|j�
�d�dS)N�sendfile is not availablerr:)rHr�r�SendfileNotAvailableErrorr�rHZ_sock_sendfile_nativerCr0rm�tell�r4r�rr
r
r�"test__sock_sendfile_native_failure�s��$z<BaseLoopSockSendfileTests.test__sock_sendfile_native_failurecCsx|��\}}|�tjd��*|�|jj||jdd��Wd�n1sJ0Y|�|j�	�d�|�|j
d�dS)NrIF)Zfallbackrr:)rHr�rrJr�rH�
sock_sendfilerCr0rKrmrLr
r
r�test_sock_sendfile_no_fallbacks��&z8BaseLoopSockSendfileTests.test_sock_sendfile_no_fallbackcCsv|��\}}|�|j�||j��}|��|�|���|�|t|j	��|�|j�
�t|j	��|�|j|j	�dSr)rHr�rHrNrCrZr�r0r�r;rKrm�r4r�rZretr
r
r�test_sock_sendfile_fallbacksz5BaseLoopSockSendfileTests.test_sock_sendfile_fallbackcCsv|��\}}|�|j�||jdd��}|��|�|���|�|d�|�|j��d�|�|j	|j
dd��dS)Ni�i�r�)rHr�rHrNrCrZr�r0rKrmr;rPr
r
r�,test_sock_sendfile_fallback_offset_and_counts�zFBaseLoopSockSendfileTests.test_sock_sendfile_fallback_offset_and_countcCs^|j�d�|jdd�}|�td��&|�|j�||j��Wd�n1sP0YdS)NT)rDzmust be non-blocking)rHr�rEr�r�r�rNrCrr
r
r�test_blocking_socket*sz.BaseLoopSockSendfileTests.test_blocking_socketc	Csx|��}ttjd��P}|�td��$|�|j�||��Wd�n1sL0YWd�n1sj0YdS)Nr�zbinary mode)	rEr9rr:r�r�r�rHrN)r4r�r(r
r
r�test_nonbinary_file0sz-BaseLoopSockSendfileTests.test_nonbinary_filecCslt�tjtj�}|�d�|�|j�|�td��&|�|j	�
||j��Wd�n1s^0YdS)NFzonly SOCK_STREAM type)rrrrr�rZr�r�r�rHrNrCrr
r
r�test_nonstream_socket6s

z/BaseLoopSockSendfileTests.test_nonstream_socketc	CsR|��}|�td��*|�|j�||jdd��Wd�n1sD0YdS)N� count must be a positive integerrrF�rEr�r�r�rHrNrCrr
r
r�test_notint_count=s
�z+BaseLoopSockSendfileTests.test_notint_countc	CsR|��}|�td��*|�|j�||jdd��Wd�n1sD0YdS)NrVrr��rEr�r�r�rHrNrCrr
r
r�test_negative_countCs
�z-BaseLoopSockSendfileTests.test_negative_countcCsP|��}|�td��(|�|j�||jd��Wd�n1sB0YdS)N�%offset must be a non-negative integer�offsetrWrr
r
r�test_notint_offsetIs
�z,BaseLoopSockSendfileTests.test_notint_offsetcCsP|��}|�td��(|�|j�||jd��Wd�n1sB0YdS)Nr[r�rYrr
r
r�test_negative_offsetOs
�z.BaseLoopSockSendfileTests.test_negative_offset)F)r@rArBr;rr�r_�classmethodr<r@rFrEr�rHrMrOrQrRrSrTrUrXrZr]r^r^r
r
rNrr2�s*	
r2c@s.eZdZdd�Ze�eed�d�dd��ZdS)�TestSelectorUtilscCsB|�tjtj�}|�|�t�|�|�tjtj�}|�|�dSr)rrr�TCP_NODELAYrYrZ_set_nodelayr[)r4r��optr
r
r�check_set_nodelayWs


z#TestSelectorUtils.check_set_nodelayrazneed socket.TCP_NODELAYcCs�tjtjtjtjd�}|�|�|�Wd�n1s:0Ytjtjtjtjd�}|�$|�d�|�|�Wd�n1s�0YdS)N)r�rrF)rrrrrcrrr
r
r�test_set_nodelay`s�(�
z"TestSelectorUtils.test_set_nodelayN)	r@rArBrcr,r-rrrdr
r
r
rr`Vs
	�r`�__main__)+�__doc__Zconcurrent.futuresrrr�r�rr�r�r�r,rrrrZtest.test_asynciorr r&rZtest.support.script_helperrZtest.supportrr�r��version_infor�rr&r)ZTestCaser*rCr�r_r�rvr|r/r2r`r@r�r
r
r
r�<module>sX
aTy5