ok

Mini Shell

Direktori : /lib64/python3.6/asyncio/__pycache__/
Upload File :
Current File : //lib64/python3.6/asyncio/__pycache__/base_events.cpython-36.pyc

3


 \��@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZdgZdZd
ZeeefZ e!e	d�Z"d)Z#dd�Z$dd�Z%dd�Z&dd�Z'dd�Z(dd�Z)de	j*ddd�dd�Z+e!e	d ��rRd!d"�Z,nd#d"�Z,d$d%�Z-Gd&d'�d'ej.�Z/Gd(d�dej0�Z1dS)*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�)�compat)�
coroutines)�events)�futures)�tasks)�	coroutine)�logger�
BaseEventLoop�dg�?�AF_INET6�icCs0|j}tt|dd�tj�r$t|j�St|�SdS)N�__self__)Z	_callback�
isinstance�getattrr�Task�reprr�str)�handle�cb�r�+/usr/lib64/python3.6/asyncio/base_events.py�_format_handle?s
rcCs(|tjkrdS|tjkrdSt|�SdS)Nz<pipe>z<stdout>)�
subprocess�PIPE�STDOUTr)�fdrrr�_format_pipeHs


rcCsLttd�std��n4y|jtjtjd�Wntk
rFtd��YnXdS)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_reuseportQs

r&cCs&ttd�r|d@tjkS|tjkSdS)N�
SOCK_NONBLOCK�)rr �SOCK_STREAM)�	sock_typerrr�_is_stream_socket\s
r+cCs&ttd�r|d@tjkS|tjkSdS)Nr'r()rr �
SOCK_DGRAM)r*rrr�_is_dgram_sockeths
r-cCsvttd�sdS|dtjtjhks(|dkr,dSt|�r<tj}nt|�rLtj}ndS|dkr^d}nVt|t�rv|dkrvd}n>t|t�r�|dkr�d}n&yt	|�}Wnt
tfk
r�dSX|tjkr�tj
g}tr�|jtj�n|g}t|t�r�|jd�}d|k�rdSxp|D]h}yJtj||�t�r@|tjk�r@|||d||ddffS|||d||ffSWntk
�rjYnX�qWdS)N�	inet_ptonr��Zidna�%)rr �IPPROTO_TCPZIPPROTO_UDPr+r-r�bytesr�int�	TypeErrorr!�	AF_UNSPEC�AF_INET�	_HAS_IPv6�appendr�decoder.r$)�host�port�family�type�protoZafs�afrrr�_ipaddr_infopsL





rA)r=r>r?�flagsc
CsZ|dd�\}}t|||||�}|dk	r@|j�}	|	j|g�|	S|j||||||d�SdS)N�)r=r>r?rB)rA�
create_future�
set_result�getaddrinfo)
�addressr=r>r?rB�loopr;r<�info�futrrr�_ensure_resolved�srK�TCP_NODELAYcCs>|jtjtjhkr:t|j�r:|jtjkr:|jtjtj	d�dS)Nr)
r=r r7rr+r>r?r2r"rL)r%rrr�_set_nodelay�s
rMcCsdS)Nr)r%rrrrM�scCs.|j}t|t�r t|t�r dS|jj�dS)N)Z
_exceptionr�
BaseException�	Exception�_loop�stop)rJ�excrrr�_run_until_complete_cb�s

rSc@sHeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
dS)�ServercCs||_||_d|_g|_dS)Nr)rP�sockets�
_active_count�_waiters)�selfrHrUrrr�__init__�szServer.__init__cCsd|jj|jfS)Nz<%s sockets=%r>)�	__class__�__name__rU)rXrrr�__repr__�szServer.__repr__cCs |jdk	st�|jd7_dS)Nr)rU�AssertionErrorrV)rXrrr�_attach�szServer._attachcCs<|jdkst�|jd8_|jdkr8|jdkr8|j�dS)Nrr)rVr]rU�_wakeup)rXrrr�_detach�szServer._detachcCsH|j}|dkrdSd|_x|D]}|jj|�qW|jdkrD|j�dS)Nr)rUrPZ
_stop_servingrVr_)rXrUr%rrr�close�s

zServer.closecCs0|j}d|_x|D]}|j�s|j|�qWdS)N)rW�donerE)rX�waiters�waiterrrrr_�s

zServer._wakeupccs<|jdks|jdkrdS|jj�}|jj|�|EdHdS)N)rUrWrPrDr9)rXrdrrr�wait_closed�s

zServer.wait_closedN)r[�
__module__�__qualname__rYr\r^r`rar_rrerrrrrT�s
rTc
@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd�d
d
d�dd�Z	d�dd
d
d
d�dd�Z
d�dd�Zd�dd�Zd�dd�Z
ed�dd��Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zed'd(��Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zej�r�d3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%dEdF�Z&dGdH�Z'dIdJ�Z(dKdL�Z)dMdMdMdMdN�dOdP�Z*d�dQdR�Z+ed�d
dMdMdMd
d
d
dS�dTdU��Z,ed�dVdW��Z-ed�dMdMdMd
d
d
d
dX�dYdZ��Z.ed[d\��Z/ed�e0j1e0j2d
d]d
d
d
d^�d_d`��Z3ed
da�dbdc��Z4eddde��Z5edfdg��Z6dhdi�Z7ee8j9e8j9e8j9ddjdMdk�dldm��Z:ee8j9e8j9e8j9dddMdk�dndo��Z;dpdq�Z<drds�Z=dtdu�Z>dvdw�Z?dxdy�Z@dzd{�ZAd|d}�ZBd~d�ZCd�d��ZDd�d��ZEd�d��ZFd
S)�r
cCs�d|_d|_d|_tj�|_g|_d|_d|_d|_	t
jd�j|_
d|_|jtjjodttjjd���d|_d|_d|_d|_ttd�r�tj�|_nd|_d|_dS)NrF�	monotonicZPYTHONASYNCIODEBUGg�������?�get_asyncgen_hooks) �_timer_cancelled_count�_closed�	_stopping�collections�deque�_ready�
_scheduled�_default_executorZ
_internal_fds�
_thread_id�timeZget_clock_infoZ
resolution�_clock_resolution�_exception_handler�	set_debug�sysrB�ignore_environment�bool�os�environ�get�slow_callback_duration�_current_handle�
_task_factory�_coroutine_wrapper_setr�weakref�WeakSet�
_asyncgens�_asyncgens_shutdown_called)rXrrrrY�s(

zBaseEventLoop.__init__cCs d|jj|j�|j�|j�fS)Nz"<%s running=%s closed=%s debug=%s>)rZr[�
is_running�	is_closed�	get_debug)rXrrrr\ szBaseEventLoop.__repr__cCstj|d�S)z,Create a Future object attached to the loop.)rH)rZFuture)rXrrrrD%szBaseEventLoop.create_futurecCs@|j�|jdkr0tj||d�}|jr<|jd=n|j||�}|S)zDSchedule a coroutine object.

        Return a task object.
        N)rHr���)�
_check_closedrrr�_source_traceback)rX�coroZtaskrrr�create_task)s

zBaseEventLoop.create_taskcCs$|dk	rt|�rtd��||_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)�callabler5r)rX�factoryrrr�set_task_factory7s
zBaseEventLoop.set_task_factorycCs|jS)z<Return a task factory, or None if the default one is in use.)r)rXrrr�get_task_factoryEszBaseEventLoop.get_task_factoryN)�extra�servercCst�dS)zCreate socket transport.N)�NotImplementedError)rXr%�protocolrdr�r�rrr�_make_socket_transportIsz$BaseEventLoop._make_socket_transportF)�server_side�server_hostnamer�r�c	Cst�dS)zCreate SSL transport.N)r�)	rXZrawsockr��
sslcontextrdr�r�r�r�rrr�_make_ssl_transportNsz!BaseEventLoop._make_ssl_transportcCst�dS)zCreate datagram transport.N)r�)rXr%r�rGrdr�rrr�_make_datagram_transportTsz&BaseEventLoop._make_datagram_transportcCst�dS)zCreate read pipe transport.N)r�)rX�piper�rdr�rrr�_make_read_pipe_transportYsz'BaseEventLoop._make_read_pipe_transportcCst�dS)zCreate write pipe transport.N)r�)rXr�r�rdr�rrr�_make_write_pipe_transport^sz(BaseEventLoop._make_write_pipe_transportc	
Kst�dS)zCreate subprocess transport.N)r�)
rXr��args�shell�stdin�stdout�stderr�bufsizer��kwargsrrr�_make_subprocess_transportcsz(BaseEventLoop._make_subprocess_transportcCst�dS)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.
        N)r�)rXrrr�_write_to_selfjszBaseEventLoop._write_to_selfcCst�dS)zProcess selector events.N)r�)rX�
event_listrrr�_process_eventssszBaseEventLoop._process_eventscCs|jrtd��dS)NzEvent loop is closed)rk�RuntimeError)rXrrrr�wszBaseEventLoop._check_closedcCs*|jj|�|j�s&|j|j|j��dS)N)r��discardr��call_soon_threadsafer��aclose)rX�agenrrr�_asyncgen_finalizer_hook{sz&BaseEventLoop._asyncgen_finalizer_hookcCs,|jrtjdj|�t|d�|jj|�dS)NzNasynchronous generator {!r} was scheduled after loop.shutdown_asyncgens() call)�source)r��warnings�warn�format�ResourceWarningr��add)rXr�rrr�_asyncgen_firstiter_hook�s
z&BaseEventLoop._asyncgen_firstiter_hookccs�d|_|jdkst|j�r dSt|j�}|jj�tjdd�|D�d|d��}|EdH}x8t||�D]*\}}t|t	�rf|j
dj|�||d��qfWdS)z,Shutdown all active asynchronous generators.TNcSsg|]}|j��qSr)r�)�.0Zagrrr�
<listcomp>�sz4BaseEventLoop.shutdown_asyncgens.<locals>.<listcomp>)Zreturn_exceptionsrHz?an error occurred during closing of asynchronous generator {!r})�message�	exceptionZasyncgen)r�r��len�list�clearr�gather�ziprrO�call_exception_handlerr�)rXZ
closing_agensZ
shutdown_coroZresults�resultr�rrr�shutdown_asyncgens�s"




z BaseEventLoop.shutdown_asyncgenscCs�|j�|j�rtd��tj�dk	r,td��|j|j�tj�|_	|j
dk	rftj�}tj
|j|jd�z$tj|�x|j�|jrtPqtWWdd|_d|_	tjd�|jd�|j
dk	r�tj
|�XdS)zRun until stop() is called.z"This event loop is already runningNz7Cannot run the event loop while another loop is running)�	firstiter�	finalizerF)r�r�r�rZ_get_running_loop�_set_coroutine_wrapper�_debug�	threading�	get_identrrr�rwri�set_asyncgen_hooksr�r�Z_set_running_loop�	_run_oncerl)rXZold_agen_hooksrrr�run_forever�s0







zBaseEventLoop.run_forevercCs�|j�tj|�}tj||d�}|r,d|_|jt�z>y|j�Wn,|rj|j	�rj|j
�rj|j��YnXWd|jt�X|j	�s�t
d��|j�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.
        )rHFNz+Event loop stopped before Future completed.)r�rZisfuturerZ
ensure_futureZ_log_destroy_pendingZadd_done_callbackrSr�rbZ	cancelledr�Zremove_done_callbackr�r�)rXZfutureZnew_taskrrr�run_until_complete�s 
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)rl)rXrrrrQ�szBaseEventLoop.stopcCsj|j�rtd��|jrdS|jr,tjd|�d|_|jj�|jj�|j	}|dk	rfd|_	|j
dd�dS)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 %rTF)�wait)r�r�rkr�r	�debugror�rprqZshutdown)rX�executorrrrra�s

zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)rk)rXrrrr�szBaseEventLoop.is_closedcCs0|j�s,tjd|t|d�|j�s,|j�dS)Nzunclosed event loop %r)r�)r�r�r�r�r�ra)rXrrr�__del__s
zBaseEventLoop.__del__cCs
|jdk	S)z*Returns True if the event loop is running.N)rr)rXrrrr�szBaseEventLoop.is_runningcCstj�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.
        )rsrh)rXrrrrsszBaseEventLoop.timecGs,|j|j�||f|��}|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.
        rr�)�call_atrsr�)rXZdelay�callbackr��timerrrr�
call_later szBaseEventLoop.call_latercGsX|j�|jr"|j�|j|d�tj||||�}|jr@|jd=tj|j	|�d|_	|S)z|Like call_later(), but uses an absolute time.

        Absolute time corresponds to the event loop's time() method.
        r�rTr�)
r�r��
_check_thread�_check_callbackr�TimerHandler��heapq�heappushrp)rX�whenr�r�r�rrrr�5szBaseEventLoop.call_atcGs@|j�|jr"|j�|j|d�|j||�}|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_soonrr�)r�r�r�r��
_call_soonr�)rXr�r�rrrrr�Es
zBaseEventLoop.call_sooncCs>tj|�stj|�r"tdj|���t|�s:tdj||���dS)Nz#coroutines cannot be used with {}()z0a callable object was expected by {}(), got {!r})rZiscoroutineZiscoroutinefunctionr5r�r�)rXr��methodrrrr�Xs

zBaseEventLoop._check_callbackcCs,tj|||�}|jr|jd=|jj|�|S)Nrr�)r�Handler�ror9)rXr�r�rrrrr�cs
zBaseEventLoop._call_sooncCs,|jdkrdStj�}||jkr(td��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)rrr�r�r�)rXZ	thread_idrrrr�js	

zBaseEventLoop._check_threadcGs@|j�|jr|j|d�|j||�}|jr4|jd=|j�|S)z"Like call_soon(), but thread-safe.r�rr�)r�r�r�r�r�r�)rXr�r�rrrrr�{sz"BaseEventLoop.call_soon_threadsafecGsZ|j�|jr|j|d�|dkr@|j}|dkr@tjj�}||_tj|j|f|��|d�S)N�run_in_executor)rH)	r�r�r�rq�
concurrentrZThreadPoolExecutorZwrap_futureZsubmit)rXr��funcr�rrrr��s
zBaseEventLoop.run_in_executorcCs
||_dS)N)rq)rXr�rrr�set_default_executor�sz"BaseEventLoop.set_default_executorcCs�d||fg}|r |jd|�|r2|jd|�|rD|jd|�|rV|jd|�dj|�}tjd|�|j�}tj||||||�}	|j�|}
d||
d	|	f}|
|jkr�tj|�n
tj|�|	S)
Nz%s:%rz	family=%rztype=%rzproto=%rzflags=%rz, zGet address info %sz(Getting address info %s took %.3f ms: %rg@�@)	r9�joinr	r�rsr rFr}rI)rXr;r<r=r>r?rB�msg�t0Zaddrinfo�dtrrr�_getaddrinfo_debug�s(


z BaseEventLoop._getaddrinfo_debugr)r=r>r?rBc	Cs>|jr |jd|j||||||�S|jdtj||||||�SdS)N)r�r�r�r rF)rXr;r<r=r>r?rBrrrrF�s


zBaseEventLoop.getaddrinfocCs|jdtj||�S)N)r�r �getnameinfo)rXZsockaddrrBrrrr��szBaseEventLoop.getnameinfo)�sslr=r?rBr%�
local_addrr�c#s|
dk	r|rtd��|
dkr2|r2|s.td��|}
|dk	sD|dk	�r�|dk	rTtd��t||f|tj|||d�}|g}|	dk	r�t|	|tj|||d�}
|j|
�nd}
tj||d�EdH|j�}|s�td��|
dk	r�|
j�}|s�td��g}�x�|D�]B\}}}}}y�tj|||d�}|j	d	�|
dk	�r�x�|D]j\}}}}}y|j
|�PWnHtk
�r�}z*t|jd
j||j
j���}|j|�WYdd}~XnX�q.W|j�d}w�|j�r�tjd||�|j||�EdHWn^tk
�r}z"|dk	�r�|j�|j|�WYdd}~Xq�|dk	�r,|j��Yq�XPq�Wt|�dk�rR|d
�nJt|d
��t�fdd�|D���r~|d
�tdjdjdd�|D�����n,|dk�r�td��t|j��s�tdj|���|j||||
�EdH\}}|j�r
|jd�}tjd|||||�||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 hostz8host/port and sock can not be specified at the same time)r=r>r?rBrH)rHz!getaddrinfo() returned empty list)r=r>r?Fz2error while attempting to bind on address {!r}: {}zconnect %r to %rrrc3s|]}t|��kVqdS)N)r)r�rR)�modelrr�	<genexpr>sz2BaseEventLoop.create_connection.<locals>.<genexpr>zMultiple exceptions: {}z, css|]}t|�VqdS)N)r)r�rRrrrr�#sz5host and port was not specified and no sock specifiedz&A Stream Socket was expected, got {!r}r z%r connected to %s:%r: (%r, %r))r!rKr r)r9rr�r�r$�setblocking�bind�errnor��strerror�lowerrar�r	r��sock_connectr�r�allr�r+r>�_create_connection_transport�get_extra_info)rX�protocol_factoryr;r<r�r=r?rBr%r�r��f1�fs�f2�infosZladdr_infos�
exceptionsr>ZcnamerG�_ZladdrrR�	transportr�r)r�r�create_connection�s�





"




zBaseEventLoop.create_connectionc
	cs�|jd�|�}|j�}|rFt|t�r*dn|}|j||||||d�}	n|j|||�}	y|EdHWn|	j��YnX|	|fS)NF)r�r�)r�rDrryr�r�ra)
rXr%r�r�r�r�r�rdr�r�rrrr�=s
z*BaseEventLoop._create_connection_transport)r=r?rB�
reuse_address�
reuse_port�allow_broadcastr%c#sZ|
dk	r�t|
j�s tdj|
����s@�s@|s@|s@|s@|s@|s@|	r~t��||||||	d�}djdd�|j�D��}tdj|���|
jd�d}
�nL�p��s�|d	kr�td
��||fdff}n�tj	�}x�d	�fd�ffD]�\}}|dk	r�t
|t��r�t|�dk�st
d
��t||tj|||d�EdH}|�s.td��xB|D]:\}}}}}||f}||k�r`ddg||<||||<�q4Wq�W��fdd�|j�D�}|�s�td��g}|dk�r�tjdk�o�tjdk}�x|D�]\\}}\}}d}
d}
y�tj|tj|d�}
|�r|
jtjtjd�|�rt|
�|	�r4|
jtjtjd�|
jd���rN|
j|���rj|j|
|�EdH|}
Wn^tk
�r�}z"|
dk	�r�|
j�|j|�WYdd}~Xn"|
dk	�r�|
j��YnXP�q�W|d	�|�}|j�}|j |
||
|�}|j!�r,��rt"j#d��||�nt"j$d�||�y|EdHWn|j��YnX||fS)zCreate datagram connection.Nz#A UDP Socket was expected, got {!r})r��remote_addrr=r?rBr�r�rz, css"|]\}}|rdj||�VqdS)z{}={}N)r�)r��k�vrrrr�isz9BaseEventLoop.create_datagram_endpoint.<locals>.<genexpr>zNsocket modifier keyword arguments can not be used when sock is specified. ({})Frzunexpected address familyrrCz2-tuple is expected)r=r>r?rBrHz!getaddrinfo() returned empty listcs8g|]0\}}�r|ddkp*�o*|ddks||f�qS)rNrr)r��keyZ	addr_pair)r�rrrr��sz:BaseEventLoop.create_datagram_endpoint.<locals>.<listcomp>zcan not get address information�posix�cygwin)r=r>r?z@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))NN)%r-r>r!r��dictr��itemsr�rm�OrderedDictr�tupler�r]rKr r,r$rz�namerw�platformr"r#�SO_REUSEADDRr&ZSO_BROADCASTr�r�rar9rDr�r�r	rIr�)rXr�r�rr=r?rBr�r�rr%ZoptsZproblemsZr_addrZaddr_pairs_infoZ
addr_infos�idxZaddrr�Zfamr�ZprorGrr�Z
local_addressZremote_addressrRr�rdr�r)r�rr�create_datagram_endpointUs�








z&BaseEventLoop.create_datagram_endpointccs4t||f|tj||d�EdH}|s0tdj|���|S)N)r=r>rBrHz%getaddrinfo({!r}) returned empty list)rKr r)r$r�)rXr;r<r=rBr�rrr�_create_server_getaddrinfo�s
z(BaseEventLoop._create_server_getaddrinfor)r=rBr%�backlogr�r�r�c #s�t|t�rtd��|dk	s$�dk	�r|dk	r4td��|	dkrPtjdkoNtjdk}	g}|dkrddg}n$t|t�s|t|t	j
�r�|g}n|}����fdd�|D�}
tj|
d	�i�EdH}t
tjj|��}d
}�z �x|D�]
}|\}}}}}ytj|||�}Wn6tjk
�r2�j�r,tjd|||dd
�w�YnX|j|�|	�rV|jtjtjd�|
�rdt|�t�r�|tjk�r�ttd��r�|jtjtjd�y|j |�Wq�t!k
�r�}z t!|j"d||j#j$�f��WYdd}~Xq�Xq�Wd}Wd|�sx|D]}|j%��q�WXn2|dk�r"td��t&|j'��s<tdj(|���|g}t)�|�}x4|D],}|j*|�|j+d
��j,|||||��qRW�j�r�tj-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 NoneNz8host/port and sock can not be specified at the same timerrr0csg|]}�j|���d��qS))r=rB)r)r�r;)r=rBr<rXrrr�sz/BaseEventLoop.create_server.<locals>.<listcomp>rHFz: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 specifiedz&A Stream Socket was expected, got {!r}z
%r is serving).rryr5r!rzrrwrrrm�Iterablerr��set�	itertools�chain�
from_iterabler �errorr�r	�warningr9r"r#r
r&r8rrrZIPV6_V6ONLYr�r$r�r�r�rar+r>r�rTZlistenr�Z_start_servingrI)rXr�r;r<r=rBr%rr�r�r�rUZhostsr�r�Z	completed�resr@Zsocktyper?Z	canonnameZsa�errr�r)r=rBr<rXr�
create_server�s�


(





zBaseEventLoop.create_server)r�ccs^t|j�stdj|���|j|||ddd�EdH\}}|jrV|jd�}tjd|||�||fS)aHandle an accepted connection.

        This is used by servers that accept connections outside of
        asyncio but that use asyncio to handle connections.

        This method is a coroutine.  When completed, the coroutine
        returns a (transport, protocol) pair.
        z&A Stream Socket was expected, got {!r}r0T)r�Nr z%r handled: (%r, %r))	r+r>r!r�r�r�r�r	r�)rXr�r%r�r�r�rrr�connect_accepted_socketAs


z%BaseEventLoop.connect_accepted_socketccsd|�}|j�}|j|||�}y|EdHWn|j��YnX|jr\tjd|j�||�||fS)Nz Read pipe %r connected: (%r, %r))rDr�rar�r	r��fileno)rXr�r�r�rdr�rrr�connect_read_pipeXszBaseEventLoop.connect_read_pipeccsd|�}|j�}|j|||�}y|EdHWn|j��YnX|jr\tjd|j�||�||fS)Nz!Write pipe %r connected: (%r, %r))rDr�rar�r	r�r)rXr�r�r�rdr�rrr�connect_write_pipeisz BaseEventLoop.connect_write_pipecCs�|g}|dk	r |jdt|��|dk	rF|tjkrF|jdt|��n4|dk	r`|jdt|��|dk	rz|jdt|��tjdj|��dS)Nzstdin=%szstdout=stderr=%sz	stdout=%sz	stderr=%s� )r9rrrr	r�r�)rXr�r�r�r�rIrrr�_log_subprocesszszBaseEventLoop._log_subprocessT)r�r�r��universal_newlinesr�r�c
ks�t|ttf�std��|r"td��|s.td��|dkr>td��|�}
d}|jrfd|}|j||||�|j|
|d||||f|	�EdH}|jr�|dk	r�tjd||�||
fS)	Nzcmd must be a stringz universal_newlines must be Falsezshell must be Truerzbufsize must be 0zrun shell command %rTz%s: %r)	rr3rr!r�r#r�r	rI)
rXr��cmdr�r�r�r$r�r�r�r��	debug_logr�rrr�subprocess_shell�s$zBaseEventLoop.subprocess_shellcos�|rtd��|rtd��|dkr(td��|f|	}x,|D]$}t|ttf�s8tdt|�j��q8W|�}
d}|jr�d|}|j||||�|j	|
|d||||f|
�EdH}|jr�|dk	r�t
jd||�||
fS)	Nz universal_newlines must be Falsezshell must be Falserzbufsize must be 0z8program arguments must be a bytes or text string, not %szexecute program %rFz%s: %r)r!rrr3r5r>r[r�r#r�r	rI)rXr�Zprogramr�r�r�r$r�r�r�r�Z
popen_args�argr�r&r�rrr�subprocess_exec�s,

zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use.
        )ru)rXrrr�get_exception_handler�sz#BaseEventLoop.get_exception_handlercCs*|dk	r t|�r tdj|���||_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})r�r5r�ru)rXZhandlerrrr�set_exception_handler�sz#BaseEventLoop.set_exception_handlerc	Cs|jd�}|sd}|jd�}|dk	r6t|�||jf}nd}d|kr`|jdk	r`|jjr`|jj|d<|g}x�t|�D]�}|dkr~qp||}|dkr�djtj|��}d	}||j	�7}n2|dkr�djtj|��}d
}||j	�7}nt
|�}|jdj||��qpWt
jdj|�|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()`.
        r�z!Unhandled exception in event loopr�NFZsource_tracebackZhandle_tracebackr0z+Object created at (most recent call last):
z+Handle created at (most recent call last):
z{}: {}�
)r>r�r�)r|r>�
__traceback__r~r��sortedr��	traceback�format_list�rstriprr9r�r	r)	rX�contextr�r�rZ	log_linesr�value�tbrrr�default_exception_handler�s6


z'BaseEventLoop.default_exception_handlercCs�|jdkr>y|j|�Wq�tk
r:tjddd�Yq�Xnny|j||�Wn\tk
r�}z@y|jd||d��Wn"tk
r�tjddd�YnXWYdd}~XnXdS)aCall 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;
        - '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 handlerT)rz$Unhandled error in exception handler)r�r�r2zeException in default exception handler while handling an unexpected error in custom exception handler)rur5rOr	r)rXr2rRrrrr�s"
z$BaseEventLoop.call_exception_handlercCs@t|tj�std��|jrdSt|tj�s0t�|jj|�dS)z3Add a Handle to _scheduled (TimerHandle) or _ready.zA Handle is required hereN)rrr�r]�
_cancelledr�ror9)rXrrrr�
_add_callback9s
zBaseEventLoop._add_callbackcCs|j|�|j�dS)z6Like _add_callback() but called from a signal handler.N)r7r�)rXrrrr�_add_callback_signalsafeAs
z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)rprj)rXrrrr�_timer_handle_cancelledFsz%BaseEventLoop._timer_handle_cancelledcCs�t|j�}|tkrd|j|tkrdg}x&|jD]}|jr>d|_q,|j|�q,Wtj|�||_d|_n8x6|jr�|jdjr�|jd8_tj	|j�}d|_qfWd}|j
s�|jr�d}n*|jr�|jdj}t
td||j��t�}|jo�|dk�r�|j�}|jj|�}|j�|}|dk�rtj}	ntj}	t|�}
|dk�rLtj|	d|d|
�nD|
�rntj|	d|d|d|
�n"|dk�r�tj|	d	|d|d�n|jj|�}|j|�|j�|j}xD|j�r�|jd}|j|k�r�Ptj	|j�}d|_|j
j|��q�Wt|j
�}x�t|�D]|}
|j
j�}|j�r*�q|j�r�zD||_|j�}|j�|j�|}||jk�rttj d
t!|�|�Wdd|_Xn|j��qWd}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.
        FrrNg�?zpoll took %.3f ms: %s eventsg@�@z$poll %.3f ms took %.3f ms: %s eventsz"poll %.3f ms took %.3f ms: timeoutzExecuting %s took %.3f seconds)"r�rp�_MIN_SCHEDULED_TIMER_HANDLESrj�%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr6r9r��heapify�heappoprorlZ_when�min�maxrs�MAXIMUM_SELECT_TIMEOUTr�Z	_selectorZselect�logging�INFO�DEBUGr	�logr�rt�range�popleftr~Z_runr}rr)rXZsched_countZ
new_scheduledrZtimeoutr�r�r�r��levelZneventZend_timeZntodo�irrrr�Ks�











zBaseEventLoop._run_oncecCs�ytj}tj}Wntk
r$dSXt|�}|j|kr<dStj}|�}|rz|d|fkrjtj	d|t
�q�||�d|_n,|d|fkr�tj	d|t
�n|d�d|_dS)Nz[loop.set_debug(True): cannot set debug coroutine wrapper; another wrapper is already set %rTzWloop.set_debug(False): cannot unset debug coroutine wrapper; another wrapper was set %rF)rw�set_coroutine_wrapper�get_coroutine_wrapper�AttributeErrorryr�rZ
debug_wrapperr�r��RuntimeWarning)rX�enabledZset_wrapperZget_wrapper�wrapperZcurrent_wrapperrrrr��s.

z$BaseEventLoop._set_coroutine_wrappercCs|jS)N)r�)rXrrrr��szBaseEventLoop.get_debugcCs||_|j�r|j|�dS)N)r�r�r�)rXrMrrrrv�szBaseEventLoop.set_debug)N)N)NNN)NN)NN)N)r)NN)F)NN)NN)Gr[rfrgrYr\rDr�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�rQrar�rZPY34r�r�rsr�r�r�r�r�r�r�r�r�r�rFr�r�r�rrr r6Z
AI_PASSIVErrr r!r#rrr'r)r*r+r5r�r7r8r9r�r�r�rvrrrrr
�s�!


		%	

u	`
12c!i�Q)2�__doc__rmZconcurrent.futuresr�r��inspectrrArzr rr�rsr/rwr�r�r0rrrrrrrDr	�__all__r:r;�BrokenPipeError�ConnectionResetError�ConnectionAbortedErrorZ_FATAL_ERROR_IGNORErr8r@rrr&r+r-rAr)rKrMrSZAbstractServerrTZAbstractEventLoopr
rrrr�<module>sV
		;


/

Zerion Mini Shell 1.0