�PNG
IHDR��;���IDATx��ܻn�0���K��
�)(�pA������7�LeG{�� �§㻢|��ذaÆ
6lذaÆ
6lذaÆ
6lom��$^�y���ذag�5bÆ
6lذaÆ
6lذa{����
6lذaÆ
�`����}H�Fkm�,�m����Ӫ���ô�ô!��x�|'ܢ˟;�E:���9�&ᶒ�}�{�v]�n&�6�
�h��_��t�ڠ͵-ҫ���Z;��Z$�.�P���k�ž)�!��o���>}l�eQfJ�T��u і���چ��\��X=8��Rن4`Vw�l�>����n�G�^��i�s��"ms�$�u��i��?w�bs[m�6�K4���O���.�4��%����/����b�C%��t��M�ז� �-l�G6�mrz2���s�%�9��s@���-�k�9�=���)������k�B5����\��+͂�Zsٲ��Rn��~G���R���C������wIcI��n7jJ���hۛNCS|���j0��8y�iHKֶۛ�k�Ɉ+;Sz������L/��F�*\��Ԕ�#"5��m�2��[S��������=�g��n�a�P�e�ғ�L��
lذaÆ
6l�^k��̱aÆ
6lذaÆ
6lذa;����
�_��ذaÆ
6lذaÆ
6lذaÆ
���R���IEND�B`
3
\��@s�dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd lmZdd
lmZdgZdZd
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/base_events.py�_format_handle?s
rcCs(|tjkrdS|tjkrdSt|�SdS)Nzz)�
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|�rt|t�r�|dkr�d}n&yt |�}Wnt
tfk
r�dSX|tjkr�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�srK�TCP_NODELAYcCs>|jtjtjhkr:t|j�r:|jtjkr:|jtjtj d�dS)Nr)
r=r r7rr+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
zServer.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�Zd�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�Zdvdw�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|_|jtjjodttjjd���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\ szBaseEventLoop.__repr__cCstj|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�sz4BaseEventLoop.shutdown_asyncgens..)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_coro�results�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|jt�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�5szBaseEventLoop.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�{sz"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|�dk�rR|d
�nJt|d
��t�fdd�|D���r~|d
�tdjdjdd�|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� sz2BaseEventLoop.create_connection..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|�dk�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�rrz, css"|]\}}|rdj||�VqdS)z{}={}N)r�)r��k�vrrrr�isz9BaseEventLoop.create_datagram_endpoint..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..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&ZSO_BROADCASTr�r�rar9rDr�r�r rIr�)rXr�r�rr=r?rBr�rrr%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�rc #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|||dd
�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|�sx|D]}|j%��q�WXn2|dk�r"td��t&|j'��s.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#rr&r8rrrZIPV6_V6ONLYr�r$r�r�r�rar+r>r�rTZlistenr�Z_start_servingrI)rXr�r;r<�r=rBr%rr�r�rrUZhostsr�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�|rtd��|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�sz#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
jdj|�|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�r3zeException in default exception handler while handling an unexpected error in custom exception handler)rur6rOr r)rXr3rRrrrr�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)r8r�)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_cancelledcCs�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_FRACTIONr7r9r��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|krsV
;
/