AlkantarClanX12

Your IP : 3.147.71.175


Current Path : /opt/alt/python35/lib64/python3.5/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/asyncio/__pycache__/base_events.cpython-35.pyc



��Yf���
@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZdgZdZd
ZeeefZ dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%dd�Z&ddde	j'dddddd�Z(d d!�Z)Gd"d#�d#ej*�Z+Gd$d�dej,�Z-dS)%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�?cCsH|j}tj|�r:t|jtj�r:t|j�St|�SdS)N)	Z	_callback�inspectZismethod�
isinstance�__self__r�Task�repr�str)�handle�cb�r�8/opt/alt/python35/lib64/python3.5/asyncio/base_events.py�_format_handle:s	$
rcCs4|tjkrdS|tjkr&dSt|�SdS)Nz<pipe>z<stdout>)�
subprocess�PIPE�STDOUTr)�fdrrr�_format_pipeCs
rcCs`ttd�std��n>y|jtjtjd�Wntk
r[td��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_reuseportLs
r$cCs|jtj@tjkS)N)�typer�SOCK_STREAM)r#rrr�_is_stream_socketWsr'cCs|jtj@tjkS)N)r%r�
SOCK_DGRAM)r#rrr�_is_dgram_socket^sr)cCs�ttd�sdS|dtjtjhks:|dkr>dS|tjkrYtj}n|tjkrttj}ndS|dkr�d}nwt|t�r�|dkr�d}nSt|t�r�|dkr�d}n/yt	|�}Wnt
tfk
rdSYnX|tjkrAtj
g}ttd�rJ|jtj�n	|g}t|t�rh|jd�}d|krxdSxP|D]H}y-tj||�|||d||ffSWqtk
r�YqXqWdS)N�	inet_ptonr���AF_INET6Zidna�%)rrZIPPROTO_TCPZIPPROTO_UDPr&r(r
�bytesr�int�	TypeErrorr�	AF_UNSPECZAF_INET�appendr-�decoder*r")�host�port�familyr%�protoZafs�afrrr�_ipaddr_infoesH					

	r:r7r%r8�flagsc
Cs�|dd�\}}t|||||�}|dk	rZ|j�}	|	j|g�|	S|j||d|d|d|d|�SdS)N�r7r%r8r;)r:�
create_future�
set_result�getaddrinfo)
�addressr7r%r8r;�loopr5r6�info�futrrr�_ensure_resolved�srDcCs=|j}t|t�r,t|t�r,dS|jj�dS)N)Z
_exceptionr
�
BaseException�	Exception�_loop�stop)rC�excrrr�_run_until_complete_cb�s
	rJc@sjeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
dS)�ServercCs(||_||_d|_g|_dS)Nr)rG�sockets�
_active_count�_waiters)�selfrArLrrr�__init__�s			zServer.__init__cCsd|jj|jfS)Nz<%s sockets=%r>)�	__class__�__name__rL)rOrrr�__repr__�szServer.__repr__cCs(|jdk	st�|jd7_dS)Nr)rL�AssertionErrorrM)rOrrr�_attach�szServer._attachcCsP|jdkst�|jd8_|jdkrL|jdkrL|j�dS)Nrr)rMrTrL�_wakeup)rOrrr�_detach�szServer._detachcCs`|j}|dkrdSd|_x|D]}|jj|�q)W|jdkr\|j�dS)Nr)rLrGZ
_stop_servingrMrV)rOrLr#rrr�close�s		
zServer.closecCs@|j}d|_x'|D]}|j�s|j|�qWdS)N)rN�doner>)rO�waiters�waiterrrrrV�s
		
zServer._wakeupccsN|jdks|jdkr"dS|jj�}|jj|�|EdHdS)N)rLrNrGr=r3)rOr[rrr�wait_closed�s
zServer.wait_closedN)rR�
__module__�__qualname__rPrSrUrWrXrVrr\rrrrrK�s
rKc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
dd
dd
dd�Z	d
dddd
dd
dd
dd�Z
d
d
d
dd�Zd
d
dd�Zd
d
dd�Z
ed
dd��Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zed)d*��Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zejr�d5d6�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)dOdPdQdPdRdPdSdPdTdU�Z*dPdVdW�Z+ed
d
dXd
dOdPdRdPdSdPdYd
dZd
dd
d[d\��Z,edd]d^��Z-ed
d
dOdPdRdPdSdPd_d
d`d
dad
dYd
dbdc��Z.eddde��Z/ed
d
dOe0j1dSe0j2dYd
dfdgdXd
d_d
d`d
dhdi��Z3edXd
djdk��Z4edldm��Z5edndo��Z6dpdq�Z7edre8j9dse8j9dte8j9duddvdwdxdPdydz��Z:edre8j9dse8j9dte8j9duddvddxdPd{d|��Z;d}d~�Z<dd��Z=d�d��Z>d�d��Z?d�d��Z@d�d��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o�ttjjd���d|_d|_d|_d|_ttd�r�tj�|_n	d|_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�sysr;�ignore_environment�bool�os�environ�get�slow_callback_duration�_current_handle�
_task_factory�_coroutine_wrapper_setr�weakref�WeakSet�
_asyncgens�_asyncgens_shutdown_called)rOrrrrP�s(													zBaseEventLoop.__init__cCs,d|jj|j�|j�|j�fS)Nz"<%s running=%s closed=%s debug=%s>)rQrR�
is_running�	is_closed�	get_debug)rOrrrrSszBaseEventLoop.__repr__cCstjd|�S)z,Create a Future object attached to the loop.rA)rZFuture)rOrrrr=szBaseEventLoop.create_futurecCsZ|j�|jdkrDtj|d|�}|jrV|jd=n|j||�}|S)zDSchedule a coroutine object.

        Return a task object.
        NrAr���)�
_check_closedrvrr�_source_traceback)rO�coroZtaskrrr�create_tasks
	
zBaseEventLoop.create_taskcCs2|dk	r%t|�r%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)�callabler1rv)rO�factoryrrr�set_task_factory#s
zBaseEventLoop.set_task_factorycCs|jS)z<Return a task factory, or None if the default one is in use.)rv)rOrrr�get_task_factory1szBaseEventLoop.get_task_factoryN�extra�servercCs
t�dS)zCreate socket transport.N)�NotImplementedError)rOr#�protocolr[r�r�rrr�_make_socket_transport5sz$BaseEventLoop._make_socket_transport�server_sideF�server_hostnamec	Cs
t�dS)zCreate SSL transport.N)r�)	rOZrawsockr��
sslcontextr[r�r�r�r�rrr�_make_ssl_transport:sz!BaseEventLoop._make_ssl_transportcCs
t�dS)zCreate datagram transport.N)r�)rOr#r�r@r[r�rrr�_make_datagram_transport@sz&BaseEventLoop._make_datagram_transportcCs
t�dS)zCreate read pipe transport.N)r�)rO�piper�r[r�rrr�_make_read_pipe_transportEsz'BaseEventLoop._make_read_pipe_transportcCs
t�dS)zCreate write pipe transport.N)r�)rOr�r�r[r�rrr�_make_write_pipe_transportJsz(BaseEventLoop._make_write_pipe_transportc	
Ks
t�dS)zCreate subprocess transport.N)r�)
rOr��args�shell�stdin�stdout�stderr�bufsizer��kwargsrrr�_make_subprocess_transportOsz(BaseEventLoop._make_subprocess_transportcCs
t�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�)rOrrr�_write_to_selfVszBaseEventLoop._write_to_selfcCs
t�dS)zProcess selector events.N)r�)rO�
event_listrrr�_process_events_szBaseEventLoop._process_eventscCs|jrtd��dS)NzEvent loop is closed)rb�RuntimeError)rOrrrr�cs	zBaseEventLoop._check_closedcCs=|jj|�|j�s9|j|j��|j�dS)N)rz�discardr}r��acloser�)rO�agenrrr�_asyncgen_finalizer_hookgsz&BaseEventLoop._asyncgen_finalizer_hookcCs<|jr(tjdj|�td|�|jj|�dS)NzNasynchronous generator {!r} was scheduled after loop.shutdown_asyncgens() call�source)r{�warnings�warn�format�ResourceWarningrz�add)rOr�rrr�_asyncgen_firstiter_hookos	
z&BaseEventLoop._asyncgen_firstiter_hookccs�d|_|jdks(t|j�r,dSt|j�}|jj�tjdd�|D�ddd|�}|EdH}xTt||�D]C\}}t|t	�r�|j
ddj|�d	|d
|i�q�WdS)z,Shutdown all active asynchronous generators.TNcSsg|]}|j��qSr)r�)�.0Zagrrr�
<listcomp>�s	z4BaseEventLoop.shutdown_asyncgens.<locals>.<listcomp>Zreturn_exceptionsrA�messagez?an error occurred during closing of asynchronous generator {!r}�	exceptionZasyncgen)r{rz�len�list�clearr�gather�zipr
rF�call_exception_handlerr�)rOZ
closing_agensZ
shutdown_coroZresults�resultr�rrr�shutdown_asyncgensxs"	
		z BaseEventLoop.shutdown_asyncgenscCs|j�|j�r"td��tj�dk	r@td��|j|j�tj�|_	|j
dk	r�tj�}tj
d|jd|j�z,tj|�x|j�|jr�Pq�WWdd|_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 runningZ	firstiterZ	finalizerF)r�r|r�rZ_get_running_loop�_set_coroutine_wrapper�_debug�	threading�	get_identrirzrnr`Zset_asyncgen_hooksr�r�Z_set_running_loop�	_run_oncerc)rOZold_agen_hooksrrr�run_forever�s0
	


				

zBaseEventLoop.run_forevercCs�|j�tj|�}tj|d|�}|r>d|_|jt�zIy|j�Wn4|r�|j	�r�|j
�r�|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.
        rAFNz+Event loop stopped before Future completed.)r�rZisfuturerZ
ensure_futureZ_log_destroy_pendingZadd_done_callbackrJr�rYZ	cancelledr�Zremove_done_callbackr�r�)rOZfutureZnew_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)rc)rOrrrrH�szBaseEventLoop.stopcCs�|j�rtd��|jr%dS|jr>tjd|�d|_|jj�|jj�|j	}|dk	r�d|_	|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 %rT�waitF)r|r�rbr�r	�debugrfr�rgrhZshutdown)rO�executorrrrrX�s			

		zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)rb)rOrrrr}�szBaseEventLoop.is_closedcCs:|j�s6tjd|t�|j�s6|j�dS)Nzunclosed event loop %r)r}r�r�r�r|rX)rOrrr�__del__�szBaseEventLoop.__del__cCs
|jdk	S)z*Returns True if the event loop is running.N)ri)rOrrrr|szBaseEventLoop.is_runningcCs
tj�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.
        )rjr_)rOrrrrjszBaseEventLoop.timecGs6|j|j�|||�}|jr2|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_atrjr�)rOZdelay�callbackr��timerrrr�
call_laters	
zBaseEventLoop.call_latercGsx|j�|jr-|j�|j|d�tj||||�}|jrX|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�heappushrg)rO�whenr�r�r�rrrr�#s
	
	
	zBaseEventLoop.call_atcGsV|j�|jr-|j�|j|d�|j||�}|jrR|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�)rOr�r�rrrrr�3s

	
	
zBaseEventLoop.call_sooncCs[tj|�stj|�r3tdj|���t|�sWtdj||���dS)Nz#coroutines cannot be used with {}()z0a callable object was expected by {}(), got {!r})rZiscoroutineZiscoroutinefunctionr1r�r�)rOr��methodrrrr�FszBaseEventLoop._check_callbackcCs<tj|||�}|jr(|jd=|jj|�|S)Nrr)r�Handler�rfr3)rOr�r�rrrrr�Qs
	
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)rir�r�r�)rOZ	thread_idrrrr�Xs	zBaseEventLoop._check_threadcGsV|j�|jr#|j|d�|j||�}|jrH|jd=|j�|S)z"Like call_soon(), but thread-safe.�call_soon_threadsaferr)r�r�r�r�r�r�)rOr�r�rrrrr�is
		

z"BaseEventLoop.call_soon_threadsafecGs{|j�|jr#|j|d�|dkr\|j}|dkr\tjj�}||_tj|j||�d|�S)N�run_in_executorrA)	r�r�r�rh�
concurrentrZThreadPoolExecutorZwrap_futureZsubmit)rOr��funcr�rrrr�ts
			zBaseEventLoop.run_in_executorcCs
||_dS)N)rh)rOr�rrr�set_default_executorsz"BaseEventLoop.set_default_executorcCsd||fg}|r*|jd|�|rA|jd|�|rX|jd|�|ro|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@�@)	r3�joinr	r�rjrr?rtrB)rOr5r6r7r%r8r;�msg�t0Zaddrinfo�dtrrr�_getaddrinfo_debug�s(
z BaseEventLoop._getaddrinfo_debugr7rr%r8r;c	CsW|jr.|jd|j||||||�S|jdtj||||||�SdS)N)r�r�r�rr?)rOr5r6r7r%r8r;rrrr?�s
	zBaseEventLoop.getaddrinfocCs|jdtj||�S)N)r�r�getnameinfo)rOZsockaddrr;rrrr��szBaseEventLoop.getnameinfo�sslr#�
local_addrc#s#|
dk	r|rtd��|
dkrI|rI|sCtd��|}
|dk	sa|dk	r�|dk	rytd��t||fd|dtjd|d|d	|�}|g}|	dk	r�t|	d|dtjd|d|d	|�}
|j|
�nd}
tj|d	|�EdH|j�}|s:td
��|
dk	rd|
j�}|sdtd
��g}xU|D]�\}}}}}y
tjd|d|d|�}|j	d�|
dk	rax�|D]�\}}}}}y|j
|�PWq�tk
rI}z9t|jdj||j
j���}|j|�WYdd}~Xq�Xq�W|j�d}wq|jr}tjd
||�|j||�EdHWnhtk
r�}z(|dk	r�|j�|j|�WYdd}~Xqq|dk	r�|j��YqqXPqqWt|�dkr"|d�q�t|d��t�fdd�|D��r[|d�tdjdjdd�|D�����n9|dkr�td��t|�s�tdj|���|j||||
�EdH\}}|jr|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 timer7r%r8r;rAz!getaddrinfo() returned empty listFz2error while attempting to bind on address {!r}: {}zconnect %r to %rrrc3s!|]}t|��kVqdS)N)r)r�rI)�modelrr�	<genexpr>sz2BaseEventLoop.create_connection.<locals>.<genexpr>zMultiple exceptions: {}z, css|]}t|�VqdS)N)r)r�rIrrrr�sz5host and port was not specified and no sock specifiedz&A Stream Socket was expected, got {!r}rz%r connected to %s:%r: (%r, %r))rrDrr&r3rr�r�r"�setblocking�bind�errnor��strerror�lowerrXr�r	r��sock_connectr�r�allr�r'�_create_connection_transport�get_extra_info)rO�protocol_factoryr5r6r�r7r8r;r#r�r��f1�fs�f2�infosZladdr_infos�
exceptionsr%Zcnamer@�_ZladdrrI�	transportr�r)r�r�create_connection�s�		

$
	



	%			zBaseEventLoop.create_connectionc
	cs�|jd�|�}|j�}|rjt|t�r=dn|}|j||||d|d|�}	n|j|||�}	y
|EdHWn|	j��YnX|	|fS)NFr�r�)r�r=r
rpr�r�rX)
rOr#r�r�r�r�r�r[r�r�rrrr�+s
	

z*BaseEventLoop._create_connection_transport�
reuse_address�
reuse_port�allow_broadcastc#s�|
dk	r�t|
�s-tdj|
����s]�s]|s]|s]|s]|s]|s]|	r�td�d�d|d|d|d|d	|d
|	�}djdd
�|j�D��}tdj|���|
jd�d}
n�p��s|dkrtd��||fdff}n<tj�}x�d�fd�ffD]�\}}|dk	rDt	|t
�r}t|�dks�td��t
|d|dtjd|d|d|�EdH}|s�td��xS|D]K\}}}}}||f}||krddg||<||||<q�WqDW��fdd�|j�D�}|s[td��g}|dkr�tjdko�tjdk}xV|D]D\\}}\}}d}
d}
y�tjd|dtjd|�}
|r�|
jtjtjd�|r	t|
�|	r(|
jtjtjd�|
jd��rH|
j|��ri|j|
|�EdH|}
Wnhtk
r�}z(|
dk	r�|
j�|j|�WYdd}~Xq�|
dk	r�|
j��Yq�XPq�W|d�|�}|j�}|j|
||
|�}|j rR�r<t!j"d��||�nt!j#d�||�y
|EdHWn|j��YnX||fS) zCreate datagram connection.Nz#A UDP Socket was expected, got {!r}r��remote_addrr7r8r;r�r�r�z, css-|]#\}}|rdj||�VqdS)z{}={}N)r�)r��k�vrrrr�Wsz9BaseEventLoop.create_datagram_endpoint.<locals>.<genexpr>zNsocket modifier keyword arguments can not be used when sock is specified. ({})Frzunexpected address familyrr<z2-tuple is expectedr%rAz!getaddrinfo() returned empty listcsNg|]D\}}�r(|ddkp;�o;|ddks||f�qS)rNrr)r��keyZ	addr_pair)r�r�rrr�xs		z:BaseEventLoop.create_datagram_endpoint.<locals>.<listcomp>zcan not get address information�posix�cygwinz@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))NN)$r)rr��dictr��itemsr�rd�OrderedDictr
�tupler�rTrDrr(r"rq�namern�platformr r!�SO_REUSEADDRr$ZSO_BROADCASTr�r�rXr3r=r�r�r	rBr�)rOr�r�r�r7r8r;r�r�r�r#ZoptsZproblemsZr_addrZaddr_pairs_infoZ
addr_infos�idxZaddrr�Zfamr�Zpror@r�r�Z
local_addressZremote_addressrIr�r[r�r)r�r�r�create_datagram_endpointCs�	
	%$	"	






				


z&BaseEventLoop.create_datagram_endpointc
csQt||fd|dtjd|d|�EdH}|sMtdj|���|S)Nr7r%r;rAz%getaddrinfo({!r}) returned empty list)rDrr&r"r�)rOr5r6r7r;r�rrr�_create_server_getaddrinfo�s	z(BaseEventLoop._create_server_getaddrinfo�backlogrc #sdt|t�rtd��|dk	s3�dk	r�|dk	rKtd��ttdd�}|	dkr�tjdko�tj	dk}	g}|dkr�dg}
n4t|t
�s�t|tj�r�|g}
n|}
����fd	d
�|
D�}t
j|d��EdH}ttjj|��}d}zWxJ|D]B}|\}}}}}ytj|||�}Wn=tjk
r��jr�tjd
|||dd�w=YnX|j|�|	r�|jtjtjd�|
r�t|�||kr!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�WXnB|dkr�td��t%|�s�tdj&|���|g}t'�|�}xA|D]9}|j(|�|j)d��j*|||||�q
W�jr`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 timer-rr�r�r,c	s.g|]$}�j|�d�d���qS)r7r;)r)r�r5)r7r;r6rOrrr��s	z/BaseEventLoop.create_server.<locals>.<listcomp>rAFz:create_server() failed to create socket.socket(%r, %r, %r)�exc_infoT�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),r
rpr1r�getattrrrqr�rnrrrd�Iterablerr��set�	itertools�chain�
from_iterable�errorr�r	�warningr3r r!rr$rrZIPV6_V6ONLYr�r"r�r�r�rXr'r�rKZlistenr�Z_start_servingrB)rOr�r5r6r7r;r#rr�r�r�r-rLZhostsr�r�Z	completed�resr9Zsocktyper8Z	canonnameZsa�errr�r)r7r;r6rOr�
create_server�s�	

		

0

	


	zBaseEventLoop.create_serverccs�t|�s!tdj|���|j|||ddd�EdH\}}|jrx|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}r,r�TNrz%r handled: (%r, %r))r'rr�r�r�r�r	r�)rOr�r#r�r�r�rrr�connect_accepted_socket.s
#	z%BaseEventLoop.connect_accepted_socketccs~|�}|j�}|j|||�}y
|EdHWn|j��YnX|jrttjd|j�||�||fS)Nz Read pipe %r connected: (%r, %r))r=r�rXr�r	r��fileno)rOr�r�r�r[r�rrr�connect_read_pipeEs	

		zBaseEventLoop.connect_read_pipeccs~|�}|j�}|j|||�}y
|EdHWn|j��YnX|jrttjd|j�||�||fS)Nz!Write pipe %r connected: (%r, %r))r=r�rXr�r	r�r)rOr�r�r�r[r�rrr�connect_write_pipeVs	

		z BaseEventLoop.connect_write_pipecCs�|g}|dk	r,|jdt|��|dk	ra|tjkra|jdt|��nF|dk	r�|jdt|��|dk	r�|jdt|��tjdj|��dS)Nzstdin=%szstdout=stderr=%sz	stdout=%sz	stderr=%s� )r3rrrr	r�r�)rOr�r�r�r�rBrrr�_log_subprocessgs	zBaseEventLoop._log_subprocessr�r�r��universal_newlinesr�Tr�c
	ks�t|ttf�s!td��|r3td��|sEtd��|dkr]td��|�}
|jr�d|}|j||||�|j|
|d|||||	�EdH}|jr�tjd||�||
fS)	Nzcmd must be a stringz universal_newlines must be Falsezshell must be Truerzbufsize must be 0zrun shell command %rTz%s: %r)	r
r/rrr�rr�r	rB)
rOr��cmdr�r�r�rr�r�r�r��	debug_logr�rrr�subprocess_shellts"		
#	zBaseEventLoop.subprocess_shellc	os	|rtd��|r$td��|dkr<td��|f|	}x<|D]4}t|ttf�sPtdt|�j��qPW|�}
|jr�d|}|j||||�|j	|
|d|||||
�EdH}|jr�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)rr
rr/r1r%rRr�rr�r	rB)rOr�Zprogramr�r�r�rr�r�r�r�Z
popen_args�argr�rr�rrr�subprocess_exec�s*

		
	zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use.
        )rl)rOrrr�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�r1r�rl)rOZhandlerrrr�set_exception_handler�s	z#BaseEventLoop.set_exception_handlerc	Cs�|jd�}|sd}|jd�}|dk	rQt|�||jf}nd}d|kr�|jdk	r�|jjr�|jj|d<|g}x�t|�D]�}|dkr�q�||}|dkrdjtj|��}d	}||j	�7}nI|dkr=djtj|��}d
}||j	�7}nt
|�}|jdj||��q�Wt
jdj|�d
|�dS)a@Default 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.

        The context parameter has the same meaning as in
        `call_exception_handler()`.
        r�z!Unhandled exception in event loopr�NFZsource_tracebackZhandle_tracebackr,z+Object created at (most recent call last):
z+Handle created at (most recent call last):
z{}: {}�
r>r�r�)rsr%�
__traceback__rur��sortedr��	traceback�format_list�rstriprr3r�r	r)	rO�contextr�r�rZ	log_linesr��value�tbrrr�default_exception_handler�s6
	
z'BaseEventLoop.default_exception_handlercCs�|jdkrKy|j|�Wq�tk
rGtjddd�Yq�Xn�y|j||�Wnptk
r�}zPy#|jddd|d|i�Wn%tk
r�tjd	dd�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 handlerrTr�z$Unhandled error in exception handlerr�r'zeException in default exception handler while handling an unexpected error in custom exception handler)rlr*rFr	r)rOr'rIrrrr��s"

z$BaseEventLoop.call_exception_handlercCsXt|tj�std��|jr+dSt|tj�sDt�|jj|�dS)z3Add a Handle to _scheduled (TimerHandle) or _ready.zA Handle is required hereN)r
rr�rT�
_cancelledr�rfr3)rOrrrr�
_add_callbacks
	zBaseEventLoop._add_callbackcCs|j|�|j�dS)z6Like _add_callback() but called from a signal handler.N)r,r�)rOrrrr�_add_callback_signalsafe's
z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)rgra)rOrrrr�_timer_handle_cancelled,s	z%BaseEventLoop._timer_handle_cancelledcCslt|j�}|tkr�|j|tkr�g}x3|jD](}|jrYd|_q>|j|�q>Wtj|�||_d|_nJxG|jr�|jdjr�|jd8_tj	|j�}d|_q�Wd}|j
s�|jr�d}n2|jr)|jdj}t
d||j��}|jr|dkr|j�}|jj|�}|j�|}|dkr�tj}	n	tj}	t|�}
|dkr�tj|	d|d|
�q+|
r�tj|	d|d|d|
�q+|dkr+tj|	d	|d|d�n|jj|�}|j|�|j�|j}xU|jr�|jd}|j|krtPtj	|j�}d|_|j
j|�qNWt|j
�}x�t|�D]�}
|j
j�}|jr�q�|jrTz[||_|j�}|j�|j�|}||jkrCtjd
t|�|�Wdd|_Xq�|j�q�Wd}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�rg�_MIN_SCHEDULED_TIMER_HANDLESra�%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr+r3r��heapify�heappoprfrcZ_when�maxrjr�Z	_selectorZselect�logging�INFO�DEBUGr	�logr�rk�range�popleftruZ_runrtrr)rOZsched_countZ
new_scheduledrZtimeoutr�r�r�r��levelZneventZend_timeZntodo�irrrr�1s�
		
	
					

				
	
zBaseEventLoop._run_oncecCs�ytj}tj}Wntk
r.dSYnXt|�}|j|krNdStj}|�}|r�|d|fkr�tj	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)rn�set_coroutine_wrapper�get_coroutine_wrapper�AttributeErrorrprwrZ
debug_wrapperr�r��RuntimeWarning)rO�enabledZset_wrapperZget_wrapper�wrapperZcurrent_wrapperrrrr��s.	

			

z$BaseEventLoop._set_coroutine_wrappercCs|jS)N)r�)rOrrrr~�szBaseEventLoop.get_debugcCs&||_|j�r"|j|�dS)N)r�r|r�)rOr@rrrrm�s	zBaseEventLoop.set_debug)GrRr]r^rPrSr=r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�rHrXr}rZPY34r�r|rjr�r�r�r�r�r�r�r�r�r�r?r�r�r�rrrr2Z
AI_PASSIVErrrrrrrrrrr r*r�r,r-r.r�r�r~rmrrrrr
�s�!		%		!	�	u				_
	,2c!).�__doc__rdZconcurrent.futuresr�r�rrr4rqrrr�rjr$rnr�rxr,rrrrrrr7r	�__all__r/r0�BrokenPipeError�ConnectionResetError�ConnectionAbortedErrorZ_FATAL_ERROR_IGNORErrr$r'r)r:r&rDrJZAbstractServerrKZAbstractEventLoopr
rrrr�<module>sL			=

/