AlkantarClanX12

Your IP : 3.145.34.237


Current Path : /opt/alt/python310/lib64/python3.10/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/asyncio/__pycache__/base_events.cpython-310.opt-1.pyc

o

6��fe"�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZzddlZWneySdZYnwddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddl m!Z!dZ"dZ#dZ$e%e	d�Z&dZ'e(�Z)dd�Z*dd�Z+dd�Z,d-dd�Z-d.dd�Z.dd �Z/e%e	d!�r�d"d#�Z0nd$d#�Z0d%d&�Z1Gd'd(�d(ej2�Z3Gd)d*�d*ej4�Z5Gd+d,�d,ej6�Z7dS)/a�Base implementation of event loop.

The event loop can be broken up into a multiplexer (the part
responsible for notifying us of I/O events) and the event loop proper,
which wraps a multiplexer with functionality for scheduling callbacks,
immediately or at a given time in the future.

Whenever a public API takes a callback, subsequent positional
arguments will be passed to the callback if/when it is called.  This
avoids the proliferation of trivial lambdas implementing closures.
Keyword arguments for the callback are not supported; this is a
conscious design decision, leaving the door open for keyword arguments
to modify the meaning of the API call itself.
�N�)�	constants)�
coroutines)�events)�
exceptions)�futures)�	protocols)�sslproto)�	staggered)�tasks)�
transports)�trsock)�logger)�
BaseEventLoop�Server�dg�?�AF_INET6i�QcCs,|j}tt|dd�tj�rt|j�St|�S)N�__self__)Z	_callback�
isinstance�getattrr�Task�reprr�str)�handle�cb�r�:/opt/alt/python310/lib64/python3.10/asyncio/base_events.py�_format_handleJs
rcCs$|tjkrdS|tjkrdSt|�S)Nz<pipe>z<stdout>)�
subprocess�PIPE�STDOUTr)�fdrrr�_format_pipeSs


r"cCsBttd�s	td��z|�tjtjd�WdSty td��w)N�SO_REUSEPORTz)reuse_port not supported by socket modulerzTreuse_port not supported by socket module, SO_REUSEPORT defined but not implemented.)�hasattr�socket�
ValueError�
setsockopt�
SOL_SOCKETr#�OSError��sockrrr�_set_reuseport\s
�r,c		Cspttd�sdS|dtjtjhvs|durdS|tjkrtj}n|tjkr(tj}ndS|dur1d}n+t|t�r=|dkr=d}nt|t�rI|dkrId}nzt	|�}Wnt
tfy[YdSw|tjkrntj
g}trm|�tj�n|g}t|t�r{|�d�}d|vr�dS|D]2}z't�||�tr�|tjkr�|||d||||ffWS|||d||ffWSty�Yq�wdS)N�	inet_ptonr��Zidna�%)r$r%�IPPROTO_TCPZIPPROTO_UDP�SOCK_STREAM�
SOCK_DGRAMr�bytesr�int�	TypeErrorr&�	AF_UNSPEC�AF_INET�	_HAS_IPv6�appendr�decoder-r))	�host�port�family�type�protoZflowinfoZscopeidZafs�afrrr�_ipaddr_infogsR


�
�

�rBcCs�t��}|D]}|d}||vrg||<||�|�qt|���}g}|dkr>|�|dd|d��|dd|d�=|�dd�tj�tj	|��D��|S)z-Interleave list of addrinfo tuples by family.rrNcss�|]	}|dur|VqdS�Nr)�.0�arrr�	<genexpr>�s���z(_interleave_addrinfos.<locals>.<genexpr>)
�collections�OrderedDictr:�list�values�extend�	itertools�chain�
from_iterable�zip_longest)Z	addrinfosZfirst_address_family_countZaddrinfos_by_family�addrr>Zaddrinfos_listsZ	reorderedrrr�_interleave_addrinfos�s"
��rQcCs4|��s|��}t|ttf�rdSt�|���dSrC)�	cancelled�	exceptionr�
SystemExit�KeyboardInterruptrZ	_get_loop�stop)�fut�excrrr�_run_until_complete_cb�s
rY�TCP_NODELAYcCsL|jtjtjhvr |jtjkr"|jtjkr$|�tjtj	d�dSdSdSdS�Nr)
r>r%r8rr?r2r@r1r'rZr*rrr�_set_nodelay�s�r\cCsdSrCrr*rrrr\�scCs$tdurt|tj�rtd��dSdS)Nz"Socket cannot be of type SSLSocket)�sslrZ	SSLSocketr6r*rrr�_check_ssl_socket�s�r^c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�_SendfileFallbackProtocolcCsjt|tj�s
td��||_|��|_|��|_|j	|_
|��|�|�|j
r0|jj
��|_dSd|_dS)Nz.transport should be _FlowControlMixin instance)rrZ_FlowControlMixinr6�
_transportZget_protocol�_protoZ
is_reading�_should_resume_readingZ_protocol_paused�_should_resume_writing�
pause_reading�set_protocol�_loop�
create_future�_write_ready_fut)�self�transprrr�__init__�s



z"_SendfileFallbackProtocol.__init__c�s4�|j��r
td��|j}|durdS|IdHdS)NzConnection closed by peer)r`�
is_closing�ConnectionErrorrh)rirWrrr�drain�s�
z_SendfileFallbackProtocol.draincC�td��)Nz?Invalid state: connection should have been established already.��RuntimeError)ri�	transportrrr�connection_made��z)_SendfileFallbackProtocol.connection_madecCs@|jdur|dur|j�td��n|j�|�|j�|�dS)NzConnection is closed by peer)rh�
set_exceptionrmra�connection_lost)rirXrrrrv�s
�z)_SendfileFallbackProtocol.connection_lostcCs |jdurdS|jj��|_dSrC)rhr`rfrg�rirrr�
pause_writing�s
z'_SendfileFallbackProtocol.pause_writingcCs$|jdurdS|j�d�d|_dS)NF)rh�
set_resultrwrrr�resume_writing�s

z(_SendfileFallbackProtocol.resume_writingcCro�Nz'Invalid state: reading should be pausedrp)ri�datarrr�
data_receivedrtz'_SendfileFallbackProtocol.data_receivedcCror{rprwrrr�eof_receivedrtz&_SendfileFallbackProtocol.eof_receivedc�sL�|j�|j�|jr|j��|jdur|j��|jr$|j��dSdSrC)	r`rerarb�resume_readingrh�cancelrcrzrwrrr�restore	s�


�z!_SendfileFallbackProtocol.restoreN)�__name__�
__module__�__qualname__rkrnrsrvrxrzr}r~r�rrrrr_�sr_c@sxeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
edd��Zdd�Z
dd�Zdd�Zdd�ZdS)rcCs@||_||_d|_g|_||_||_||_||_d|_d|_	dS)NrF)
rf�_sockets�
_active_count�_waiters�_protocol_factory�_backlog�_ssl_context�_ssl_handshake_timeout�_serving�_serving_forever_fut)ri�loop�sockets�protocol_factoryZssl_context�backlog�ssl_handshake_timeoutrrrrks
zServer.__init__cCsd|jj�d|j�d�S)N�<z	 sockets=�>)�	__class__r�r�rwrrr�__repr__%szServer.__repr__cCs|jd7_dSr[)r�rwrrr�_attach(szServer._attachcCs6|jd8_|jdkr|jdur|��dSdSdS)Nrr)r�r��_wakeuprwrrr�_detach,s�zServer._detachcCs,|j}d|_|D]}|��s|�|�qdSrC)r��donery)ri�waiters�waiterrrrr�2s
��zServer._wakeupc	CsJ|jrdSd|_|jD]}|�|j�|j�|j||j||j|j�qdS)NT)	r�r�Zlistenr�rf�_start_servingr�r�r�)rir+rrrr�9s


��zServer._start_servingcC�|jSrC)rfrwrrr�get_loopC�zServer.get_loopcCr�rC)r�rwrrr�
is_servingFr�zServer.is_servingcCs"|jdurdStdd�|jD��S)Nrcss�|]}t�|�VqdSrC)r
ZTransportSocket)rD�srrrrFMs�z!Server.sockets.<locals>.<genexpr>)r��tuplerwrrrr�Is
zServer.socketscCsr|j}|dur	dSd|_|D]}|j�|�qd|_|jdur,|j��s,|j��d|_|jdkr7|��dSdS)NFr)	r�rfZ
_stop_servingr�r�r�r�r�r�)rir�r+rrr�closeOs
�

�zServer.closec�s�|��t�d�IdHdS)Nr)r�r�sleeprwrrr�
start_servingbs�zServer.start_servingc	�s��|jdurtd|�d���|jdurtd|�d���|��|j��|_z&z|jIdHWntjyEz
|��|�	�IdHW��wWd|_dSd|_w)Nzserver z, is already being awaited on serve_forever()z
 is closed)
r�rqr�r�rfrgrZCancelledErrorr��wait_closedrwrrr�
serve_foreverhs&�

�
��zServer.serve_foreverc�s>�|jdus|jdur
dS|j��}|j�|�|IdHdSrC)r�r�rfrgr:)rir�rrrr�}s�
zServer.wait_closedN)r�r�r�rkr�r�r�r�r�r�r��propertyr�r�r�r�r�rrrrrs


rc@s�eZdZdd�Zdd�Zdd�Zdd�d	d
�Zdd�Zd
d�Zd�ddd�dd�Z		d�ddddddd�dd�Z
	d�dd�Z		d�dd�Z		d�dd�Z
	d�dd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zejfd=d>�Z d?d@�Z!dAdB�Z"ddC�dDdE�Z#ddC�dFdG�Z$ddC�dHdI�Z%dJdK�Z&dLdM�Z'dNdO�Z(ddC�dPdQ�Z)dRdS�Z*dTdU�Z+dVdW�Z,dXdXdXdXdY�dZd[�Z-d�d\d]�Z.d�dd^�d_d`�Z/dadb�Z0dcdd�Z1dedf�Z2d�dgdh�Z3	d�ddXdXdXdddddddi�
djdk�Z4		d�dldm�Z5d�dd^�dndo�Z6dpdq�Z7drds�Z8ddddt�dudv�Z9	d�dXdXdXe:ddddw�dxdy�Z;dXe<j=dXdXdY�dzd{�Z>d|d}�Z?	d�e<j@e<jAdd~dddddd�	d�d��ZBddd��d�d��ZCd�d��ZDd�d��ZEd�d��ZFeGjHeGjHeGjHdddXdddd��	d�d��ZIeGjHeGjHeGjHdddXdddd��	d�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUdS)�rcCs�d|_d|_d|_t��|_g|_d|_d|_d|_	t
�d�j|_
d|_|�t���d|_d|_d|_d|_d|_t��|_d|_d|_dS)NrF�	monotonicg�������?)�_timer_cancelled_count�_closed�	_stoppingrG�deque�_ready�
_scheduled�_default_executorZ
_internal_fds�
_thread_id�time�get_clock_infoZ
resolution�_clock_resolution�_exception_handler�	set_debugrZ_is_debug_mode�slow_callback_duration�_current_handle�
_task_factory�"_coroutine_origin_tracking_enabled�&_coroutine_origin_tracking_saved_depth�weakrefZWeakSet�
_asyncgens�_asyncgens_shutdown_called�_executor_shutdown_calledrwrrrrk�s&


zBaseEventLoop.__init__c	Cs.d|jj�d|���d|���d|���d�	S)Nr�z	 running=z closed=z debug=r�)r�r��
is_running�	is_closed�	get_debugrwrrrr��s���zBaseEventLoop.__repr__cCstj|d�S)z,Create a Future object attached to the loop.�r�)rZFuturerwrrrrg�szBaseEventLoop.create_futureN)�namecCsP|��|jdurtj|||d�}|jr|jd=|S|�||�}t�||�|S)zDSchedule a coroutine object.

        Return a task object.
        N)r�r����)�
_check_closedr�rr�_source_tracebackZ_set_task_name)ri�coror�Ztaskrrr�create_task�s
�zBaseEventLoop.create_taskcCs"|durt|�std��||_dS)awSet a task factory that will be used by loop.create_task().

        If factory is None the default task factory will be set.

        If factory is a callable, it should have a signature matching
        '(loop, coro)', where 'loop' will be a reference to the active
        event loop, 'coro' will be a coroutine object.  The callable
        must return a Future.
        Nz'task factory must be a callable or None)�callabler6r�)ri�factoryrrr�set_task_factory�s

zBaseEventLoop.set_task_factorycCr�)z<Return a task factory, or None if the default one is in use.)r�rwrrr�get_task_factory��zBaseEventLoop.get_task_factory)�extra�servercC�t�)zCreate socket transport.��NotImplementedError)rir+�protocolr�r�r�rrr�_make_socket_transport��z$BaseEventLoop._make_socket_transportFT)�server_side�server_hostnamer�r�r��call_connection_madecCr�)zCreate SSL transport.r�)riZrawsockr��
sslcontextr�r�r�r�r�r�r�rrr�_make_ssl_transport��z!BaseEventLoop._make_ssl_transportcCr�)zCreate datagram transport.r�)rir+r��addressr�r�rrr�_make_datagram_transport�r�z&BaseEventLoop._make_datagram_transportcCr�)zCreate read pipe transport.r��ri�piper�r�r�rrr�_make_read_pipe_transport�r�z'BaseEventLoop._make_read_pipe_transportcCr�)zCreate write pipe transport.r�r�rrr�_make_write_pipe_transport�r�z(BaseEventLoop._make_write_pipe_transportc	
�s�t�)zCreate subprocess transport.r�)
rir��args�shell�stdin�stdout�stderr�bufsizer��kwargsrrr�_make_subprocess_transport�s�z(BaseEventLoop._make_subprocess_transportcCr�)z�Write a byte to self-pipe, to wake up the event loop.

        This may be called from a different thread.

        The subclass is responsible for implementing the self-pipe.
        r�rwrrr�_write_to_self�r�zBaseEventLoop._write_to_selfcCr�)zProcess selector events.r�)ri�
event_listrrr�_process_events�szBaseEventLoop._process_eventscC�|jrtd��dS)NzEvent loop is closed)r�rqrwrrrr���zBaseEventLoop._check_closedcCr�)Nz!Executor shutdown has been called)r�rqrwrrr�_check_default_executorr�z%BaseEventLoop._check_default_executorcCs.|j�|�|��s|�|j|���dSdSrC)r��discardr��call_soon_threadsafer��aclose�ri�agenrrr�_asyncgen_finalizer_hook	s�z&BaseEventLoop._asyncgen_finalizer_hookcCs.|jrtjd|�d�t|d�|j�|�dS)Nzasynchronous generator z3 was scheduled after loop.shutdown_asyncgens() call��source)r��warnings�warn�ResourceWarningr��addr�rrr�_asyncgen_firstiter_hooks
�z&BaseEventLoop._asyncgen_firstiter_hookc�s��d|_t|j�sdSt|j�}|j��tjdd�|D�ddi�IdH}t||�D]\}}t|t	�r?|�
d|��||d��q*dS)z,Shutdown all active asynchronous generators.TNcSsg|]}|���qSr)r�)rDZagrrr�
<listcomp>$sz4BaseEventLoop.shutdown_asyncgens.<locals>.<listcomp>Zreturn_exceptionsz;an error occurred during closing of asynchronous generator )�messagerSZasyncgen)r��lenr�rI�clearr�gather�zipr�	Exception�call_exception_handler)riZ
closing_agensZresults�resultr�rrr�shutdown_asyncgenss,�


��
����z BaseEventLoop.shutdown_asyncgensc�s\�d|_|jdurdS|��}tj|j|fd�}|��z|IdHW|��dS|��w)z.Schedule the shutdown of the default executor.TN)�targetr�)r�r�rg�	threadingZThread�_do_shutdown�start�join)ri�future�threadrrr�shutdown_default_executor0s�
z'BaseEventLoop.shutdown_default_executorc
Cs|z|jjdd�|��s|�|jd�WdSWdSty=}z|��s2|�|j|�WYd}~dSWYd}~dSd}~ww)NT��wait)r��shutdownr�r�ryrru)rirZexrrrr=s����zBaseEventLoop._do_shutdowncCs(|��rtd��t��durtd��dS)Nz"This event loop is already runningz7Cannot run the event loop while another loop is running)r�rqrZ_get_running_looprwrrr�_check_runningFs��zBaseEventLoop._check_runningc	Cs�|��|��|�|j�t��}z5t��|_tj	|j
|jd�t�
|�	|��|jr/nq'Wd|_d|_t�
d�|�d�tj	|�dSd|_d|_t�
d�|�d�tj	|�w)zRun until stop() is called.)�	firstiter�	finalizerTFN)r�r�_set_coroutine_origin_tracking�_debug�sys�get_asyncgen_hooksr
�	get_identr��set_asyncgen_hooksr�r�rZ_set_running_loop�	_run_oncer�)riZold_agen_hooksrrr�run_foreverMs4
�
�

�

zBaseEventLoop.run_foreverc	Cs�|��|��t�|�}tj||d�}|rd|_|�t�z z|�	�Wn|r8|�
�r8|��s8|���W|�
t�n|�
t�w|�
�sNtd��|��S)a\Run until the Future is done.

        If the argument is a coroutine, it is wrapped in a Task.

        WARNING: It would be disastrous to call run_until_complete()
        with the same coroutine twice -- it would wrap it in two
        different Tasks and that can't be good.

        Return the Future's result, or raise its exception.
        r�Fz+Event loop stopped before Future completed.)r�rrZisfuturerZ
ensure_futureZ_log_destroy_pendingZadd_done_callbackrYrr�rRrSZremove_done_callbackrqr)rirZnew_taskrrr�run_until_completees$
�	z BaseEventLoop.run_until_completecCs
d|_dS)z�Stop running the event loop.

        Every callback already scheduled will still run.  This simply informs
        run_forever to stop looping after a complete iteration.
        TN)r�rwrrrrV�s
zBaseEventLoop.stopcCst|��rtd��|jr
dS|jrt�d|�d|_|j��|j��d|_	|j
}|dur8d|_
|jdd�dSdS)z�Close the event loop.

        This clears the queues and shuts down the executor,
        but does not wait for the executor to finish.

        The event loop must not be running.
        z!Cannot close a running event loopNzClose %rTFr)r�rqr�rr�debugr�rr�r�r�r�ri�executorrrrr��s

�zBaseEventLoop.closecCr�)z*Returns True if the event loop was closed.)r�rwrrrr��r�zBaseEventLoop.is_closedcCs8|��s|d|��t|d�|��s|��dSdSdS)Nzunclosed event loop r�)r�r�r�r�)riZ_warnrrr�__del__�s�zBaseEventLoop.__del__cCs
|jduS)z*Returns True if the event loop is running.N)r�rwrrrr��s
zBaseEventLoop.is_runningcCst��S)z�Return the time according to the event loop's clock.

        This is a float expressed in seconds since an epoch, but the
        epoch, precision, accuracy and drift are unspecified and may
        differ per event loop.
        )r�r�rwrrrr��szBaseEventLoop.time)�contextcGs4|j|��||g|�Rd|i�}|jr|jd=|S)a8Arrange for a callback to be called at a given time.

        Return a Handle: an opaque object with a cancel() method that
        can be used to cancel the call.

        The delay can be an int or float, expressed in seconds.  It is
        always relative to the current time.

        Each callback will be called exactly once.  If two callbacks
        are scheduled for exactly the same time, it undefined which
        will be called first.

        Any positional arguments after the callback will be passed to
        the callback when it is called.
        r$r�)�call_atr�r�)riZdelay�callbackr$r��timerrrr�
call_later�s�zBaseEventLoop.call_latercGsZ|��|jr|��|�|d�t�|||||�}|jr!|jd=t�|j	|�d|_	|S)z|Like call_later(), but uses an absolute time.

        Absolute time corresponds to the event loop's time() method.
        r%r�T)
r�r�
_check_thread�_check_callbackrZTimerHandler��heapqZheappushr�)ri�whenr&r$r�r'rrrr%�szBaseEventLoop.call_atcGsB|��|jr|��|�|d�|�|||�}|jr|jd=|S)aTArrange for a callback to be called as soon as possible.

        This operates as a FIFO queue: callbacks are called in the
        order in which they are registered.  Each callback will be
        called exactly once.

        Any positional arguments after the callback will be passed to
        the callback when it is called.
        �	call_soonr�)r�rr)r*�
_call_soonr��rir&r$r�rrrrr-�s
zBaseEventLoop.call_sooncCsDt�|�s
t�|�rtd|�d���t|�s td|�d|����dS)Nzcoroutines cannot be used with z()z"a callable object was expected by z(), got )rZiscoroutineZiscoroutinefunctionr6r�)rir&�methodrrrr*�s
�
����zBaseEventLoop._check_callbackcCs.t�||||�}|jr|jd=|j�|�|S)Nr�)rZHandler�r�r:)rir&r�r$rrrrr.s
zBaseEventLoop._call_sooncCs,|jdurdSt��}||jkrtd��dS)aoCheck that the current thread is the thread running the event loop.

        Non-thread-safe methods of this class make this assumption and will
        likely behave incorrectly when the assumption is violated.

        Should only be called when (self._debug == True).  The caller is
        responsible for checking this condition for performance reasons.
        NzMNon-thread-safe operation invoked on an event loop other than the current one)r�r
rrq)riZ	thread_idrrrr)s
	
��zBaseEventLoop._check_threadcGsB|��|jr
|�|d�|�|||�}|jr|jd=|��|S)z"Like call_soon(), but thread-safe.r�r�)r�rr*r.r�r�r/rrrr�sz"BaseEventLoop.call_soon_threadsafecGsh|��|jr
|�|d�|dur&|j}|��|dur&tjjdd�}||_tj|j	|g|�R�|d�S)N�run_in_executorZasyncio)Zthread_name_prefixr�)
r�rr*r�r��
concurrentr�ThreadPoolExecutorZwrap_futureZsubmit)rir"�funcr�rrrr1's��zBaseEventLoop.run_in_executorcCs&t|tjj�st�dtd�||_dS)Nz{Using the default executor that is not an instance of ThreadPoolExecutor is deprecated and will be prohibited in Python 3.9�)rr2rr3r�r��DeprecationWarningr�r!rrr�set_default_executor7s�
z"BaseEventLoop.set_default_executorcCs�|�d|��g}|r|�d|���|r|�d|���|r&|�d|���|r0|�d|���d�|�}t�d|�|��}t�||||||�}	|��|}
d|�d	|
d
d�d|	��}|
|jkrit�|�|	St�|�|	S)
N�:zfamily=ztype=zproto=zflags=�, zGet address info %szGetting address info z took g@�@z.3fzms: )	r:r
rr r�r%�getaddrinfor��info)rir<r=r>r?r@�flags�msg�t0�addrinfo�dtrrr�_getaddrinfo_debug@s(



�z BaseEventLoop._getaddrinfo_debugr�r>r?r@r<c
�s4�|jr|j}ntj}|�d|||||||�IdHSrC)rrAr%r:r1)rir<r=r>r?r@r<Zgetaddr_funcrrrr:Xs�
�zBaseEventLoop.getaddrinfoc�s�|�dtj||�IdHSrC)r1r%�getnameinfo)riZsockaddrr<rrrrCbs�

�zBaseEventLoop.getnameinfo)�fallbackc
�s��|jr|��dkrtd��t|�|�||||�z|�||||�IdHWStjy<}z	|s2�WYd}~nd}~ww|�||||�IdHS)Nrzthe socket must be non-blocking)	rZ
gettimeoutr&r^�_check_sendfile_params�_sock_sendfile_nativer�SendfileNotAvailableError�_sock_sendfile_fallback)rir+�file�offset�countrDrXrrr�
sock_sendfilefs$�����
�zBaseEventLoop.sock_sendfilec�s�t�d|�d|�d���)Nz-syscall sendfile is not available for socket z
 and file z combination�rrG�rir+rIrJrKrrrrFus���z#BaseEventLoop._sock_sendfile_nativec

�s��|r|�|�|rt|tj�ntj}t|�}d}zL	|r)t|||�}|dkr)n(t|�d|�}|�d|j|�IdH}	|	s?n|�||d|	��IdH||	7}q|W|dkrdt	|d�re|�||�SSS|dkrwt	|d�rx|�||�www)NrT�seek)
rO�minrZ!SENDFILE_FALLBACK_READBUFFER_SIZE�	bytearray�
memoryviewr1�readintoZsock_sendallr$)
rir+rIrJrK�	blocksize�buf�
total_sent�view�readrrrrH|s8�
�����z%BaseEventLoop._sock_sendfile_fallbackcCs�dt|dd�vrtd��|jtjkstd��|dur1t|t�s&td�|���|dkr1td�|���t|t�s=td�|���|dkrHtd�|���dS)N�b�modez$file should be opened in binary modez+only SOCK_STREAM type sockets are supportedz+count must be a positive integer (got {!r})rz0offset must be a non-negative integer (got {!r}))	rr&r?r%r2rr5r6�formatrNrrrrE�s4
��
�����z$BaseEventLoop._check_sendfile_paramsc�sX�g}|�|�|\}}}}}	d}
z�zotj|||d�}
|
�d�|durq|D]<\}}}}}||kr2q&z|
�|�Wn6tyb}
zd|�d|
j����}t|
j|�}
|�|
�WYd}
~
q&d}
~
ww|ri|���td|�d���|�	|
|	�IdH|
WWd}}Sty�}
z|�|
�|
dur�|
�
��d}
~
w|
dur�|
�
��d}}w)z$Create, bind and connect one socket.N�r>r?r@Fz*error while attempting to bind on address �: z&no matching local address with family=z found)r:r%�setblocking�bindr)�strerror�lower�errno�pop�sock_connectr�)rirZ	addr_infoZlocal_addr_infosZ
my_exceptionsr>Ztype_r@�_r�r+ZlfamilyZladdrrXr=rrr�
_connect_sock�sV�


�����	
�
�
zBaseEventLoop._connect_sock)
r]r>r@r<r+�
local_addrr�r��happy_eyeballs_delay�
interleavec
	�sd�|
dur|std��|
dur|r|std��|}
|dur#|s#td��|dur+t|�|dur5|
dur5d}
|dus=|dur�|durEtd���j||f|tj||�d�IdH}|s\td��|	durv�j|	|tj||�d�IdH��sutd��nd�|
rt||
�}g�|dur�|D]}z
���|��IdH}Wn	ty�Yq�wntj	���fd	d
�|D�|�d�IdH\}}}|dur�dd
��D��z.t
��dkrΈd�t�d��t�fdd
��D��r�d�td�
d�dd
��D�����d�wn|dur�td��|jtjk�rtd|�����j||||
|d�IdH\}}�j�r.|�d�}t�d|||||�||fS)a�Connect to a TCP server.

        Create a streaming transport connection to a given internet host and
        port: socket family AF_INET or socket.AF_INET6 depending on host (or
        family if specified), socket type SOCK_STREAM. protocol_factory must be
        a callable returning a protocol instance.

        This method is a coroutine which will try to establish the connection
        in the background.  When successful, the coroutine returns a
        (transport, protocol) pair.
        Nz+server_hostname is only meaningful with sslz:You must set server_hostname when using ssl without a host�1ssl_handshake_timeout is only meaningful with sslr�8host/port and sock can not be specified at the same time�r>r?r@r<r��!getaddrinfo() returned empty listc3s"�|]}t��j�|��VqdSrC)�	functools�partialrf)rDr?)r�laddr_infosrirrrF+s���z2BaseEventLoop.create_connection.<locals>.<genexpr>r�cSsg|]	}|D]}|�qqSrr)rD�subrXrrrr�1sz3BaseEventLoop.create_connection.<locals>.<listcomp>rc3s�|]	}t|��kVqdSrC�r�rDrX)�modelrrrF8s�zMultiple exceptions: {}r9css�|]}t|�VqdSrCrrrsrrrrF=s�z5host and port was not specified and no sock specified�"A Stream Socket was expected, got )r�r%z%r connected to %s:%r: (%r, %r))r&r^�_ensure_resolvedr%r2r)rQrfr
Zstaggered_racerr�allr[r
r?�_create_connection_transportr�get_extra_inforr )rir�r<r=r]r>r@r<r+rgr�r�rhri�infosr?rerrr�r)rrprtrir�create_connection�s����
���

����������

�zBaseEventLoop.create_connectionc	�s~�|�d�|�}|��}|r%t|t�rdn|}	|j|||	||||d�}
n|�|||�}
z
|IdHW|
|fS|
���)NF�r�r�r�)r^rgr�boolr�r�r�)rir+r�r]r�r�r�r�r�r�rrrrrrxZs$�
��z*BaseEventLoop._create_connection_transportc
�s��|��r	td��t|dtjj�}|tjjurtd|����|tjjurGz|�||||�IdHWStj	yF}z	|s<�WYd}~nd}~ww|sPtd|����|�
||||�IdHS)a�Send a file to transport.

        Return the total number of bytes which were sent.

        The method uses high-performance os.sendfile if available.

        file must be a regular file object opened in binary mode.

        offset tells from where to start reading the file. If specified,
        count is the total number of bytes to transmit as opposed to
        sending the file until EOF is reached. File position is updated on
        return or also in case of error in which case file.tell()
        can be used to figure out the number of bytes
        which were sent.

        fallback set to True makes asyncio to manually read and send
        the file when the platform does not support the sendfile syscall
        (e.g. Windows or SSL socket on Unix).

        Raise SendfileNotAvailableError if the system does not support
        sendfile syscall and fallback is False.
        zTransport is closingZ_sendfile_compatiblez(sendfile is not supported for transport NzHfallback is disabled and native sendfile is not supported for transport )rlrqrrZ
_SendfileModeZUNSUPPORTEDZ
TRY_NATIVE�_sendfile_nativerrG�_sendfile_fallback)rirrrIrJrKrDrZrXrrr�sendfilets<���������
�zBaseEventLoop.sendfilec�s�t�d��)Nz!sendfile syscall is not supportedrM)rirjrIrJrKrrrr~�s��zBaseEventLoop._sendfile_nativec
�s@�|r|�|�|rt|d�nd}t|�}d}t|�}zl	|rDt|||�}|dkrD|W|dkr<t|d�r<|�||�|��IdHSt|�d|�}	|�d|j|	�IdH}
|
ss|W|dkrkt|d�rk|�||�|��IdHS|�	�IdH|�
|	d|
��||
7}q|dkr�t|d�r�|�||�|��IdHw)Ni@rTrO)rOrPrQr_r$r�rRr1rSrn�write)rirjrIrJrKrTrUrVr@rWrXrrrr�s<�
	���
z BaseEventLoop._sendfile_fallbackr|c
�s��tdur	td��t|tj�std|����t|dd�s$td|�d���|��}tj|||||||dd�}|�	�|�
|�|�|j|�}	|�|j
�}
z	|IdHW|jStyh|��|	��|
���w)	zzUpgrade transport to TLS.

        Return a new transport that *protocol* should start using
        immediately.
        Nz"Python ssl module is not availablez@sslcontext is expected to be an instance of ssl.SSLContext, got Z_start_tls_compatibleFz
transport z  is not supported by start_tls())r�r�)r]rqrZ
SSLContextr6rrgr	ZSSLProtocolrdrer-rsr�
BaseExceptionr�r�Z_app_transport)rirrr�r�r�r�r�r�Zssl_protocolZ
conmade_cbZ	resume_cbrrr�	start_tls�sB�	��
��
��zBaseEventLoop.start_tls)r>r@r<�
reuse_address�
reuse_port�allow_broadcastr+c �s��|
durI|
jtjkrtd|
�����s �s |s |s |s |s |	r@t��||||||	d�}d�dd�|��D��}td|�d���|
�d	�d}
�ne�s]�s]|d
krUtd��||fdff}n�ttd
�r�|tj	kr���fD]}|durzt
|t�sztd��qk�r��d
dvr�zt
�t�
��j�r�t���Wn!ty�Ynty�}z
t�d�|�WYd}~nd}~ww||f��fff}nZi}d
�fd�ffD]<\}}|du�r|j||tj|||d�IdH}|s�td��|D]\}}}}}||f}||vr�ddg||<||||<q�qɇ�fdd�|��D�}|�std��g}|tu�r/|�r'td��tjdtdd�|D]x\\}}\}}d}
d}
z<tj|tj|d�}
|�rNt|
�|	�rZ|
�tjtjd�|
�d	���rg|
�|���rx|	�sv|� |
|�IdH|}
Wn.t�y�}z|
du�r�|
�!�|�"|�WYd}~�q1d}~w|
du�r�|
�!��n|d
�|�}|�#�}|�$|
||
|�}|j%�rֈ�r�t�&d��||�nt�'d�||�z
|IdHW||fS|�!��)zCreate datagram connection.NzA UDP Socket was expected, got )rg�remote_addrr>r@r<r�r�r�r9css&�|]\}}|r|�d|��VqdS)�=Nr)rD�k�vrrrrFs�$z9BaseEventLoop.create_datagram_endpoint.<locals>.<genexpr>zKsocket modifier keyword arguments can not be used when sock is specified. (�)Frzunexpected address family�NN�AF_UNIXzstring is expected)r�z2Unable to check or remove stale UNIX socket %r: %rrrlrmcs8g|]\}}�r|ddus�r|ddus||f�qS)rNrr)rD�keyZ	addr_pair�rgr�rrr�3s���z:BaseEventLoop.create_datagram_endpoint.<locals>.<listcomp>zcan not get address informationz~Passing `reuse_address=True` is no longer supported, as the usage of SO_REUSEPORT in UDP poses a significant security concern.zdThe *reuse_address* parameter has been deprecated as of 3.5.10 and is scheduled for removal in 3.11.r5)�
stacklevelr\z@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))(r?r%r3r&�dictr
�itemsr^r$r�rrr6�stat�S_ISSOCK�os�st_mode�remove�FileNotFoundErrorr)r�errorrv�_unsetr�r�r6r,r'r(ZSO_BROADCASTr_rdr�r:rgr�rr;r ) rir�rgr�r>r@r<r�r�r�r+ZoptsZproblemsZr_addrZaddr_pairs_inforP�errZ
addr_infos�idxrzZfamreZpror�r�rZ
local_addressZremote_addressrXr�r�rrrr�r�create_datagram_endpoint�s����������
�
�����
���
���
�

�
�
����z&BaseEventLoop.create_datagram_endpointc
�s\�|dd�\}}t|||||g|dd��R�}	|	dur |	gS|j||||||d�IdHS)Nr5rB)rBr:)
rir�r>r?r@r<r�r<r=r;rrrrv�s� �zBaseEventLoop._ensure_resolvedc�s:�|j||f|tj||d�IdH}|std|�d���|S)N)r>r?r<r�zgetaddrinfo(z) returned empty list)rvr%r2r))rir<r=r>r<rzrrr�_create_server_getaddrinfo�s��z(BaseEventLoop._create_server_getaddrinfor)	r>r<r+r�r]r�r�r�r�c	�s��t|t�r
td��|dur|durtd��|durt|�|dus'�du�r|dur/td��|	dur=tjdko<tjdk}	g}
|dkrGdg}nt|t	�sSt|t
jj�sW|g}n|}����fdd	�|D�}t
j|�IdH}ttj�|��}d
}z�|D]v}|\}}}}}z	t�|||�}Wntjy��jr�tjd|||dd
�Yqzw|
�|�|	r�|�tjtjd�|
r�t|�tr�|tjkr�ttd�r�|�tj tj!d�z|�"|�Wqzt#y�}zt#|j$d||j%�&�f�d�d}~wwd}W|s�|
D]}|�'�q�n)|�s
|
D]}|�'��qww|du�rtd��|j(tj)k�r&td|����|g}
|
D]}|�*d
��q+t+�|
||||�}|�rL|�,�t
�-d�IdH�j�rVt�.d|�|S)a1Create a TCP server.

        The host parameter can be a string, in that case the TCP server is
        bound to host and port.

        The host parameter can also be a sequence of strings and in that case
        the TCP server is bound to all hosts of the sequence. If a host
        appears multiple times (possibly indirectly e.g. when hostnames
        resolve to the same IP address), the server is only bound once to that
        host.

        Return a Server object which can be used to stop the service.

        This method is a coroutine.
        z*ssl argument must be an SSLContext or NoneNrjrk�posix�cygwinr/csg|]}�j|���d��qS))r>r<)r�)rDr<�r>r<r=rirrr��s

�
�z/BaseEventLoop.create_server.<locals>.<listcomp>Fz:create_server() failed to create socket.socket(%r, %r, %r)T��exc_info�IPPROTO_IPV6z0error while attempting to bind on address %r: %sz)Neither host/port nor sock were specifiedrurz
%r is serving)/rr}r6r&r^r�r�r�platformrrG�abc�Iterablerr�setrLrMrNr%r�rr�warningr:r'r(ZSO_REUSEADDRr,r9rr$r�ZIPV6_V6ONLYr_r)rbr`rar�r?r2r^rr�r�r;)rir�r<r=r>r<r+r�r]r�r�r�r�r�ZhostsZfsrzZ	completed�resrAZsocktyper@Z	canonnameZsar�r�rr�r�
create_server�s��
��
����

�
������
���
�zBaseEventLoop.create_server)r]r�c�s��|jtjkrtd|����|dur|std��|dur t|�|j|||dd|d�IdH\}}|jr@|�d�}t�	d|||�||fS)Nrurjr/T)r�r�r%z%r handled: (%r, %r))
r?r%r2r&r^rxrryrr )rir�r+r]r�rrr�rrr�connect_accepted_socket
s"��
�
z%BaseEventLoop.connect_accepted_socketc��`�|�}|��}|�|||�}z|IdHWn|���|jr,t�d|��||�||fS)Nz Read pipe %r connected: (%r, %r))rgr�r�rrr �fileno�rir�r�r�r�rrrrr�connect_read_pipe%��
�zBaseEventLoop.connect_read_pipec�r�)Nz!Write pipe %r connected: (%r, %r))rgr�r�rrr r�r�rrr�connect_write_pipe5r�z BaseEventLoop.connect_write_pipecCs�|g}|dur|�dt|����|dur%|tjkr%|�dt|����n|dur3|�dt|����|durA|�dt|����t�d�|��dS)Nzstdin=zstdout=stderr=zstdout=zstderr=� )r:r"rr rr r
)rir=r�r�r�r;rrr�_log_subprocessEszBaseEventLoop._log_subprocess)	r�r�r��universal_newlinesr�r��encoding�errors�textc	�s��t|ttf�std��|rtd��|std��|dkr td��|r&td��|	dur.td��|
dur6td��|�}
d}|jrJd	|}|�||||�|j|
|d
||||fi|��IdH}|jrj|durjt�d||�||
fS)Nzcmd must be a string� universal_newlines must be Falsezshell must be Truer�bufsize must be 0�text must be False�encoding must be None�errors must be Nonezrun shell command %rT�%s: %r)	rr4rr&rr�r�rr;)rir��cmdr�r�r�r�r�r�r�r�r�r�r��	debug_logrrrrr�subprocess_shellRs8���zBaseEventLoop.subprocess_shellc	�s��|rtd��|r
td��|dkrtd��|rtd��|	dur#td��|
dur+td��|f|}|�}d}|jrEd|��}|�||||�|j||d	||||fi|
��IdH}|jre|duret�d
||�||fS)Nr�zshell must be Falserr�r�r�r�zexecute program Fr�)r&rr�r�rr;)rir�Zprogramr�r�r�r�r�r�r�r�r�r�r�Z
popen_argsr�r�rrrrr�subprocess_execvs8�

��zBaseEventLoop.subprocess_execcCr�)zKReturn an exception handler, or None if the default one is in use.
        )r�rwrrr�get_exception_handler�sz#BaseEventLoop.get_exception_handlercCs(|durt|�std|����||_dS)a�Set handler as the new event loop exception handler.

        If handler is None, the default exception handler will
        be set.

        If handler is a callable object, it should have a
        signature matching '(loop, context)', where 'loop'
        will be a reference to the active event loop, 'context'
        will be a dict object (see `call_exception_handler()`
        documentation for details about context).
        Nz+A callable object or None is expected, got )r�r6r�)riZhandlerrrr�set_exception_handler�s
�
z#BaseEventLoop.set_exception_handlerc	Cs|�d�}|s	d}|�d�}|durt|�||jf}nd}d|vr0|jdur0|jjr0|jj|d<|g}t|�D]C}|dvr>q7||}|dkrWd	�t�|��}d
}||�	�7}n|dkrld	�t�|��}d}||�	�7}nt
|�}|�|�d|���q7tj
d
�|�|d�dS)aEDefault exception handler.

        This is called when an exception occurs and no exception
        handler is set, and can be called by a custom exception
        handler that wants to defer to the default behavior.

        This default handler logs the error message and other
        context-dependent information.  In debug mode, a truncated
        stack trace is also appended showing where the given object
        (e.g. a handle or future or task) was created, if any.

        The context parameter has the same meaning as in
        `call_exception_handler()`.
        rz!Unhandled exception in event looprSNFZsource_tracebackZhandle_traceback>rrSr/z+Object created at (most recent call last):
z+Handle created at (most recent call last):
r]�
r�)�getr?�
__traceback__r�r��sortedr
�	traceback�format_list�rstriprr:rr�)	rir$rrSr�Z	log_linesr��value�tbrrr�default_exception_handler�s:


��z'BaseEventLoop.default_exception_handlercCs�|jdur(z|�|�WdSttfy�ty'tjddd�YdSwz	|�||�WdSttfy;�tyy}z3z|�d||d��WnttfyW�tyftjddd�YnwWYd}~dSWYd}~dSd}~ww)aDCall the current event loop's exception handler.

        The context argument is a dict containing the following keys:

        - 'message': Error message;
        - 'exception' (optional): Exception object;
        - 'future' (optional): Future instance;
        - 'task' (optional): Task instance;
        - 'handle' (optional): Handle instance;
        - 'protocol' (optional): Protocol instance;
        - 'transport' (optional): Transport instance;
        - 'socket' (optional): Socket instance;
        - 'asyncgen' (optional): Asynchronous generator that caused
                                 the exception.

        New keys maybe introduced in the future.

        Note: do not overload this method in an event loop subclass.
        For custom exception handling, use the
        `set_exception_handler()` method.
        Nz&Exception in default exception handlerTr�z$Unhandled error in exception handler)rrSr$zeException in default exception handler while handling an unexpected error in custom exception handler)r�r�rTrUr�rr�)rir$rXrrrr�s@
���
���
��z$BaseEventLoop.call_exception_handlercCs|js|j�|�dSdS)zAdd a Handle to _ready.N)�
_cancelledr�r:�rirrrr�
_add_callbacks�zBaseEventLoop._add_callbackcCs|�|�|��dS)z6Like _add_callback() but called from a signal handler.N)r�r�r�rrr�_add_callback_signalsafes
z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dSdS)z3Notification that a TimerHandle has been cancelled.rN)r�r�r�rrr�_timer_handle_cancelled#s�z%BaseEventLoop._timer_handle_cancelledc	Cs�t|j�}|tkr0|j|tkr0g}|jD]}|jrd|_q|�|�qt�|�||_d|_n"|jrR|jdjrR|jd8_t�	|j�}d|_|jrR|jdjs9d}|j
sZ|jr]d}n|jrr|jdj}t
td||���t�}|j�|�}|�|�d}|��|j}|jr�|jd}|j|kr�nt�	|j�}d|_|j
�|�|js�t|j
�}t|�D];}	|j
��}|jr�q�|jr�z$||_|��}
|��|��|
}||jkr�t�dt|�|�Wd|_q�d|_w|��q�d}dS)z�Run one full iteration of the event loop.

        This calls all currently ready callbacks, polls for I/O,
        schedules the resulting callbacks, and finally schedules
        'call_later' callbacks.
        FrrNzExecuting %s took %.3f seconds)rr��_MIN_SCHEDULED_TIMER_HANDLESr��%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr�r:r+ZheapifyZheappopr�r�Z_whenrP�maxr��MAXIMUM_SELECT_TIMEOUTZ	_selectorZselectr�r��range�popleftrr�Z_runr�rr�r)riZsched_countZ
new_scheduledrZtimeoutr,r�Zend_timeZntodo�ir>r@rrrr(sn
�

�


�


��
zBaseEventLoop._run_oncecCsHt|�t|j�krdS|rt��|_t�tj�nt�|j�||_dSrC)r}r�r�#get_coroutine_origin_tracking_depthr��#set_coroutine_origin_tracking_depthrZDEBUG_STACK_DEPTH�riZenabledrrrrxs���
z,BaseEventLoop._set_coroutine_origin_trackingcCr�rC)rrwrrrr��r�zBaseEventLoop.get_debugcCs$||_|��r|�|j|�dSdSrC)rr�r�rr�rrrr��s�zBaseEventLoop.set_debugrC)NNNr�)r)rN)FN)Vr�r�r�rkr�rgr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrVr�r�r�r�r#r�r�r(r%r-r*r.r)r�r1r7rAr:rCrLrFrHrErfr{rxr�r~rr�r�r�r%r2rvr�r7Z
AI_PASSIVEr�r�r�r�r�rrr�r�r�r�r�rr�r�r�rrr�r�rrrrr�s���

�
�
�
�		
	&	
	�

�
-��
��/�/���	��z��%�"29Pr)rr)r)8�__doc__rGZcollections.abcZconcurrent.futuresr2rnr+rLr�r%r�rr
r�r�rr�r�r]�ImportErrorr/rrrrrrr	r
rrr
�logr�__all__r�r�r$r9r��objectr�rr"r,rBrQrYr\r^ZProtocolr_ZAbstractServerrZAbstractEventLooprrrrr�<module>sj�
		

;


Do