HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/test_asyncio/__pycache__/test_base_events.cpython-310.pyc
o

�iC<�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl	m
Z
ddlZddlmZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlZe
jZejdkZdd
�Zdd�Zdd�ZGdd�dej �Z!Gdd�dej �Z"Gdd�dej#�Z$Gdd�dej%�Z&Gdd�dej �Z'Gdd�de	j �Z(Gdd�dej �Z)Gd d!�d!ej �Z*e+d"kr�e	�,�dSdS)#zTests for base_events.py�N)�mock)�base_events)�	constants)�utils)�support)�assert_python_ok)�	os_helper)�
socket_helper)��cCst�d�dS�N)�asyncioZset_event_loop_policy�rr�?/usr/local/lib/python3.10/test/test_asyncio/test_base_events.py�tearDownModule�rcCs`tjtd�}dD]}tt|�rt||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�namerrr�mock_socket_modules

r(cCstjdtd�|�S)Nzasyncio.base_events.socket)Znew_callable)r�patchr()�frrr�patch_socket1s
��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|||��dSdS)
N���1.2.3.4�r/r0s1.2.3.4r)�::3r0rrr1z::3%lo0)rrrrrrrr�assertEqualr�_ipaddr_info�assertIsNoner	�IPV6_ENABLED)�selfZUNSPEC�INETZINET6�STREAMZDGRAM�TCPZUDPrrr�test_ipaddr_info8sj�������������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)rrrrr2rr3)r6r7r8r9rrr�test_port_parameter_typests.�����z(BaseEventTests.test_port_parameter_typesc	Cs&|`|�t�ddtjtjtj��dS)Nr/r0)rr4rr3rrrr�r6r&rrr�test_ipaddr_info_no_inet_pton�s
�z,BaseEventTests.test_ipaddr_info_no_inet_ptonN)�__name__�
__module__�__qualname__r:r?r+rArrrrr,6s
<r,csteZdZ�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-dWdX�Z.�Z/S)Y�BaseEventLoopTestscs<t���t��|_t��|j_d|jjj_	|�
|j�dS�Nr)�super�setUpr�
BaseEventLoop�loopr�Mock�	_selector�selectr#�set_event_loop�r6��	__class__rrrH�s


zBaseEventLoopTests.setUpc	Cs�t��}|�t|jj||�|�t|jj||||�|�t|jj||�|�t|jjg�|�t|jj	�|�t|jj
||�|�t|jj||�|j�|||||||�}|�t��|�
d�Wd�dS1skwYdSr)rrK�assertRaises�NotImplementedErrorrJZ_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)r6�m�genrrr�test_not_implemented�s>
��
�
��
�
�"�z'BaseEventLoopTests.test_not_implementedcCsn|�|j���|j��|�|j���|j��|j��|j��}|�t|jj�|�t|jj	|�dSr)
�assertFalserJZ	is_closed�close�
assertTrue�
create_futurerR�RuntimeError�run_forever�run_until_complete)r6r*rrr�
test_close�s



zBaseEventLoopTests.test_closecCsDt�dd�d|jd�}|j�|�|�|jj�|�||jj�dS)NcS�dS�NFrrrrr�<lambda>��z>BaseEventLoopTests.test__add_callback_handle.<locals>.<lambda>r)r
�HandlerJ�
_add_callbackr[�
_scheduled�assertIn�_ready�r6�hrrr�test__add_callback_handle�sz,BaseEventLoopTests.test__add_callback_handlecCsJt�dd�d|jd�}|��|j�|�|�|jj�|�|jj�dS)NcSrcrdrrrrrre�rfzHBaseEventLoopTests.test__add_callback_cancelled_handle.<locals>.<lambda>r)r
rgrJ�cancelrhr[rirkrlrrr�#test__add_callback_cancelled_handle�s
z6BaseEventLoopTests.test__add_callback_cancelled_handlecCsRGdd�dtjj�}t��|j_t��|j_|�}|j�|�|�	||jj
�dS)Nc@�eZdZdd�ZdS)zCBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutorc_�td��)Nz#cannot submit into a dummy executor)rS)r6�fn�args�kwargsrrr�submit�s�zJBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutor.submitN)rBrCrDrvrrrr�
DummyExecutor�srw)�
concurrent�futures�ThreadPoolExecutorrrKrJrUrV�set_default_executor�assertIs�_default_executor)r6rw�executorrrr�test_set_default_executor�sz,BaseEventLoopTests.test_set_default_executorcCsJt��}|�t��|j�|�Wd�n1swYd|j_dSr)rrK�assertWarns�DeprecationWarningrJr{r})r6r~rrr�.test_set_default_executor_deprecation_warnings�s
�zABaseEventLoopTests.test_set_default_executor_deprecation_warningscCsDdd�}|j�|�}|�|j|�|�|tj�|�||jj�dS)NcS�dSrrrrrr�cb��z-BaseEventLoopTests.test_call_soon.<locals>.cb)	rJ�	call_soonr2�	_callback�assertIsInstancer
rgrjrk�r6r�rmrrr�test_call_soon�s
z!BaseEventLoopTests.test_call_sooncCsJ|j�d�|�td��|j�d�Wd�dS1swYdS)NTza callable objectr0)rJ�	set_debug�assertRaisesRegex�	TypeErrorr�rOrrr�test_call_soon_non_callable�s"�z.BaseEventLoopTests.test_call_soon_non_callablecCsHdd�}|j�d|�}|�|tj�|�||jj�|�||jj�dS)NcSr�rrrrrrr��r�z.BaseEventLoopTests.test_call_later.<locals>.cb�$@)	rJ�
call_laterr�r
�TimerHandlerjriZassertNotInrkr�rrr�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�Zcallsrrr�rz>BaseEventLoopTests.test_call_later_negative_delays.<locals>.cb����a����b)rrKrJrUr�r"�run_brieflyr2)r6r�rr�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�rJ�stoprrOrrr�rz4BaseEventLoopTests.test_time_and_call_at.<locals>.cb皙�����?g�������?g�������?)	rrKrJrU�time�call_atr`ZassertGreaterEqual�assertLessEqual)r6r��delayZwhen�t0ZdtrrOr�test_time_and_call_ats

z(BaseEventLoopTests.test_time_and_call_atcCs�dd�}|�|�|rgd}|�t|��
|�|�Wd�n1s#wY|�t|��|�d|�Wd�n1s?wY|�t|��|�|��d|�Wd�dS1s`wYdS|�|�|�d|�|�|��d|�dS)NcSr�rrrrrrr�#r�z+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�)r6rJ�debugr��msgrrr�check_thread"s 
��"�
zBaseEventLoopTests.check_threadcsn�fdd��d�fdd�	}t���j_t���j_|�jd�|�jd�|�jddd�|�jddd�dS)	Nc
s�|��z/|r,t��}zt�|���||�Wt�d�|��nt�d�|��w��||�WntyM}z|�|j	|�WYd}~dSd}~ww|�|j
d�dSr)�waitrrIr
rNr�r\�	Exception�call_soon_threadsafe�
set_exception�
set_result)rJ�eventr��create_loop�futZloop2�excrOrr�check_in_thread6s$



�
���z=BaseEventLoopTests.test_check_thread.<locals>.check_in_threadFcsVt��}|��}|�|j�|||||f}tj�|d�}|��|�|�|��dS)N)�targetrt)	�	threading�Eventr^r��set�Thread�startra�join)rJr�r�r�r�rt�thread)r�rr�test_threadJs
z9BaseEventLoopTests.test_check_thread.<locals>.test_threadT)r��F)rrKrJrUrV)r6r�r)r�r6r�test_check_thread5s
z$BaseEventLoopTests.test_check_threadcCs�t�t��ddd�d|jd�}t�t��ddd�d|jd�}|��t��|j_|jj	�
|�|jj	�
|�|j��|jjj
jdd}|�d|koRd	kn|�|�|g|jj	�|�|jjj�dS)
Ng@cSrc�NTrrrrrreerfz3BaseEventLoopTests.test__run_once.<locals>.<lambda>rr�cSrcr�rrrrrregrfrg#@g%@)r
r�r��	monotonicrJrorrKrUrir��	_run_oncerLrM�	call_argsr]r2�called)r6Zh1Zh2�trrr�test__run_onceds��
 z!BaseEventLoopTests.test__run_oncecCs<|j�d�|�|j���|j�d�|�|j���dS)NTF)rJr�r]Z	get_debugr[rOrrr�test_set_debugvsz!BaseEventLoopTests.test_set_debugcs~d�d���fdd�}t�t��d||jf|jd�}t��|j_|jj�	|�|j�
�|���|��gt
|jj��dS)NFcsd�|�dd���dS)NTcSrcr�rrrrrre�rfzOBaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb.<locals>.<lambda>)r��rJ��handleZ	processedrrr��sz=BaseEventLoopTests.test__run_once_schedule_handle.<locals>.cbr0)r
r�r�r�rJrrKrUrir�r�r]r2�listrkr�rr�r�test__run_once_schedule_handle|s�

z1BaseEventLoopTests.test__run_once_schedule_handlecCs�t��|j_|�dtjkodkn�dd�}d}|j�d|�d}td�D]
}|j�d|�}|�	�q)|d7}td�D]
}|j�d	|�}|�	�q?|�
||tj�|�|jj
|�|j��|d8}|�|jj
|�|�t|jj�||�tt�tjtj��d}ttj|d�}||7}t|�D]	}|j�d|�q�||7}t|�D]
}|j�d|�}|�	�q�|�t|jj�||�|j��|�t|jj�|�|�td
d�|jjD���dS)Nrg�?cSr�rrrrrrr��r�zEBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.cbr0��i�dcSsg|]}|j�qSr)Z
_cancelled)�.0�xrrr�
<listcomp>�szMBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.<listcomp>)rrKrJrUr]rZ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr��rangeror�Z_MIN_SCHEDULED_TIMER_HANDLESr2Z_timer_cancelled_countr��lenri�int�math�ceil�max�all)r6r�Znot_cancelled_countZcancelled_countr�rmZadd_cancel_countZadd_not_cancel_countrrr�&test__run_once_cancelled_event_cleanup�sd�


�
������
�
 z9BaseEventLoopTests.test__run_once_cancelled_event_cleanupcCs|�t|jjd�dS)NZblah)rRr�rJrarOrrr�"test_run_until_complete_type_error�s�z5BaseEventLoopTests.test_run_until_complete_type_errorcCs2|j��}|��}|�|j�|�t|j|�dSr)rJr^Z
new_test_loop�
addCleanupr\rR�
ValueErrorra)r6�taskZ
other_looprrr�test_run_until_complete_loop�s
�z/BaseEventLoopTests.test_run_until_complete_loopcs�Gdd�dt��dd�}�fdd�}t��|j_|j�|�|����|j�|d��Wd�n1s6wY|j�|d��dS)	Nc@�eZdZdS)z]BaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.ShowStopperN�rBrCrDrrrr�ShowStopper��r�c�s�t�|�IdHdSr�r
�sleep)r�rrr�foo�s�zUBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.foocs��rrr�r�rr�throw�r�zWBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.throwr�g�������?)�
SystemExitrrKrJrUr�rRra)r6r�r�rr�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�
executablerRr�rJraZsubprocess_execr
�SubprocessProtocol)r6rtrrr�!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�)	rRr�rJraZsubprocess_shellr
r�r�r�rOrrr�"test_subprocess_shell_invalid_argss(����
�z5BaseEventLoopTests.test_subprocess_shell_invalid_argscst���j_dd�}t�d��0}�j��}�j�||�|��fdd���j��|j	j
t�d�t
ttfd�Wd�n1sBwYt�d��2}�j��}�j�d||�|��fd	d���j��|j	j
t�d�t
ttfd�Wd�dS1s�wYdS)
NcSs|�d�dddS)NTr0r)r��r�rrr�
zero_error-s
zHBaseEventLoopTests.test_default_exc_handler_callback.<locals>.zero_error�asyncio.base_events.loggerc�
�j��Srr�r�rOrrre5�
zFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>�Exception in callback.*zero��exc_info�{�G�z�?cr�rr�r�rOrrre?r�)rrKrJrUr)r^r��add_done_callbackr`�error�assert_called_withr"�MockPattern�ZeroDivisionError�MOCK_ANYr�)r6r��logr�rrOr�!test_default_exc_handler_callback*s,

��


�"�z4BaseEventLoopTests.test_default_exc_handler_callbackcs�t���j_dd�}t�d��J}tj|��jd�}|��fdd���j��d}t	�
�tr>|jj
t�d�tttfd�n|jj
t�d	�d
d�Wd�dSWd�dS1s\wYdS)Nc�s�t�d�IdHdddS)Nr�r0rr�rrrr�zero_error_coroHs�zIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_coror�r�cr�rr��rtrOrrreOr�zBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>z.*exception was never retrievedr�z(.*exception was never retrieved.*ZeroDivF)rrKrJrUr)r
�
ensure_futurer�r`r�
gc_collect�PY34r�rr"rrr)r6rrr�rrOr�test_default_exc_handler_coroEs,
����	"�z0BaseEventLoopTests.test_default_exc_handler_corocCs>|�td��|j�d�Wd�dS1swYdS)NzA callable object or None�spam)r�r�rJ�set_exception_handlerrOrrr�test_set_exc_handler_invalid`s"�z/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��}|�|jj	t�d	�tt
t
fd
�Wd�n1spwY��|j�dS)NcS�dddS�Nr0rrrrrrr�e�zBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_errorcs�j���}�j��|Sr�rJr�r�)r��r6r�rr�run_loophs
z@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopTz!Exception in callback.*zero_error)�	exception�messager�Zsource_tracebackr�r�r�)rJr�rrKrUr4Zget_exception_handlerr
r|rrr"rZ_source_traceback�
reset_mockr)r�rr[r�)r6rZmock_handlerr�rrrr�test_set_exc_handler_customds:�����z.BaseEventLoopTests.test_set_exc_handler_customcs~�fdd�}dd�}t���j_�j�|�t�d��}|�|jjt�	d�t
ttfd�Wd�dS1s8wYdS)Ncs"dd�}�j�|��j��dS)NcSrrrrrrrr��rzTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_errorr�r�rOrrr�sz@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loopcSrr�Nr)�AttributeError�rJ�contextrrr�handler��z?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handlerr�z$Unhandled error in exception handlerr�)rrKrJrUr
r)r�rr"rrr)r6rrrrrOr�test_set_exc_handler_broken�s��"�z.BaseEventLoopTests.test_set_exc_handler_brokencsd�G�fdd�dtj�}|��|��j�t����fdd�}t�d��}|�|jj	ddd�Wd�n1s<wYd	d
�}d���
|�t�d��)}|�|jj	t�d�dd�|�
d��|�t�dd
�t�Wd�dS1s}wYdS)Ncs(eZdZe��Ze��Z�fdd�ZdS)z@BaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loopcs|�td��r�r�)r6r��_contextrr�default_exception_handler�szZBaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loop.default_exception_handlerN)rBrCrDrrKrLrUr$rr"rr�Loop�sr%csdd�}��|����dS)NcSrrrrrrrr��rzXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)r�r�rr�rrr�s
zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loopr�z&Exception in default exception handlerTr�cSrr)NZhamr!rrrr�custom_handler�rzJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handlerz9Exception in default exception.*while handling.*in customrr)rrIr�r\r
rNrr)r�rr
r"rrjr|�typer)r6r%rrr&r)r#rJr�test_default_exc_handler_broken�s6
��
��"�z2BaseEventLoopTests.test_default_exc_handler_brokencCsL|�td��|j�d�Wd�n1swY|�|j���dS)Nz'task factory must be a callable or Noner0)r�r�rJ�set_task_factoryr4�get_task_factoryrOrrr�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@r�)z8BaseEventLoopTests.test_set_task_factory.<locals>.MyTaskNr�rrrr�MyTask�r�r,c���dSrrrrrr�coro���z6BaseEventLoopTests.test_set_task_factory.<locals>.corocs�||d�S�Nr�r�rJr.�r,rrre��z:BaseEventLoopTests.test_set_task_factory.<locals>.<lambda>)rrKrJrUr
�Taskr4r*r)r|�create_taskr]�
isinstancerar[)r6r.�factoryr�rr2r�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.new_event_loop()zprint(loop.get_debug())z-Er�sFalser-)�PYTHONASYNCIODEBUGZ
PYTHONDEVMODEr=sTrue)r:z-X�dev)r�rr2�rstrip)r6�code�sts�stdout�stderrrrr�test_env_var_debug�s*
���
�z%BaseEventLoopTests.test_env_var_debugcstGdd�dtj��dd�}G��fdd�dtj�}|��|���|�}tj|�d�}|�|��d|_|��dS)	Nc@r�)z3BaseEventLoopTests.test_create_task.<locals>.MyTaskNr�rrrrr,r�r,c�r-rrrrrr�testr/z1BaseEventLoopTests.test_create_task.<locals>.testcseZdZ��fdd�ZdS)z6BaseEventLoopTests.test_create_task.<locals>.EventLoopcs�|�d�Sr0r�r6r.�r,rJrrr5rzBBaseEventLoopTests.test_create_task.<locals>.EventLoop.create_taskN)rBrCrDr5rrDrr�	EventLoopsrEr�F)	r
r4rrIrNrr�Z_log_destroy_pendingr\)r6rBrEr.r�rrDr�test_create_tasks
z#BaseEventLoopTests.test_create_taskc	Cs�dd�}t��}|��tjdd��.}|�t��tj|�|d�Wd�n1s+wY|�t	|�d�Wd�dS1sCwYdS)Nc�r-rrrrrrrB%r/zCBaseEventLoopTests.test_create_task_error_closes_coro.<locals>.testT)�recordr�r)
r
�new_event_loopr\�warnings�catch_warningsrRr_rr2r�)r6rBrJ�wrrr�"test_create_task_error_closes_coro$s�"�z5BaseEventLoopTests.test_create_task_error_closes_coroc	Cs^dd�}t��}|j|�dd�}z|�|��d�W|�|�|��dS|�|�|��w)Nc�r-rrrrrrrB0r/zLBaseEventLoopTests.test_create_named_task_with_default_factory.<locals>.test�	test_task�r')r
rHr5r2�get_namerar\)r6rBrJr�rrr�+test_create_named_task_with_default_factory/s

�
z>BaseEventLoopTests.test_create_named_task_with_default_factoryc	Cspdd�}dd�}t��}|�|�|j|�dd�}z|�|��d�W|�|�|��dS|�|�|��w)NcSstj||d�Sr0)r
r4r1rrr�task_factory<rzSBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.task_factoryc�r-rrrrrrrB?r/zKBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.testrMrN)r
rHr)r5r2rOrar\)r6rQrBrJr�rrr�*test_create_named_task_with_custom_factory;s


�
z=BaseEventLoopTests.test_create_named_task_with_custom_factorycCsldd�}t��|j_t��|j_z	|j�|��Wn	ty"Ynw|j��t�	�|�
|jjj�dS)Nc���t�r��KeyboardInterruptrrrr�raise_keyboard_interruptOr/zXBaseEventLoopTests.test_run_forever_keyboard_interrupt.<locals>.raise_keyboard_interrupt)rrKrJrUZcall_exception_handlerrarUr\rr	r[r��r6rVrrr�#test_run_forever_keyboard_interruptKs�
z6BaseEventLoopTests.test_run_forever_keyboard_interruptcs�dd�}t���j_z	�j�|��Wn	tyYnw��fdd��d�_z
�j����j��Wn	ty=Ynw��	�j�dS)Nc�rSrrTrrrrrVar/zZBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.raise_keyboard_interruptcs�j��d�_dSr�)rJr�r�r��funcr6rrrZk�

zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcF)
rrKrJrUrarUr�r�r`r]rWrrYr�%test_run_until_complete_baseexception^s ��z8BaseEventLoopTests.test_run_until_complete_baseexceptionc	s�t��d�d�����fdd�}���fdd����fdd��|�j_�f�jjj_tdd	�D],}��d
|���j��jj	��j�
����d�Wd�n1sVwYq/dS)Nrcs�|vr�j����dSdSr�rJr�)Z
event_list)�do_event�doer�event_sentinelr6rr�proc_events}s�zZBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.proc_eventscs�d7��j���dS�Nr0r]r)�	callcount�clear_selectorr6rrr^�szWBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.do_eventcs���d�jjj_dSrF)rorJrLrMr#r)r_r6rrrd�sz]BaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.clear_selectorr0r
z	Loop %d/2)�objectrJrUrLrMr#r�ZsubTestr�r�r`r2)r6ra�ir)rcrdr^r_r`r6r�2test_single_selecter_event_callback_after_stoppingvs 
���zEBaseEventLoopTests.test_single_selecter_event_callback_after_stoppingcsDd��fdd�}t��|j_|j�|�t�|j�|��d�dS)Nrcs�d7�dSrbrr��countrr�callback�sz2BaseEventLoopTests.test_run_once.<locals>.callbackr0)rrKrJrUr�r"Zrun_oncer2)r6rjrrhr�
test_run_once�sz BaseEventLoopTests.test_run_oncecCs4t��|j_|j��|j��|jjj�d�dS�Nr)	rrKrJrUr�r`rLrMZassert_called_once_withrOrrr�test_run_forever_pre_stopped�s

z/BaseEventLoopTests.test_run_forever_pre_stoppedc�sH�dddd���fdd�}|�}|������fdd��t�����S)NF)�started�stopped�	finalizedc	s4�d�d<zdD]}|VqWd�d<dSd�d<w)NTrn)ZZEROZONEZTWO�THREEZFOURrpr��item)�statusrr�agen�s��z;BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.agenc�sN�z	���IdH}Wn
tyYdSw|dkrd�d<dSt����dS)NrqTro)�	__anext__�StopAsyncIterationr
r5rr�Zai�iter_onertrrry�s��z?BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.iter_one)�	__aiter__r
r5)r6ruZagrrxr�leave_unfinalized_asyncgen�s��
z-BaseEventLoopTests.leave_unfinalized_asyncgencCs�t��|j_t��|j_t���E|j�|���}|ds't	�
|j�|dr|�|d�|�|d�|�|d�t�
�t	�
|j�|�|d�Wd�dS1sXwYdS)Nrornrp)rrKrJrUrVr�
disable_gcrar{r"r�r]r[r	�r6rtrrr� test_asyncgen_finalization_by_gc�s
�"�z3BaseEventLoopTests.test_asyncgen_finalization_by_gccCs�t��|j_t��|j_|j�d�t���M|j�|�	��}|ds-t
�|j�|dr#|�|d�|�|d�|�
|d�|j�|j�dtj��t
�|j�|�|d�Wd�dS1sfwYdS)NTrornrp)rrKrJrUrVr�rr|rar{r"r�r]r[�run_in_executorr	r}rrr�0test_asyncgen_finalization_by_gc_in_other_thread�s"
��"�zCBaseEventLoopTests.test_asyncgen_finalization_by_gc_in_other_thread)0rBrCrDrHrZrbrnrprr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr r(r+r8rArFrLrPrRrXr\rgrkrmr{r~r��
__classcell__rrrPrrE�sZ
			/L$0"rEc@�BeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�MyProtoNFcCs&d|_d|_|rt����|_dSdS�N�INITIALr)�state�nbytesr
Zget_running_loopr^�done)r6r^rrr�__init__�s
�zMyProto.__init__cGs$|j|vrtd|j�d|����dS�Nzstate: z, expected: �r��AssertionError�r6Zexpectedrrr�
_assert_state��
�zMyProto._assert_statecCs$||_|�d�d|_|�d�dS)Nr��	CONNECTEDs%GET / HTTP/1.0
Host: example.com

)�	transportr�r��write�r6r�rrr�connection_made�s
zMyProto.connection_madecC� |�d�|jt|�7_dS)Nr��r�r�r��r6�datarrr�
data_received�
zMyProto.data_receivedcCs|�d�d|_dS)Nr��EOF)r�r�rOrrr�eof_receivedr[zMyProto.eof_receivedcCs,|�dd�d|_|jr|j�d�dSdS)Nr�r��CLOSED�r�r�r�r��r6r�rrr�connection_losts
�zMyProto.connection_lostr�)
rBrCrDr�r�r�r�r�r�r�rrrrr��s
r�c@r�)�MyDatagramProtoNFcCs"d|_d|_|r|��|_dSdSr�)r�r�r^r�)r6r^rJrrrr�s
�zMyDatagramProto.__init__cCs$|j|krtd|j�d|����dSr�r�r�rrrr�r�zMyDatagramProto._assert_statecCs||_|�d�d|_dS)Nr��INITIALIZED)r�r�r�r�rrrr�s

zMyDatagramProto.connection_madecCr��Nr�r�)r6r��addrrrr�datagram_received$r�z!MyDatagramProto.datagram_receivedcCs|�d�dSr�)r�r�rrr�error_received(rzMyDatagramProto.error_receivedcCs*|�d�d|_|jr|j�d�dSdS)Nr�r�r�r�rrrr�+s

�zMyDatagramProto.connection_lost)FN)
rBrCrDr�r�r�r�r�r�r�rrrrr�s
r�cs�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?e�ejdhkdi�djdk��Z@dldm�ZAdndo�ZBedpdq��ZCedrds��ZDdtdu�ZEe�dv�dwdx��ZFdydz�ZGe�dv�d{d|��ZH�ZIS)}�BaseEventLoopWithSelectorTestscs$t���t��|_|�|j�dSr)rGrHr
ZSelectorEventLooprJrNrOrPrrrH4s

z$BaseEventLoopWithSelectorTests.setUpzsocket.getnameinfocCs.dd�|_|j�|j�d��}|�|d�dS)NcWrc)N�*rrrrrre;rfzABaseEventLoopWithSelectorTests.test_getnameinfo.<locals>.<lambda>)�abcr�r�)�side_effectrJra�getnameinfor2)r6Zm_gai�rrrr�test_getnameinfo9s
z/BaseEventLoopWithSelectorTests.test_getnameinfocs�Gdd�dtj�}dd����fdd�}d�dd	g���fd
d�}||_|�j_�j�|dd
�}��t��}�j�|�Wd�n1sFwY��	t
|j�d�dS)Nc@r�)zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.MyProtoNr�rrrrr�Br�r�c�s
�ddgS�N�r�r0�r-)z107.6.106.82�Pr�rt�kwrrrr$E���zZBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfoc��j��|i|���Sr�rJr5�rt�kwds�r$r6rr�getaddrinfo_taskI�z_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_taskr�Zerr1Zerr2cs�d7�t����rb)�OSErrorr�)�errors�idxrr�_socketOszVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socket�example.comr�zMultiple exceptions: err1, err2)r
�ProtocolrrJr$�create_connectionrRr�rar2�strr)r6r&r�r�r�r.�cmr)r�r$r�r6r�&test_create_connection_multiple_errors?s�zEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errorsc	s�t��}||j_�fdd�}|�j_tjj�jdtj	d��4�j�
tdd�}��tj	���j�
|�Wd�n1s=wY��|jj�Wd�dS1sTwYdS)Ncs,�j��}tjtjdddf}|�|g�|S)Nrr-)�	127.0.0.1r�)rJr^rrrr�)rtr�r�r�rOrrr$ds
�zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfo�sock_connect)r�r�r�)rrKrr#rJr$r)rer
�TimeoutErrorr�r�rRrar]r\r�)r6r&�sockr$r.rrOr�test_create_connection_timeout^s��"�z=BaseEventLoopWithSelectorTests.test_create_connection_timeoutcC�,|jjtddt�d�}|�t|jj|�dS)Nr�r��r�)rJr�r�rerRr�rarCrrr�%test_create_connection_host_port_socks�
�zDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sockc	C�t�tjtj�}|�5|jjt|d�}|�td��|j�|�Wd�n1s*wYWd�dSWd�dS1sBwYdS�Nr�zA Stream Socket was expected)	rrrrJr�r�r�r�ra�r6r�r.rrr�!test_create_connection_wrong_sockx����"�z@BaseEventLoopWithSelectorTests.test_create_connection_wrong_sockc	Cr�r�)	rrrrJ�
create_serverr�r�r�rar�rrr�test_create_server_wrong_sock�r�z<BaseEventLoopWithSelectorTests.test_create_server_wrong_sockcC�R|jjtdddd�}|�td��|j�|�Wd�dS1s"wYdS�Nr�r�r0)�ssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)rJr�r�r�r�rarCrrr�/test_create_server_ssl_timeout_for_plain_socket����"�zNBaseEventLoopWithSelectorTests.test_create_server_ssl_timeout_for_plain_socket�
SOCK_NONBLOCKz$no socket.SOCK_NONBLOCK (linux only)cCsxt�tjtjtjB�}|�%|jjdd�|d�}|j�|�}|��|j�|���Wd�dS1s5wYdS)NcSr�rrrrrrre�rfzRBaseEventLoopWithSelectorTests.test_create_server_stream_bittype.<locals>.<lambda>r�)	rrrr�rJr�rar\�wait_closed)r6r�r.�srvrrr�!test_create_server_stream_bittype�s�"�z@BaseEventLoopWithSelectorTests.test_create_server_stream_bittypezno IPv6 supportc
sl�fdd�}z
�j�|��WdSty5}zttd�r)|jtjkr)��d�n�WYd}~dSd}~ww)Nc�sb�t�dd�dd�IdH}z��t|j�d�W|��|��IdHdS|��|��IdHw)NcSr�rrrrrrre�rfzVBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main.<locals>.<lambda>�::1r)r
Zstart_serverZ
assertGreaterr��socketsr\r�)r�rOrr�main�s��zDBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main�
EADDRNOTAVAILzfailed to bind to ::1)rJrar�r�errnor�ZskipTest)r6r��exrrOr�test_create_server_ipv6�s
���z6BaseEventLoopWithSelectorTests.test_create_server_ipv6c	Cs�t�tj�}|�5|jjt|d�}|�td��|j�|�Wd�n1s(wYWd�dSWd�dS1s@wYdS)Nr�zA UDP Socket was expected)rrrJ�create_datagram_endpointr�r�r�rar�rrr�(test_create_datagram_endpoint_wrong_sock�s���"�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_wrong_sockcC�"|j�t�}|�t|jj|�dSr�rJr�r�rRr�rarCrrr�(test_create_connection_no_host_port_sock��zGBaseEventLoopWithSelectorTests.test_create_connection_no_host_port_sockcsDdd����fdd�}|�j_�j�tdd�}��t�jj|�dS)Nc�s�gSrrr�rrrr$�r/zYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfocr�rr�r�r�rrr��r�z^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_taskr�r�)rJr$r�r�rRr�ra�r6r�r.rr�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�s�dgSr�rr�rrrr$�s�zVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfocr�rr�r�r�rrr��r�z[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_taskr�r�)rJr$rrKr�r�r�r�r�rRrar�rr�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�dS1s<wYdS)Nc��
�ddgS�N)r�r0r�r-)�0.0.0.1r�)r�r0r�r-)z0.0.0.2r�rr�rrrr$�r�zSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfocr�rr�r�r�rrr��r�zXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_taskr�r���family)
rJr$rrKr�r�r�r�r�rrrRrar�rr�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�n1sGwY��t|j��d����|jjjj�dS)
NcSs"|ddkrtd�}d|_|�dS)Nrr��Err)r��strerror)r��errrrr�bind�s
�z^BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.bindc�r�r�rr�rrrr$�r�zeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfocr�rr�r�r�rrr��r�zjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_taskZErr2r�r��Ni��r��
local_addrzMultiple exceptions: )rr#r�rJr$rrKr�r�r�r�r�rrRrar]r�r�
startswithr\r�)r6r&r�r�r.r�rr�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�
|�\}}z*|j�d�|jj\}}|�|d|j�|�|d|j�W|��t�|j�n|��t�|j�wtjr�tj|_|j�
tjdd�}|j�
|�\}}z@|jjd\}	|	dd	�\}
}|�|
d
�|�|d�|jj\}}|�|d|j�|�|d|j�W|��t�|j�dS|��t�|j�wdS)NFr/r��r/r�r�r'r�rr�z	::(0\.)*1)rrr$r#rrKrJ�_add_readerr%�_add_writerr�r
r�ra�connectrr�r2rrr\r"r�r	r5rr��assertRegex)r6r&Zallow_inet_ptonr�r.r��p�_ru�address�host�portrrr�_test_create_connection_ip_addrsH

���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�|�\}}z+|j�d�|jj\}}|�|d|j�|�|d|j�W|��t�|j�dS|��t�|j�w)NFz	fe80::1%1r�)zfe80::1r�rr0r�r')rr$r#rr�rrKrJr�r%rr�r
r�rarrr�r2rr\r"r�)r6r&r�r.r�rrrurrr�!test_create_connection_ipv6_scope0s$

�z@BaseEventLoopWithSelectorTests.test_create_connection_ipv6_scopecC�|�|d�dSr��rr@rrr�test_create_connection_ip_addrI�z=BaseEventLoopWithSelectorTests.test_create_connection_ip_addrcCr
rdrr@rrr�#test_create_connection_no_inet_ptonMr
zBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptonc

Cs0tj|_|jj}t��|j_d|jj_t��|j_d|jj_dD]L\}}|j�	t
jd|�}|j�|�\}}z,|j
�d|f�|jj\}}	|�|	d|j�|�|	d|j�W|��t�|j�q |��t�|j�wdD]&}|j�	t
jd|�}|�t��|j�|�Wd�n1s�wYqodS)NF))�httpr�)shttpr�r�r�r')Znonsensesnonsense)rr$r#rrKrJr�r%rr�r
r�rarrr�r2rrr\r"r�rRr�)
r6r&r�Zservicerr.r�rrrurrr�#test_create_connection_service_nameQs:


��
����zBBaseEventLoopWithSelectorTests.test_create_connection_service_namecsLdd����fdd�}|�j_�jjtddtjdd�}��t�jj|�dS)	Nc�s�|dkr	ddgSgS)Nr�r�r)rrtr�rrrr$qs��zXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfocr�rr�r�r�rrr�xr�z]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_taskr�r�r�r�)	rJr$r�r�rrrRr�rar�rr�r�$test_create_connection_no_local_addrps
�
�zCBaseEventLoopWithSelectorTests.test_create_connection_no_local_addrcs>d���fdd�}||_|��}�j�|��}�j�|�dS)N)z00:01:02:03:04:05r0cs$��||f��dddd�dffgS)Ni�r0r-)r2)rrrtr��r�r6rrr$�szTBaseEventLoopWithSelectorTests.test_create_connection_bluetooth.<locals>.getaddrinfo)r$rrJr�ra)r6r&r$r�r.rrr� test_create_connection_bluetooth�s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�)rJr^r�rrr�SOL_TCP)rtr�r*rOrr�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)rrK)r6�keyrrr�get_extra_info�rz�BaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.get_extra_infocSs|j��dSr)�_sockr\rOrrrr\�rzwBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.close)rBrCrDrrr\rrrr�_SelectorTransportMock�srcs|�d���}||_|Sr)r�r)r��protocolZ
sslcontext�waiterr�r�)rrr�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)rrr�r-)rrKrJr$r�r�r^r#r�rT�ANYrerr�r�rar\r)r6rrr Zhandshake_timeoutr.r�rr)rr6r�2test_create_connection_ssl_server_hostname_default�sj
	
�����
�zQBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_defaultcCsP|jjtdddd�}|�t|jj|�|jjtdddd�}|�t|jj|�dS)Nrr�r-)rr�rCrrr�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)rr�)	rJr�r�rRr�rarr�r\)r6r.r�rrr�1test_create_connection_ssl_server_hostname_errors�s�zPBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_errorscCr�r�)rJr�r�r�r�rarCrrr�3test_create_connection_ssl_timeout_for_plain_socket�r�zRBaseEventLoopWithSelectorTests.test_create_connection_ssl_timeout_for_plain_socketcsXt���fdd����fdd�}|�j_�j�tdd�}��t�jj|�����dS)Nc�s�|d�gSrlrr�)rrrr$�s�zQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfocr�rr�r�r�rrr�r�zVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_taskr-r)	rerJr$r�r�rRr�rar4)r6r�r�r)r$rr6r�test_create_server_empty_host�sz<BaseEventLoopWithSelectorTests.test_create_server_empty_hostcCr�)N�0.0.0.0rr�)rJr�r�rerRr�ra�r6r�rrr�!test_create_server_host_port_sockr�z@BaseEventLoopWithSelectorTests.test_create_server_host_port_sockcCr�r)rJr�r�rRr�rar'rrr�$test_create_server_no_host_port_sock
r�zCBaseEventLoopWithSelectorTests.test_create_server_no_host_port_sockcCsNt��}|j_|j��|_|j�d�|j�tdd�}|�	t
|jj|�dS)Nrr)rrKrJr$r^r#r�r�r�rRr�ra)r6r$r*rrr�!test_create_server_no_getaddrinfos
z@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfocCsBtj|_|`t��|j_|jjtdddd�}|�	t
|jj|�dS)Nr&rT��
reuse_port)rr$�SO_REUSEPORTrrKr#rJr�r�rRr�ra�r6r&r*rrr� test_create_server_nosoreuseports�z?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseportcCsDtj|_t��|j_d|_|jjtdddd�}|�	t
|jj|�dS)Nr�r&rTr+)rr$rrKr#r-rJr�r�rRr�rar.rrr�+test_create_server_soreuseport_only_defined$s�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)rBrCrDr�rrrrr�2sr�)r�r0r�r-)r�it'Fr&r)r�r$r#r%rrKrr�r�rJr�r�rRrar]r\r��r6r&r�Zm_sockr�rrr�test_create_server_cant_bind/s�z;BaseEventLoopWithSelectorTests.test_create_server_cant_bindcCs6g|j_d|j_|jjtdd�}|�t|jj|�dS)NF)�	localhostr�r�)	r$r#r%rJr�r�rRr�ra�r6r&r.rrr�)test_create_datagram_endpoint_no_addrinfo?s�
�zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfocCsH|jjtdd�}|�t|jj|�|jjtdd�}|�t|jj|�dS)Nr3r4)r3r0r�r
)rJr�r�rRr�rarCrrr�(test_create_datagram_endpoint_addr_errorIs�
��
�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errorcCs>t��|j_t|jj_|jjtjdd�}|�	t|jj
|�dS)N�r�r)�remote_addr)rrKrJr�r�r�r�r
�DatagramProtocolrRrarCrrr�)test_create_datagram_endpoint_connect_errSs
�
�zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_connect_errcs�td|jd��t��|j_}g|_|jj�fdd�ddd�}|j�|�\}}|�|j	�|�
�|j��j�|�d�j
�dS)NT�r^rJc��Srrr�rrrrebrfz^BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcast.<locals>.<lambda>r8)r9�allow_broadcastr�)r�rJrrKr�r#r�rar[r�r\r�r2r�)r6r�r.r�rrr>r�-test_create_datagram_endpoint_allow_broadcast\s
�zLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcastcCs^tj|_t|j_|jjtjtjd�}|�	t|jj
|�|jjtjdd�}|�	t|jj
|�dS)Nr�r8r4)rr$r�r�rJr�r
r:rrRrar5rrr�(test_create_datagram_endpoint_socket_errms�
��
�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_socket_errzIPv6 not supported or enabledcCs*|jjtjddd�}|�t|jj|�dS)Nr8)r�r)r9r��rJr�r
r:rRr�rarCrrr�0test_create_datagram_endpoint_no_matching_family|s�
�zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_matching_familycCsHt|jjj_|jjtjtj	d�}|�
t|jj|�|�|jjj
j�dS)Nr�)r�rr#�setblockingr�rJr�r
r:rrRrar]r\r�r5rrr�(test_create_datagram_endpoint_setblk_err�s�
�
�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_setblk_errcCs$|j�tj�}|�t|jj|�dSrrBrCrrr�-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@r�)zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bind.<locals>.ErrNr�rrrrr��r�r�r8)r�r�)r�rr$rrKr#r�r�rJr�r�rrRrar]r\r�r1rrr�'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)Nr8c�td�jd�S�NTr<�r�rJrrOrrre��zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>r�r�)rrrr�rJr�rar\r�r2r�)r6r�r�r�rrrOr�"test_create_datagram_endpoint_sock�s

�zABaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock�AF_UNIXzNo UNIX Socketscsd�jj�fdd�tjd�}�j�|�\}}��|jjtj�|���j�|j	���d|j
�dS)NcrHrIrJrrOrrre�rKzXBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unix.<locals>.<lambda>r�r�)rJr�rrMrar2rr�r\r�r�)r6r�r�rrrOr�'test_create_datagram_endpoint_sock_unix�s
�zFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unixcs�t���<}tjtjtjd�}|�|�|���jj�fdd�|tjd�}�j�	|�\}}|���j�	|j
�Wd�dS1sCwYdS)N)r'crHrIrJrrOrrre�rKzaBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unix.<locals>.<lambda>r�)r"Zunix_socket_pathrrMrr�r\rJr�rar�)r6�pathr�r.r�rrrOr�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)rBrCrDrrr'rrrr�FakeSock�s
rQr8)r�r�)r9r�r0)r�r�)�protor�)�flagsr�T)r,r�)r?r�)rJr�r�rRr�ra)r6rQr�rrr�+test_create_datagram_endpoint_sock_sockopts�s:�������zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockopts�vxworksz-SO_BROADCAST is enabled by default on VxWorkscs4�jj�fdd�dd�}�j�|�\}}|�d�}ttd�}|r+��|�tjtj	����|�tjtj
��|���j�|j���
d|j��jj�fdd�d|d	d
�}�j�|�\}}|�d�}��|�tjtj��|r{��|�tjtj	����|�tjtj
��|���j�|j���
d|j�dS)NcrHrIrJrrOrrre�rKzWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>r8r4rr-r�crHrIrJrrOrrrerKT)r�r,r?)rJr�rarrrr[�
getsockoptrr-�SO_BROADCASTr\r�r2r�rr])r6r.r�rr��reuseport_supportedrrOr�&test_create_datagram_endpoint_sockopts�s`
�

����
�
������zEBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockoptscsV�jj�fdd�ddd�}��t���j�|�Wd�dS1s$wYdS)NcrHrIrJrrOrrrerKzbBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_error.<locals>.<lambda>r8T�r�Z
reuse_address)rJr�rRr�rarCrrOr�1test_create_datagram_endpoint_reuse_address_errors
�"�zPBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_errorcs~�jj�fdd�ddd�}��t��#�j�|�\}}|���j�|j���d|j�Wd�dS1s8wYdS)NcrHrIrJrrOrrre(rKzdBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warning.<locals>.<lambda>r8FrZr�)	rJr�r�r�rar\r�r2r�)r6r.r�rrrOr�3test_create_datagram_endpoint_reuse_address_warning$s
�"�zRBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warningcs@|`t��|j_�jj�fdd�ddd�}��t�jj	|�dS)Nc�t�jd�Sr0rJrrOrrre8r3z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>r8T�r�r,)
r-rrKrr#rJr�rRr�rar5rrOr�+test_create_datagram_endpoint_nosoreuseport2s
�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�dS|��t��j�w)
Ncs��d�dS)Nz"should not have called getaddrinfo)Zfailr�rOrrr$@rzYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfoFr-cr]r0rJrrOrrreJr3zVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>r;r^)r�rRr')r$rrKrr#r�rJr�r%rr�rarrrrr\r"r�)r6r&r$r�rXr.r�rrrOr�%test_create_datagram_endpoint_ip_addr>s,


�

��zDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addrcCs2t��}t�|j_|j�t|�|�|j	j
�dSr)rrK�BlockingIOError�acceptr�rJ�_accept_connectionr�r[r\r��r6r�rrr�test_accept_connection_retryXs
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)rrK�filenor#r�r�ZEMFILErbr�rJZ_remove_readerr�rcr�r]r�r�r[r\rrZACCEPT_RETRY_DELAYr )r6Zm_logr�rrr� test_accept_connection_exception_s�z?BaseEventLoopWithSelectorTests.test_accept_connection_exceptionc	Cs�|�t��tjdd��}Wd�n1swY|j�d�|}|�}|�|j�||fD]�}|�t	��|j�
|�Wd�n1sIwY|�t	��|j�|�Wd�n1sdwY|�t	��|j�d|�Wd�n1s�wY|�t	��|j�
|j��d|�Wd�n1s�wY|�t	��|j�|j�d|��Wd�n1s�wYq1dS)NcSr�rrrrrr�simple_coroutinesszLBaseEventLoopWithSelectorTests.test_call_coroutine.<locals>.simple_coroutineTr�)r�r�r
�	coroutinerJr�r�r\rRr�r�r�r�r�r�rar)r6riZ	coro_funcZcoro_objrZrrr�test_call_coroutineqs8���������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�rrr�stop_loop_cb�rzLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cbc���|��dSrrlr�rrr�stop_loop_coro���zNBaseEventLoopWithSelectorTests.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
rNrJr�Zslow_callback_durationr�r`�warningr�r�tupler)r6Zm_loggerrmro�fmtrtrrr�test_log_slow_callbacks�s"
�
�z6BaseEventLoopWithSelectorTests.test_log_slow_callbacks)JrBrCrDrHrr)r�r+r�r�r�r�r�r��unittest�
skipUnlessrrr�r	r5r�r�r�r�r�r�r�rZskipIfr��platformr�r	rrrrrr!r"r#r$r%r(r)r*r/r0r2r6r7r;r@rArCrErFrGrLrNZskip_unless_bind_unix_socketrPrTrYr[r\r_r`rerhrkrtr�rrrPrr�2s�


�
	

+�



I	





	
	








 �
/


r�c@rq)�RunningLoopTestscCs�dd�}t��}t��}z3|�td��|�||��Wd�n1s%wYW|��|��dSW|��|��dS|��|��w)Nc�rnr)r`r�rrr�runner�rpz@RunningLoopTests.test_running_loop_within_a_loop.<locals>.runnerzwhile another loop is running)r
rHr�r_rar\)r6ryrJZ
outer_looprrr�test_running_loop_within_a_loop�s ����
z0RunningLoopTests.test_running_loop_within_a_loopN)rBrCrDrzrrrrrx�srxcs�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|_dSrd)rn�closed�	bytearrayr�r^r�r�)r6rJrrrr��s


z*BaseLoopSockSendfileTests.MyProto.__init__cCsd|_||_dSr�)rnr�r�rrrr��s
z1BaseLoopSockSendfileTests.MyProto.connection_madecCs|j�|�dSr)r��extendr�rrrr��sz/BaseLoopSockSendfileTests.MyProto.data_receivedcCsd|_|j�d�d|_dSr�)r|r�r�r�r�rrrr��s
z1BaseLoopSockSendfileTests.MyProto.connection_lostc�s�|jIdHdSrr�rOrrrr��s�z-BaseLoopSockSendfileTests.MyProto.wait_closedN)rBrCrDr�r�r�r�r�rrrrr��sr�csTtj|_dt_ttjd��}|�|j�Wd�n1swYt��	�dS)Ni@�wb)
r�!SENDFILE_FALLBACK_READBUFFER_SIZE�'_BaseLoopSockSendfileTests__old_bufsize�openr�TESTFNr��DATArG�
setUpClass)�cls�fprPrrr��s�z$BaseLoopSockSendfileTests.setUpClasscs"|jt_t�tj�t���dSr)r�rr�r�unlinkr�rG�
tearDownClass)r�rPrrr��sz'BaseLoopSockSendfileTests.tearDownClasscsJddlm}|�|_|�|j�ttjd�|_|�|jj	�t
���dS)Nr)�BaseSelectorEventLoop�rb)Zasyncio.selector_eventsr�rJrNr�rr��filer�r\rGrH)r6r�rPrrrH�szBaseLoopSockSendfileTests.setUpFcCs*t�tjtj�}|�|�|�|j�|Sr)rrrrDr�r\)r6�blockingr�rrr�make_socket�s
z%BaseLoopSockSendfileTests.make_socketcCs|j�|�Sr)rJrarCrrrr�rz"BaseLoopSockSendfileTests.run_loopc	s��������j�����jj�fdd�tjdtjd����j	d�
�}td�D]!}z���j��|��Wnt
yG��t�d��Yq(wn
���j��|������fdd�}��|���fS)	Ncr=rrr)rRrrre�rfz3BaseLoopSockSendfileTests.prepare.<locals>.<lambda>rr�rfg�?csH�������������jdur"�j��������dSdSr)r\rr�r�r�rRr6Zserverr�rr�cleanups

�z2BaseLoopSockSendfileTests.prepare.<locals>.cleanup)r�r�rJrr�r	ZHOSTrrr��getsocknamer�r�r�r
r�r�)r6r�rr�rr�r�prepare�s$
��
z!BaseLoopSockSendfileTests.preparec	Csx|��\}}|�tjd��|�|j�||jdd��Wd�n1s%wY|�|j	d�|�|j�
�d�dS)N�sendfile is not availablerr<)r�r�r
�SendfileNotAvailableErrorrrJZ_sock_sendfile_nativer�r2r��tell�r6r�rRrrr�"test__sock_sendfile_native_failures���z<BaseLoopSockSendfileTests.test__sock_sendfile_native_failurecCsx|��\}}|�tjd��|�|jj||jdd��Wd�n1s%wY|�|j�	�d�|�|j
d�dS)Nr�F)�fallbackrr<)r�r�r
r�rrJ�
sock_sendfiler�r2r�r�r�rrr�test_sock_sendfile_no_fallbacks�
��z8BaseLoopSockSendfileTests.test_sock_sendfile_no_fallbackcCsv|��\}}|�|j�||j��}|��|�|���|�|t|j	��|�|j�
�t|j	��|�|j|j	�dSr)r�rrJr�r�r\r�r2r�r�r�r��r6r�rR�retrrr�test_sock_sendfile_fallback'sz5BaseLoopSockSendfileTests.test_sock_sendfile_fallbackcCsv|��\}}|�|j�||jdd��}|��|�|���|�|d�|�|j��d�|�|j	|j
dd��dS)Ni�i�r�)r�rrJr�r�r\r�r2r�r�r�r�rrr�,test_sock_sendfile_fallback_offset_and_count2s�zFBaseLoopSockSendfileTests.test_sock_sendfile_fallback_offset_and_countcCs`|j�d�|jdd�}|�td��|�|j�||j��Wd�dS1s)wYdS)NT)r�zmust be non-blocking)rJr�r�r�r�rr�r�rdrrr�test_blocking_socket>s
"�z.BaseLoopSockSendfileTests.test_blocking_socketc	Cs�|��}ttjdd��1}|�td��|�|j�||��Wd�n1s'wYWd�dSWd�dS1s?wYdS)Nzutf-8)�encodingzbinary mode)	r�r�rr�r�r�rrJr�)r6r�r*rrr�test_nonbinary_fileDs��"�z-BaseLoopSockSendfileTests.test_nonbinary_filecCsnt�tjtj�}|�d�|�|j�|�td��|�|j	�
||j��Wd�dS1s0wYdS)NFzonly SOCK_STREAM type)rrrrDr�r\r�r�rrJr�r�rdrrr�test_nonstream_socketJs
"�z/BaseLoopSockSendfileTests.test_nonstream_socketc	C�T|��}|�td��|�|j�||jdd��Wd�dS1s#wYdS)N� count must be a positive integerrri�r�r�r�rrJr�r�rdrrr�test_notint_countQ��"�z+BaseLoopSockSendfileTests.test_notint_countc	Cr�)Nr�rr��r�r�r�rrJr�r�rdrrr�test_negative_countWr�z-BaseLoopSockSendfileTests.test_negative_countcC�R|��}|�td��|�|j�||jd��Wd�dS1s"wYdS)N�%offset must be a non-negative integer�offsetr�rdrrr�test_notint_offset]��"�z,BaseLoopSockSendfileTests.test_notint_offsetcCr�)Nr�r�r�rdrrr�test_negative_offsetcr�z.BaseLoopSockSendfileTests.test_negative_offsetr�)rBrCrDr�r
r�r��classmethodr�r�rHr�rr�r�r�r�r�r�r�r�r�r�r�r�r�rrrPrr{�s,
	r{c@s.eZdZdd�Ze�eed�d�dd��ZdS)�TestSelectorUtilscCsB|�tjtj�}|�|�t�|�|�tjtj�}|�|�dSr)rVrr�TCP_NODELAYr[rZ_set_nodelayr])r6r��optrrr�check_set_nodelayks


z#TestSelectorUtils.check_set_nodelayr�zneed socket.TCP_NODELAYcCs�tjtjtjtjd�}|�
|�|�Wd�n1swYtjtjtjtjd�}|�|�d�|�|�Wd�dS1sEwYdS)N)r�r'rRF)rrrrr�rDrdrrr�test_set_nodelayts���
"�z"TestSelectorUtils.test_set_nodelayN)	rBrCrDr�rurvrrr�rrrrr�js	�r��__main__)-�__doc__�concurrent.futuresrxr�r�rr�r�r�rurr
rrZtest.test_asynciorr"rBrZtest.support.script_helperrZtest.supportrr	rIr r�version_infor
rr(r+ZTestCaser,rEr�r�r:r�r�rxr{r�rBr�rrrr�<module>s`
a_" y5�