<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>

j f                 @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d g Z d Z d Z d Z d d   Z d d   Z  d Z! e" e d  re! e j# OZ! n  e" e d  re! e j$ OZ! n  e j% d d  d d    Z& d d   Z' d d   Z( Gd d   d e j)  Z* Gd d   d e j+  Z, d S) 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   d   g      ?c             C   sH   |  j  } t j |  r: t | j t j  r: t | j  St |   Sd  S)N)		_callbackinspectZismethod
isinstance__self__r   Taskreprstr)handlecb r   8/opt/alt/python34/lib64/python3.4/asyncio/base_events.py_format_handle9   s    	$r   c             C   s4   |  t  j k r d S|  t  j k r& d St |   Sd  S)Nz<pipe>z<stdout>)
subprocessPIPESTDOUTr   )fdr   r   r   _format_pipeB   s
    r   SOCK_NONBLOCKSOCK_CLOEXECmaxsizei   c             C   s  | d t  j t  j h k s' |  d  k r+ d  S| t M} | t  j k rQ t  j } n | t  j k rl t  j } n d  St t  d  r2| t  j k r t  j t  j	 g } n	 | g } x | D]w } y\ | t  j	 k r t  j
 | |  j d  d  n t  j
 | |   | | | d |  | f f SWq t k
 r)Yq Xq Wd  Sy t j |   } WnK t k
 ry  t j |  j d  d  } Wn t k
 rd  SYn XYn X| j d k rt  j n t  j	 } | t  j | f k rd  S| | | d |  | f f S)Nr   	inet_pton%    )socketZIPPROTO_TCPZIPPROTO_UDP_SOCKET_TYPE_MASKSOCK_STREAM
SOCK_DGRAMhasattr	AF_UNSPECZAF_INETAF_INET6r!   	partitionOSError	ipaddressZIPv4Address
ValueErrorZIPv6Addressversion)hostportfamilytypeprotoZafsafaddrr   r   r   _ipaddr_infoS   s@    '	 	 !r8   c             C   sy   t  t d  r% |  j t j k r% d  S| d  d  \ } } t | | |  j |  j |  j  d  k ru t d |   n  d  S)NAF_UNIX   z2address must be resolved (IP address), got host %r)r)   r%   r3   r9   r8   r4   r5   r/   )sockaddressr1   r2   r   r   r   _check_resolved_address   s    !'r=   c             C   s=   |  j  } t | t  r, t | t  r, d  S|  j j   d  S)N)Z
_exceptionr   BaseException	Exception_loopstop)futexcr   r   r   _run_until_complete_cb   s
    	rD   c               @   sj   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z e	 d d    Z
 d S)Serverc             C   s(   | |  _  | |  _ d |  _ g  |  _ d  S)Nr   )r@   sockets_active_count_waiters)selflooprF   r   r   r   __init__   s    			zServer.__init__c             C   s   d |  j  j |  j f S)Nz<%s sockets=%r>)	__class____name__rF   )rI   r   r   r   __repr__   s    zServer.__repr__c             C   s(   |  j  d  k	 s t  |  j d 7_ d  S)Nr   )rF   AssertionErrorrG   )rI   r   r   r   _attach   s    zServer._attachc             C   sS   |  j  d k s t  |  j  d 8_  |  j  d k rO |  j d  k rO |  j   n  d  S)Nr   r   )rG   rO   rF   _wakeup)rI   r   r   r   _detach   s    zServer._detachc             C   sc   |  j  } | d  k r d  Sd  |  _  x | D] } |  j j |  q) W|  j d k r_ |  j   n  d  S)Nr   )rF   r@   Z_stop_servingrG   rQ   )rI   rF   r;   r   r   r   close   s    		zServer.closec             C   sC   |  j  } d  |  _  x* | D]" } | j   s | j |  q q Wd  S)N)rH   done
set_result)rI   waiterswaiterr   r   r   rQ      s
    		zServer._wakeupc             c   sT   |  j  d  k s |  j d  k r" d  St j d |  j  } |  j j |  | Dd  Hd  S)NrJ   )rF   rH   r   Futurer@   append)rI   rW   r   r   r   wait_closed   s
    zServer.wait_closedN)rM   
__module____qualname__rK   rN   rP   rR   rS   rQ   r   rZ   r   r   r   r   rE      s   
rE   c               @   s!  e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d d d d d d Z d d d d d d d d d d d Z	 d d d d d  Z
 d d d d  Z d d d d  Z e d d d   Z d d   Z d d    Z d! d"   Z d# d$   Z d% d&   Z d' d(   Z d) d*   Z d+ d,   Z e j rPd- d.   Z n  d/ d0   Z d1 d2   Z d3 d4   Z d5 d6   Z d7 d8   Z d9 d:   Z d; d<   Z  d= d>   Z! d? d@   Z" dA dB   Z# dC dD   Z$ dE dF dG dF dH dF dI dF dJ dK  Z% dF dL dM  Z& e d d dN d dE dF dH dF dI dF dO d dP d d d dQ dR  Z' e dS dT    Z( e d d dE dF dH dF dI dF dU d dV d dW d dO d dX dY  Z) e dZ d[    Z* e d d dE e+ j, dI e+ j- dO d d\ d] dN d dU d dV d d^ d_  Z. e d` da    Z/ e db dc    Z0 dd de   Z1 e df e2 j3 dg e2 j3 dh e2 j3 di d dj dk dl dF dm dn   Z4 e df e2 j3 dg e2 j3 dh e2 j3 di d dj d dl dF do dp   Z5 dq dr   Z6 ds dt   Z7 du dv   Z8 dw dx   Z9 dy dz   Z: d{ d|   Z; d} d~   Z< d d   Z= d d   Z> d d   Z? d S)r
   c             C   s   d |  _  d |  _ d |  _ t j   |  _ g  |  _ d  |  _ d |  _ d  |  _	 t
 j d  j |  _ d  |  _ |  j t j j o t t j j d    d |  _ d  |  _ d  |  _ d |  _ d  S)Nr   F	monotonicZPYTHONASYNCIODEBUGg?)_timer_cancelled_count_closed	_stoppingcollectionsdeque_ready
_scheduled_default_executorZ_internal_fds
_thread_idtimeZget_clock_infoZ
resolution_clock_resolution_exception_handler	set_debugsysflagsignore_environmentboolosenvirongetslow_callback_duration_current_handle_task_factory_coroutine_wrapper_set)rI   r   r   r   rK      s     											zBaseEventLoop.__init__c             C   s,   d |  j  j |  j   |  j   |  j   f S)Nz"<%s running=%s closed=%s debug=%s>)rL   rM   
is_running	is_closed	get_debug)rI   r   r   r   rN      s    zBaseEventLoop.__repr__c             C   s]   |  j    |  j d k rG t j | d |  } | j rY | j d =qY n |  j |  |  } | S)zDSchedule a coroutine object.

        Return a task object.
        NrJ   r   )_check_closedrt   r   r   _source_traceback)rI   ZcoroZtaskr   r   r   create_task   s    
	zBaseEventLoop.create_taskc             C   s5   | d k	 r( t  |  r( t d   n  | |  _ d S)aw  Set 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)callable	TypeErrorrt   )rI   Zfactoryr   r   r   set_task_factory   s    
zBaseEventLoop.set_task_factoryc             C   s   |  j  S)z<Return a task factory, or None if the default one is in use.)rt   )rI   r   r   r   get_task_factory  s    zBaseEventLoop.get_task_factoryNextraserverc            C   s
   t   d S)zCreate socket transport.N)NotImplementedError)rI   r;   protocolrW   r   r   r   r   r   _make_socket_transport  s    z$BaseEventLoop._make_socket_transportserver_sideFserver_hostnamec      	      C   s
   t   d S)zCreate SSL transport.N)r   )	rI   Zrawsockr   
sslcontextrW   r   r   r   r   r   r   r   _make_ssl_transport  s    z!BaseEventLoop._make_ssl_transportc             C   s
   t   d S)zCreate datagram transport.N)r   )rI   r;   r   r<   rW   r   r   r   r   _make_datagram_transport  s    z&BaseEventLoop._make_datagram_transportc             C   s
   t   d S)zCreate read pipe transport.N)r   )rI   piper   rW   r   r   r   r   _make_read_pipe_transport   s    z'BaseEventLoop._make_read_pipe_transportc             C   s
   t   d S)zCreate write pipe transport.N)r   )rI   r   r   rW   r   r   r   r   _make_write_pipe_transport%  s    z(BaseEventLoop._make_write_pipe_transportc	       
      K   s
   t   d S)zCreate subprocess transport.N)r   )
rI   r   argsshellstdinstdoutstderrbufsizer   kwargsr   r   r   _make_subprocess_transport*  s    z(BaseEventLoop._make_subprocess_transportc             C   s
   t   d S)zWrite 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   )rI   r   r   r   _write_to_self1  s    zBaseEventLoop._write_to_selfc             C   s
   t   d S)zProcess selector events.N)r   )rI   
event_listr   r   r   _process_events:  s    zBaseEventLoop._process_eventsc             C   s   |  j  r t d   n  d  S)NzEvent loop is closed)r_   RuntimeError)rI   r   r   r   rz   >  s    	zBaseEventLoop._check_closedc             C   s   |  j    |  j   r% t d   n  |  j |  j  t j   |  _ z" x |  j   |  j	 rJ PqJ qJ WWd d |  _	 d |  _ |  j d  Xd S)zRun until stop() is called.zEvent loop is running.NF)
rz   rv   r   _set_coroutine_wrapper_debug	threading	get_identrf   	_run_oncer`   )rI   r   r   r   run_foreverB  s    

			zBaseEventLoop.run_foreverc          	   C   s   |  j    t | t j  } t j | d |  } | rD d | _ n  | j t  y |  j	   Wn7 | r | j
   r | j   r | j   n    Yn X| j t  | j
   s t d   n  | 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.
        rJ   Fz+Event loop stopped before Future completed.)rz   r   r   rX   r   Zensure_futureZ_log_destroy_pendingZadd_done_callbackrD   r   rT   Z	cancelled	exceptionZremove_done_callbackr   result)rI   ZfutureZnew_taskr   r   r   run_until_completeS  s     
z BaseEventLoop.run_until_completec             C   s   d |  _  d S)zStop 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`   )rI   r   r   r   rA   w  s    zBaseEventLoop.stopc             C   s   |  j    r t d   n  |  j r( d S|  j rD t j d |   n  d |  _ |  j j   |  j j   |  j	 } | d k	 r d |  _	 | j
 d d  n  d S)zClose 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 loopNzClose %rTwaitF)rv   r   r_   r   r	   debugrc   clearrd   re   Zshutdown)rI   executorr   r   r   rS     s    					zBaseEventLoop.closec             C   s   |  j  S)z*Returns True if the event loop was closed.)r_   )rI   r   r   r   rw     s    zBaseEventLoop.is_closedc             C   s@   |  j    s< t j d |  t  |  j   s< |  j   q< n  d  S)Nzunclosed event loop %r)rw   warningswarnResourceWarningrv   rS   )rI   r   r   r   __del__  s    zBaseEventLoop.__del__c             C   s   |  j  d k	 S)z*Returns True if the event loop is running.N)rf   )rI   r   r   r   rv     s    zBaseEventLoop.is_runningc             C   s
   t  j   S)zReturn 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.
        )rg   r]   )rI   r   r   r   rg     s    zBaseEventLoop.timec             G   s9   |  j  |  j   | | |  } | j r5 | j d =n  | S)a8  Arrange 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   ry   )call_atrg   r{   )rI   Zdelaycallbackr   timerr   r   r   
call_later  s    	zBaseEventLoop.call_laterc             G   s   t  j |  s t  j |  r- t d   n  |  j   |  j rM |  j   n  t j | | | |   } | j	 r{ | j	 d =n  t
 j |  j |  d | _ | S)z|Like call_later(), but uses an absolute time.

        Absolute time corresponds to the event loop's time() method.
        z(coroutines cannot be used with call_at()r   Try   )r   iscoroutineiscoroutinefunctionr~   rz   r   _check_threadr   TimerHandler{   heapqheappushrd   )rI   whenr   r   r   r   r   r   r     s    
			zBaseEventLoop.call_atc             G   sB   |  j  r |  j   n  |  j | |  } | j r> | j d =n  | S)aT  Arrange 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.
        r   ry   )r   r   
_call_soonr{   )rI   r   r   r   r   r   r   	call_soon  s    
		zBaseEventLoop.call_soonc             C   sv   t  j |  s t  j |  r- t d   n  |  j   t j | | |   } | j rb | j d =n  |  j j	 |  | S)Nz*coroutines cannot be used with call_soon()r   ry   )
r   r   r   r~   rz   r   Handler{   rc   rY   )rI   r   r   r   r   r   r   r     s    
	zBaseEventLoop._call_soonc             C   sA   |  j  d k r d St j   } | |  j  k r= t d   n  d S)ao  Check 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)rf   r   r   r   )rI   Z	thread_idr   r   r   r     s    	zBaseEventLoop._check_threadc             G   s6   |  j  | |  } | j r( | j d =n  |  j   | S)z"Like call_soon(), but thread-safe.r   ry   )r   r{   r   )rI   r   r   r   r   r   r   call_soon_threadsafe  s
    	
z"BaseEventLoop.call_soon_threadsafec             G   s  t  j |  s t  j |  r- t d   n  |  j   t | t j  r | sV t  t | t j	  so t  | j
 r t j d |   } | j d   | S| j | j } } n  | d  k r |  j } | d  k r t j j t  } | |  _ q n  t j | j | |  d |  S)Nz0coroutines cannot be used with run_in_executor()rJ   )r   r   r   r~   rz   r   r   r   rO   r   
_cancelledr   rX   rU   r   _argsre   
concurrentZThreadPoolExecutor_MAX_WORKERSZwrap_futureZsubmit)rI   r   funcr   fr   r   r   run_in_executor  s$    
		zBaseEventLoop.run_in_executorc             C   s   | |  _  d  S)N)re   )rI   r   r   r   r   set_default_executor   s    z"BaseEventLoop.set_default_executorc             C   s  d | | f g } | r- | j  d |  n  | rG | j  d |  n  | ra | j  d |  n  | r{ | j  d |  n  d j |  } t j d |  |  j   } t j | | | | | |  }	 |  j   | }
 d | |
 d	 |	 f } |
 |  j k r
t j |  n t j |  |	 S)
Nz%s:%rz	family=%rztype=%rzproto=%rzflags=%rz, zGet address info %sz(Getting address info %s took %.3f ms: %rg     @@)	rY   joinr	   r   rg   r%   getaddrinforr   info)rI   r1   r2   r3   r4   r5   rl   msgt0Zaddrinfodtr   r   r   _getaddrinfo_debug#  s(    z BaseEventLoop._getaddrinfo_debugr3   r   r4   r5   rl   c      	   	   C   s   t  | | | | |  } | d  k	 rJ t j d |   } | j | g  | S|  j rx |  j d  |  j | | | | | |  S|  j d  t j | | | | | |  Sd  S)NrJ   )	r8   r   rX   rU   r   r   r   r%   r   )	rI   r1   r2   r3   r4   r5   rl   r   rB   r   r   r   r   <  s    	zBaseEventLoop.getaddrinfoc             C   s   |  j  d  t j | |  S)N)r   r%   getnameinfo)rI   Zsockaddrrl   r   r   r   r   J  s    zBaseEventLoop.getnameinfosslr;   
local_addrc            #   s0  |
 d k	 r" | r" t  d   n  |
 d k rR | rR | sI t  d   n  | }
 n  | d k	 sj | d k	 r| d k	 r t  d   n  |  j | | d | d t j d | d | } | g } |	 d k	 r|  j d | d t j d | d | |	  } | j |  n d } t j | d	 |  Dd H| j   } | s@t d
   n  | d k	 rp| j   } | spt d
   qpn  g  } xF| D]\ } } } } } yt j d | d | d |  } | j	 d  | d k	 rpx | D] \ } } } } } y | j
 |  PWqt k
 rU} z9 t | j d j | | j j     } | j |  WYd d } ~ XqXqW| j   d } w}n  |  j rt j d | |  n  |  j | |  Dd HWnn t k
 r} z+ | d k	 r| j   n  | j |  WYd d } ~ Xq}| d k	 r| j   n    Yq}XPq}Wt |  d k r:| d  qt | d    t   f d d   | D  rv| d  n  t d j d j d d   | D     n | d k rt  d   n  | j	 d  |  j | | | |
  Dd H\ } } |  j r&| j d  } t j d | | | | |  n  | | f S)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 timer3   r4   r5   rl   rJ   z!getaddrinfo() returned empty listFz2error while attempting to bind on address {!r}: {}zconnect %r to %rr   r   c             3   s!   |  ] } t  |    k Vq d  S)N)r   ).0rC   )modelr   r   	<genexpr>  s    z2BaseEventLoop.create_connection.<locals>.<genexpr>zMultiple exceptions: {}z, c             s   s   |  ] } t  |  Vq d  S)N)r   )r   rC   r   r   r   r     s    z5host and port was not specified and no sock specifiedr%   z%r connected to %s:%r: (%r, %r))r/   r   r%   r'   rY   r   r   r   r-   setblockingbinderrnoformatstrerrorlowerrS   r   r	   r   sock_connectlenr   allr   _create_connection_transportZget_extra_info)rI   protocol_factoryr1   r2   r   r3   r5   rl   r;   r   r   f1fsf2infosZladdr_infos
exceptionsr4   Zcnamer<   _ZladdrrC   	transportr   r   )r   r   create_connectionM  s    			$
		%		zBaseEventLoop.create_connectionc       	   	   c   s   |   } t  j d |   } | rc t | t  r6 d  n | } |  j | | | | d d d | } n |  j | | |  } y | Dd  HWn | j     Yn X| | f S)NrJ   r   Fr   )r   rX   r   rn   r   r   rS   )	rI   r;   r   r   r   r   rW   r   r   r   r   r   r     s    	
z*BaseEventLoop._create_connection_transportreuse_address
reuse_portallow_broadcastc            #   s  |
 d k	 r   s<  s< | s< | s< | s< | s< | s< |	 r t  d   d  d | d | d | d | d | d	 |	  } d
 j d d   | j   D  } t d j |    n  |
 j d  d } nR  p  s| d k r t d   n  | | f d  f f } nEt j   } x d   f d  f f D] \ } } | d k	 r)t | t	  rbt
 |  d k snt d   |  j d | d t j d | d | |  Dd H} | st d   n  xY | D]N \ } } } } } | | f } | | k rd d g | | <n  | | | | <qWq)q)W   f d d   | j   D } | sIt d   n  g  } | d k r|t j d k ovt j d k } n  x| D]\ \ } } \ } } d }
 d } y t j d | d t j d |  }
 | r|
 j t j t j d  n  | r-t t d  st d   q-|
 j t j t j d  n  |	 rO|
 j t j t j d  n  |
 j d    rr|
 j |  n   r|  j |
 |  Dd H| } n  Wnn t k
 r} z+ |
 d k	 r|
 j   n  | j |  WYd d } ~ Xq|
 d k	 r |
 j   n    YqXPqW| d  |   } t j d |   } |  j  |
 | | |  } |  j! r  rut" j# d    | |  qt" j$ d  | |  n  y | Dd HWn | j     Yn X| | f S)!zCreate datagram connection.Nr   remote_addrr3   r5   rl   r   r   r   z, c             s   s-   |  ]# \ } } | r d  j  | |  Vq d S)z{}={}N)r   )r   kvr   r   r   r     s    z9BaseEventLoop.create_datagram_endpoint.<locals>.<genexpr>zNsocket modifier keyword arguments can not be used when sock is specified. ({})Fr   zunexpected address familyr   r:   z2-tuple is expectedr4   z!getaddrinfo() returned empty listc                sN   g  |  ]D \ } }   r( | d  d k p;  o; | d d k s | | f  q S)r   Nr   r   )r   keyZ	addr_pair)r   r   r   r   
<listcomp>  s   	 	z:BaseEventLoop.create_datagram_endpoint.<locals>.<listcomp>zcan not get address informationposixcygwinSO_REUSEPORTz)reuse_port not supported by socket modulerJ   z@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))NN)%dictr   itemsr/   r   r   ra   OrderedDictr   tupler   rO   r   r%   r(   r-   ro   namerk   platform
setsockopt
SOL_SOCKETSO_REUSEADDRr)   r   ZSO_BROADCASTr   r   rS   rY   r   rX   r   r   r	   r   r   )rI   r   r   r   r3   r5   rl   r   r   r   r;   ZoptsZproblemsZr_addrZaddr_pairs_infoZ
addr_infosidxr7   r   Zfamr   Zpror<   r   r   Zlocal_addressZremote_addressrC   r   rW   r   r   )r   r   r   create_datagram_endpoint  s    		%$		"!	
				
z&BaseEventLoop.create_datagram_endpointc          	   c   sN   |  j  | | d | d t j d | Dd  H} | sJ t d j |    n  | S)Nr3   r4   rl   z%getaddrinfo({!r}) returned empty list)r   r%   r'   r-   r   )rI   r1   r2   r3   rl   r   r   r   r   _create_server_getaddrinfoZ  s    	z(BaseEventLoop._create_server_getaddrinfobacklogr   c             #   s  t  | t  r t d   n  | d k	 s6  d k	 r| d k	 rQ t d   n  t t d d  } |	 d k r t j d k o t j	 d k }	 n  g  } | d k r d g } n4 t  | t
  s t  | t j  r | g } n | }      f d	 d
   | D } t j d  |  Dd H} t j j |  } d } zx| D]{} | \ } } } } } y t j | | |  } Wn@ t j k
 r j rt j d | | | d d n  w@Yn X| j |  |	 r| j t j t j d  n  |
 r&t t d  s
t d   q&| j t j t j d  n  | | k r]t t d  r]| j t j t j d  n  y | j |  Wq@t k
 r} z* t | j  d | | j! j"   f   WYd d } ~ Xq@Xq@Wd } Wd | sx | D] } | j#   qWn  Xn$ | d k rt d   n  | g } t$  |  } x> | D]6 } | j% |  | j& d   j' | | | |  q+W j rt j( d |  n  | S)a  Create 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.

        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+   r   r   r   r#   c          	      s.   g  |  ]$ }  j  |  d    d   q S)r3   rl   )r   )r   r1   )r3   rl   r2   rI   r   r   r     s   	z/BaseEventLoop.create_server.<locals>.<listcomp>rJ   Fz:create_server() failed to create socket.socket(%r, %r, %r)exc_infoTr   z)reuse_port not supported by socket moduleIPPROTO_IPV6z0error while attempting to bind on address %r: %sz)Neither host/port nor sock were specifiedz%r is serving))r   rn   r~   r/   getattrr%   ro   r   rk   r   r   ra   Iterabler   Zgather	itertoolschainfrom_iterableerrorr   r	   warningrY   r   r   r   r)   r   r   ZIPV6_V6ONLYr   r-   r   r   r   rS   rE   Zlistenr   Z_start_servingr   )rI   r   r1   r2   r3   rl   r;   r   r   r   r   r+   rF   Zhostsr   r   Z	completedresr6   Zsocktyper5   Z	canonnameZsaerrr   r   )r3   rl   r2   rI   r   create_serverc  s    !
		
0
		zBaseEventLoop.create_serverc             c   s   |   } t  j d |   } |  j | | |  } y | Dd  HWn | j     Yn X|  j r} t j d | j   | |  n  | | f S)NrJ   z Read pipe %r connected: (%r, %r))r   rX   r   rS   r   r	   r   fileno)rI   r   r   r   rW   r   r   r   r   connect_read_pipe  s    	
		zBaseEventLoop.connect_read_pipec             c   s   |   } t  j d |   } |  j | | |  } y | Dd  HWn | j     Yn X|  j r} t j d | j   | |  n  | | f S)NrJ   z!Write pipe %r connected: (%r, %r))r   rX   r   rS   r   r	   r   r  )rI   r   r   r   rW   r   r   r   r   connect_write_pipe  s    	
		z BaseEventLoop.connect_write_pipec             C   s   | g } | d  k	 r/ | j  d t |   n  | d  k	 rd | t j k rd | j  d t |   nL | d  k	 r | j  d t |   n  | d  k	 r | j  d t |   n  t j d j |   d  S)Nzstdin=%szstdout=stderr=%sz	stdout=%sz	stderr=%s )rY   r   r   r   r	   r   r   )rI   r   r   r   r   r   r   r   r   _log_subprocess  s    	zBaseEventLoop._log_subprocessr   r   r   universal_newlinesr   Tr   c         	   k   s   t  | t t f  s$ t d   n  | r9 t d   n  | sN t d   n  | d k ri t d   n  |   }
 |  j r d | } |  j | | | |  n  |  j |
 | d | | | | |	  Dd  H} |  j r t j d | | f  n  | |
 f S)	Nzcmd must be a stringz universal_newlines must be Falsezshell must be Truer   zbufsize must be 0zrun shell command %rTz%s: %r)	r   bytesr   r/   r   r
  r   r	   r   )rI   r   cmdr   r   r   r  r   r   r   r   	debug_logr   r   r   r   subprocess_shell  s"    		
#	zBaseEventLoop.subprocess_shellc         	   o   s  | r t  d   n  | r* t  d   n  | d k rE t  d   n  | f |	 } x? | D]7 } t | t t f  sY t d t |  j   qY qY W|   } |  j r d | } |  j | | | |  n  |  j	 | | d | | | | |
  Dd  H} |  j rt
 j d | | f  n  | | f S)	Nz universal_newlines must be Falsezshell must be Falser   zbufsize must be 0z8program arguments must be a bytes or text string, not %szexecute program %rFz%s: %r)r/   r   r   r  r~   r4   rM   r   r
  r   r	   r   )rI   r   Zprogramr   r   r   r  r   r   r   r   Z
popen_argsargr   r  r   r   r   r   subprocess_exec  s*    		
	zBaseEventLoop.subprocess_execc             C   s>   | d k	 r1 t  |  r1 t d j |    n  | |  _ d S)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}   r~   r   ri   )rI   Zhandlerr   r   r   set_exception_handler0  s    	z#BaseEventLoop.set_exception_handlerc       	      C   s  | j  d  } | s d } n  | j  d  } | d k	 rT t |  | | j f } n d } d | k r |  j d k	 r |  j j r |  j j | d <n  | g } x t |  D] } | d k r q n  | | } | d k r	d j t j |   } d	 } | | j	   7} nI | d k rFd j t j |   } d
 } | | j	   7} n t
 |  } | j d j | |   q Wt j d j |  d | d S)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()`.
        messagez!Unhandled exception in event loopr   NFZsource_tracebackZhandle_tracebackr#   z+Object created at (most recent call last):
z+Handle created at (most recent call last):
z{}: {}
r   >   	exceptionmessage)rq   r4   __traceback__rs   r{   sortedr   	tracebackformat_listrstripr   rY   r   r	   r  )	rI   contextr  r   r   Z	log_linesr   valuetbr   r   r   default_exception_handlerA  s6    
		
z'BaseEventLoop.default_exception_handlerc             C   s   |  j  d k rK y |  j |  Wq t k
 rG t j d d d Yq Xn y |  j  |  |  Wns t k
 r } zS y& |  j i d d 6| d 6| d 6 Wn% t k
 r t j d	 d d Yn XWYd d } ~ Xn Xd S)
a  Call 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.

        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 handlerr   Tz$Unhandled error in exception handlerr  r   r  zeException in default exception handler while handling an unexpected error in custom exception handler)ri   r  r?   r	   r  )rI   r  rC   r   r   r   call_exception_handlerm  s"    	z$BaseEventLoop.call_exception_handlerc             C   sX   t  | t j  s t d   | j r+ d St  | t j  sD t  |  j j |  d S)z3Add a Handle to _scheduled (TimerHandle) or _ready.zA Handle is required hereN)r   r   r   rO   r   r   rc   rY   )rI   r   r   r   r   _add_callback  s
    	zBaseEventLoop._add_callbackc             C   s   |  j  |  |  j   d S)z6Like _add_callback() but called from a signal handler.N)r!  r   )rI   r   r   r   r   _add_callback_signalsafe  s    z&BaseEventLoop._add_callback_signalsafec             C   s   | j  r |  j d 7_ n  d S)z3Notification that a TimerHandle has been cancelled.r   N)rd   r^   )rI   r   r   r   r   _timer_handle_cancelled  s    	z%BaseEventLoop._timer_handle_cancelledc             C   s{  t  |  j  } | t k r |  j | t k r g  } x3 |  j D]( } | j rY d | _ q> | j |  q> Wt j |  | |  _ d |  _ nJ xG |  j r |  j d j r |  j d 8_ t j	 |  j  } d | _ q Wd } |  j
 s |  j r d } n5 |  j r,|  j d j } t d | |  j    } n  |  j r| d k r|  j   } |  j j |  } |  j   | } | d k rt j }	 n	 t j }	 t  |  }
 | d k rt j |	 d | d |
  q1|
 rt j |	 d | d | d |
  q1| d k r1t j |	 d	 | d | d  q1n |  j j |  } |  j |  |  j   |  j } xX |  j r|  j d } | j | k r}Pn  t j	 |  j  } d | _ |  j
 j |  qTWt  |  j
  } x t |  D] } |  j
 j   } | j rqn  |  j rcz^ | |  _ |  j   } | j   |  j   | } | |  j k rRt j d
 t |  |  n  Wd d |  _ Xq| j   qWd } d S)zRun 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.
        Fr   r   Ng      ?zpoll took %.3f ms: %s eventsg     @@z$poll %.3f ms took %.3f ms: %s eventsz"poll %.3f ms took %.3f ms: timeoutzExecuting %s took %.3f seconds) r   rd   _MIN_SCHEDULED_TIMER_HANDLESr^   %_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr   rY   r   heapifyheappoprc   r`   Z_whenmaxrg   r   Z	_selectorZselectloggingINFODEBUGr	   logr   rh   rangepopleftrs   Z_runrr   r  r   )rI   Zsched_countZnew_scheduledr   Ztimeoutr   r   r   r   levelZneventZend_timeZntodoir   r   r   r     s    
												
	zBaseEventLoop._run_oncec             C   s   y t  j } t  j } Wn t k
 r. d  SYn Xt |  } |  j | k rN d  St j } |   } | r | d  | f k r t j	 d | t
  q | |  d |  _ n< | d  | f k r t j	 d | t
  n | d   d |  _ d  S)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)rk   Zset_coroutine_wrapperZget_coroutine_wrapperAttributeErrorrn   ru   r   Zdebug_wrapperr   r   RuntimeWarning)rI   enabledZset_wrapperZget_wrapperwrapperZcurrent_wrapperr   r   r   r     s.    				

z$BaseEventLoop._set_coroutine_wrapperc             C   s   |  j  S)N)r   )rI   r   r   r   rx   3  s    zBaseEventLoop.get_debugc             C   s)   | |  _  |  j   r% |  j |  n  d  S)N)r   rv   r   )rI   r3  r   r   r   rj   6  s    	zBaseEventLoop.set_debug)@rM   r[   r\   rK   rN   r|   r   r   r   r   r   r   r   r   r   r   r   rz   r   r   rA   rS   rw   r   ZPY34r   rv   rg   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r%   r*   Z
AI_PASSIVEr  r  r  r
  r   r   r  r  r  r  r   r!  r"  r#  r   r   rx   rj   r   r   r   r   r
      s   	$		!	y	w				^	,0c!)-__doc__ra   Zconcurrent.futuresr   	functoolsr   r   r.   r   r)  ro   r%   r   r   rg   r  rk   r   r#   r   r   r   r   r   r   r,  r	   __all__r   r$  r%  r   r   r&   r)   r   r   	lru_cacher8   r=   rD   ZAbstractServerrE   ZAbstractEventLoopr
   r   r   r   r   <module>   sN   		
:
/