
    Rh0                    >   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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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Z$dZ%dZ& e'e
d      Z(dZ)d Z*d Z+d Z,d&dZ-d'dZ.d Z/ e'e
d      rd Z0nd Z0d Z1 G d  d!ejd                        Z3 G d" d#ejh                        Z5 G d$ d%ejl                        Z7y# e$ r dZY w xY w)(a  Base implementation of event loop.

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

Whenever a public API takes a callback, subsequent positional
arguments will be passed to the callback if/when it is called.  This
avoids the proliferation of trivial lambdas implementing closures.
Keyword arguments for the callback are not supported; this is a
conscious design decision, leaving the door open for keyword arguments
to modify the meaning of the API call itself.
    N   )	constants)
coroutines)events)
exceptions)futures)	protocols)sslproto)	staggered)tasks)timeouts)
transports)trsock)logger)BaseEventLoopServerd   g      ?AF_INET6iQ c                     | j                   }t        t        |dd       t        j                        rt        |j                        S t        |       S )N__self__)	_callback
isinstancegetattrr   Taskreprr   str)handlecbs     */usr/lib/python3.12/asyncio/base_events.py_format_handler    H   s=    			B'"j$/<BKK  6{    c                 h    | t         j                  k(  ry| t         j                  k(  ryt        |       S )Nz<pipe>z<stdout>)
subprocessPIPESTDOUTr   )fds    r   _format_piper'   Q   s+    	Z__	z  	 Bxr!   c                     t        t        d      st        d      	 | j                  t        j                  t        j
                  d       y # t        $ r t        d      w xY w)NSO_REUSEPORTz)reuse_port not supported by socket moduler   zTreuse_port not supported by socket module, SO_REUSEPORT defined but not implemented.)hasattrsocket
ValueError
setsockopt
SOL_SOCKETr)   OSErrorsocks    r   _set_reuseportr2   Z   s`    6>*DEE	JOOF--v/B/BAF 	J I J J	Js   /A A"c           	      P   t        t        d      sy |dt        j                  t        j                  hvs| y |t        j                  k(  rt        j                  }n%|t        j
                  k(  rt        j                  }ny |d}n<t        |t              r|dk(  rd}n$t        |t              r|dk(  rd}n	 t        |      }|t        j                  k(  r7t        j                  g}t        r#|j                  t        j                          n|g}t        | t              r| j#                  d      } d| v ry |D ]I  }	 t        j$                  ||        t        r |t        j                   k(  r|||d| |||ffc S |||d| |ffc S  y # t        t        f$ r Y y w xY w# t&        $ r Y mw xY w)N	inet_ptonr   r!    idna%)r*   r+   IPPROTO_TCPIPPROTO_UDPSOCK_STREAM
SOCK_DGRAMr   bytesr   int	TypeErrorr,   	AF_UNSPECAF_INET	_HAS_IPv6appendr   decoder4   r/   )	hostportfamilytypeprotoflowinfoscopeidafsafs	            r   _ipaddr_inforM   e   s    6;'Q**F,>,>??Lv!!!""	""	"""|	D%	 TS[	D#	42:	t9D !!!~~JJv'h${{6"
d{  		R&R6??24T47,KKK4T4L88	 ; :& 		2  		s*   7F ;9F7FFF	F%$F%c                    t        j                         }| D ]$  }|d   }||vrg ||<   ||   j                  |       & t        |j	                               }g }|dkD  r%|j                  |d   d|dz
          |d   d|dz
  = |j                  d t        j                  j                  t        j                  |       D               |S )z-Interleave list of addrinfo tuples by family.r   r   Nc              3   $   K   | ]  }|| 
 y wN ).0as     r   	<genexpr>z(_interleave_addrinfos.<locals>.<genexpr>   s      ] 	
s   )
collectionsOrderedDictrB   listvaluesextend	itertoolschainfrom_iterablezip_longest)	addrinfosfirst_address_family_countaddrinfos_by_familyaddrrF   addrinfos_lists	reordereds          r   _interleave_addrinfosrd      s     &113 1a,,*,'F#**40	1
 .5578OI!A%+,K-G!-KLMA> :Q >>? ??00!!?3
  r!   c                     | j                         s'| j                         }t        |t        t        f      ry t        j                  |       j                          y rP   )	cancelled	exceptionr   
SystemExitKeyboardInterruptr   	_get_loopstop)futexcs     r   _run_until_complete_cbrn      sB    ==?mmocJ(9:; c!r!   TCP_NODELAYc                 4   | j                   t        j                  t        j                  hv rl| j                  t        j
                  k(  rN| j                  t        j                  k(  r0| j                  t        j                  t        j                  d       y y y y Nr   )
rF   r+   r@   r   rG   r:   rH   r8   r-   ro   r0   s    r   _set_nodelayrr      sj    KKFNNFOO<<		V///

f000OOF..0B0BAF 1 0 =r!   c                      y rP   rQ   r0   s    r   rr   rr      s    r!   c                 \    t         &t        | t         j                        rt        d      y y )Nz"Socket cannot be of type SSLSocket)sslr   	SSLSocketr>   r0   s    r   _check_ssl_socketrw      s'    
:dCMM:<== ;r!   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)_SendfileFallbackProtocolc                    t        |t        j                        st        d      || _        |j                         | _        |j                         | _        |j                  | _
        |j                          |j                  |        | j                  r*| j                  j                  j                         | _        y d | _        y )Nz.transport should be _FlowControlMixin instance)r   r   _FlowControlMixinr>   
_transportget_protocol_proto
is_reading_should_resume_reading_protocol_paused_should_resume_writingpause_readingset_protocol_loopcreate_future_write_ready_fut)selftransps     r   __init__z"_SendfileFallbackProtocol.__init__   s    &*">">?LMM ))+&,&7&7&9#&,&=&=#D!&&$(OO$9$9$G$G$ID!$(D!r!   c                    K   | j                   j                         rt        d      | j                  }|y | d {    y 7 w)NzConnection closed by peer)r|   
is_closingConnectionErrorr   )r   rl   s     r   drainz_SendfileFallbackProtocol.drain   s<     ??%%'!"=>>##;		s   :AAAc                     t        d      )Nz?Invalid state: connection should have been established already.RuntimeError)r   	transports     r   connection_madez)_SendfileFallbackProtocol.connection_made   s     N O 	Or!   c                     | j                   B|%| j                   j                  t        d             n| j                   j                  |       | j                  j	                  |       y )NzConnection is closed by peer)r   set_exceptionr   r~   connection_lost)r   rm   s     r   r   z)_SendfileFallbackProtocol.connection_lost   s[      , {%%33#$BCE %%33C8##C(r!   c                 p    | j                   y | j                  j                  j                         | _         y rP   )r   r|   r   r   r   s    r   pause_writingz'_SendfileFallbackProtocol.pause_writing   s,      , $ 5 5 C C Er!   c                 b    | j                   y | j                   j                  d       d | _         y )NF)r   
set_resultr   s    r   resume_writingz(_SendfileFallbackProtocol.resume_writing   s-      (((/ $r!   c                     t        d      Nz'Invalid state: reading should be pausedr   )r   datas     r   data_receivedz'_SendfileFallbackProtocol.data_received      DEEr!   c                     t        d      r   r   r   s    r   eof_receivedz&_SendfileFallbackProtocol.eof_received  r   r!   c                 <  K   | j                   j                  | j                         | j                  r| j                   j	                          | j
                  | j
                  j                          | j                  r| j                  j                          y y wrP   )	r|   r   r~   r   resume_readingr   cancelr   r   r   s    r   restorez!_SendfileFallbackProtocol.restore  ss     $$T[[1&&OO**,  , !!((*&&KK&&( 's   BBN)__name__
__module____qualname__r   r   r   r   r   r   r   r   r   rQ   r!   r   ry   ry      s3    )O	)F
%FF
)r!   ry   c                   h    e Zd Z	 ddZd Zd Zd Zd Zd Zd Z	d	 Z
ed
        Zd Zd Zd Zd Zy)r   Nc                     || _         || _        d| _        g | _        || _        || _        || _        || _        || _        d| _	        d | _
        y )Nr   F)r   _sockets_active_count_waiters_protocol_factory_backlog_ssl_context_ssl_handshake_timeout_ssl_shutdown_timeout_serving_serving_forever_fut)r   loopsocketsprotocol_factoryssl_contextbacklogssl_handshake_timeoutssl_shutdown_timeouts           r   r   zServer.__init__  sU    
!1'&;#%9"$(!r!   c                 P    d| j                   j                   d| j                  dS )N<z	 sockets=>)	__class__r   r   r   s    r   __repr__zServer.__repr__$  s'    4>>**+9T\\4DAFFr!   c                 J    | j                   J | xj                  dz  c_        y rq   )r   r   r   s    r   _attachzServer._attach'  s#    }}(((ar!   c                     | j                   dkD  sJ | xj                   dz  c_         | j                   dk(  r| j                  | j                          y y y )Nr   r   )r   r   _wakeupr   s    r   _detachzServer._detach+  sO    !!A%%%a"t}}'<LLN (="r!   c                 |    | j                   }d | _         |D ]$  }|j                         r|j                  d        & y rP   )r   doner   )r   waiterswaiters      r   r   zServer._wakeup1  s8    -- 	(F;;=!!$'	(r!   c           
      *   | j                   ry d| _         | j                  D ]p  }|j                  | j                         | j                  j                  | j                  || j                  | | j                  | j                  | j                         r y )NT)
r   r   listenr   r   _start_servingr   r   r   r   )r   r1   s     r   r   zServer._start_serving8  su    ==MM 	,DKK&JJ%%&&d.?.?dmmT%@%@**,	,r!   c                     | j                   S rP   )r   r   s    r   get_loopzServer.get_loopC  s    zzr!   c                     | j                   S rP   )r   r   s    r   
is_servingzServer.is_servingF  s    }}r!   c                 T    | j                   yt        d | j                   D              S )NrQ   c              3   F   K   | ]  }t        j                  |        y wrP   )r   TransportSocket)rR   ss     r   rT   z!Server.sockets.<locals>.<genexpr>M  s     F1V++A.Fs   !)r   tupler   s    r   r   zServer.socketsI  s$    == FFFFr!   c                 P   | j                   }|y d | _         |D ]  }| j                  j                  |        d| _        | j                  ;| j                  j                         s!| j                  j                          d | _        | j                  dk(  r| j                          y y )NFr   )	r   r   _stop_servingr   r   r   r   r   r   )r   r   r1   s      r   closezServer.closeO  s    --? 	+DJJ$$T*	+ %%1--224%%,,.(,D%"LLN #r!   c                 j   K   | j                          t        j                  d       d {    y 7 w)Nr   )r   r   sleepr   s    r   start_servingzServer.start_servingb  s%      kk!ns   )313c                   K   | j                   t        d| d      | j                  t        d| d      | j                          | j                  j                         | _         	 | j                    d {    	 d | _         y 7 # t        j                  $ r1 	 | j                          | j                          d {  7    #  xY ww xY w# d | _         w xY ww)Nzserver z, is already being awaited on serve_forever()z
 is closed)
r   r   r   r   r   r   r   CancelledErrorr   wait_closedr   s    r   serve_foreverzServer.serve_foreverh  s     $$0$!MNP P== 
;<<$(JJ$<$<$>!		-++++ )-D% ,(( 	

&&(((	 )-D%s`   A&C)B 8B9B >CB C#C?C CCCCC 	CCc                    K   | j                   y| j                  j                         }| j                   j                  |       | d{    y7 w)a  Wait until server is closed and all connections are dropped.

        - If the server is not closed, wait.
        - If it is closed, but there are still active connections, wait.

        Anyone waiting here will be unblocked once both conditions
        (server is closed and all connections have been dropped)
        have become true, in either order.

        Historical note: In 3.11 and before, this was broken, returning
        immediately if the server was already closed, even if there
        were still active connections. An attempted fix in 3.12.0 was
        still broken, returning immediately if the server was still
        open and there were no active connections. Hopefully in 3.12.1
        we have it right.
        N)r   r   r   rB   )r   r   s     r   r   zServer.wait_closed}  s@     * == ))+V$s   AA
AArP   )r   r   r   r   r   r   r   r   r   r   r   propertyr   r   r   r   r   rQ   r!   r   r   r     s[     >B)G (	, G G
&-*r!   r   c                      e Zd Zd Zd Zd ZddddZd Zd Zd\ddd	d
Z		 d\dddddddddZ
	 d]dZ	 	 d^dZ	 	 d^dZ	 d\dZd Zd Zd Zd Zd Zd Zd Zd\dZd Zd Zd Zd Zd Zd  Zd! Zej>                  fd"Z d# Z!d$ Z"dd%d&Z#dd%d'Z$dd%d(Z%d) Z&d* Z'd+ Z(dd%d,Z)d- Z*d. Z+d/ Z,d0d0d0d0d1d2Z-d_d3Z.d`dd4d5Z/d6 Z0d7 Z1d8 Z2d\d9Z3	 d^dd0d0d0ddddddddd:d;Z4	 	 	 dad<Z5d`dd4d=Z6d> Z7d? Z8ddddd@dAZ9	 d^d0d0d0ddddBdCZ:d0e;jx                  d0d0d1dDZ=dE Z>	 d^e;j~                  e;j                  ddFdddddddG
dHZAddddIdJZBdK ZCdL ZDdM ZEeFj                  eFj                  eFj                  ddd0ddddN	dOZHeFj                  eFj                  eFj                  ddd0ddddN	dPZIdQ ZJdR ZKdS ZLdT ZMdU ZNdV ZOdW ZPdX ZQdY ZRdZ ZSd[ ZTy)br   c                    d| _         d| _        d| _        t        j                         | _        g | _        d | _        d| _        d | _	        t        j                  d      j                  | _        d | _        | j                  t!        j"                                d| _        d | _        d | _        d| _        d | _        t/        j0                         | _        d| _        d| _        y )Nr   F	monotonicg?)_timer_cancelled_count_closed	_stoppingrU   deque_ready
_scheduled_default_executor_internal_fds
_thread_idtimeget_clock_info
resolution_clock_resolution_exception_handler	set_debugr   _is_debug_modeslow_callback_duration_current_handle_task_factory"_coroutine_origin_tracking_enabled&_coroutine_origin_tracking_saved_depthweakrefWeakSet
_asyncgens_asyncgens_shutdown_called_executor_shutdown_calledr   s    r   r   zBaseEventLoop.__init__  s    &'#!'')!% !%!4!4[!A!L!L"&z0023 '*##!27/6:3 "//+*/').&r!   c           	          d| j                   j                   d| j                          d| j                          d| j	                          d	S )Nr   z	 running=z closed=z debug=r   )r   r   
is_running	is_closed	get_debugr   s    r   r   zBaseEventLoop.__repr__  sP    ''(	$//2C1D Enn&'wt~~/?.@C	
r!   c                 .    t        j                  |       S )z,Create a Future object attached to the loop.r   )r   Futurer   s    r   r   zBaseEventLoop.create_future  s    ~~4((r!   N)namecontextc                $   | j                          | j                  4t        j                  || ||      }|j                  r|j                  d= |S || j                  | |      }n| j                  | ||      }t        j
                  ||       |S )zDSchedule a coroutine object.

        Return a task object.
        )r   r  r	  r	  )_check_closedr   r   r   _source_traceback_set_task_name)r   coror  r	  tasks        r   create_taskzBaseEventLoop.create_task  s    
 	%::dD'JD%%**2.  ))$5))$g)F  t,r!   c                 B    |t        |      st        d      || _        y)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)callabler>   r   )r   factorys     r   set_task_factoryzBaseEventLoop.set_task_factory  s%     x'8EFF$r!   c                     | j                   S )z<Return a task factory, or None if the default one is in use.)r   r   s    r   get_task_factoryzBaseEventLoop.get_task_factory  s    !!!r!   )extraserverc                    t         )zCreate socket transport.NotImplementedError)r   r1   protocolr   r  r  s         r   _make_socket_transportz$BaseEventLoop._make_socket_transport  
     "!r!   FT)server_sideserver_hostnamer  r  r   r   call_connection_madec                    t         )zCreate SSL transport.r  )r   rawsockr  
sslcontextr   r!  r"  r  r  r   r   r#  s               r   _make_ssl_transportz!BaseEventLoop._make_ssl_transport  s
     "!r!   c                     t         )zCreate datagram transport.r  )r   r1   r  addressr   r  s         r   _make_datagram_transportz&BaseEventLoop._make_datagram_transport  r   r!   c                     t         )zCreate read pipe transport.r  r   piper  r   r  s        r   _make_read_pipe_transportz'BaseEventLoop._make_read_pipe_transport  r   r!   c                     t         )zCreate write pipe transport.r  r,  s        r   _make_write_pipe_transportz(BaseEventLoop._make_write_pipe_transport  r   r!   c	                    K   t         w)zCreate subprocess transport.r  )
r   r  argsshellstdinstdoutstderrbufsizer  kwargss
             r   _make_subprocess_transportz(BaseEventLoop._make_subprocess_transport  s      "!s   	c                     t         )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.
        r  r   s    r   _write_to_selfzBaseEventLoop._write_to_self  s
     "!r!   c                     t         )zProcess selector events.r  )r   
event_lists     r   _process_eventszBaseEventLoop._process_events  s    !!r!   c                 2    | j                   rt        d      y )NzEvent loop is closed)r   r   r   s    r   r  zBaseEventLoop._check_closed  s    <<566 r!   c                 2    | j                   rt        d      y )Nz!Executor shutdown has been called)r   r   r   s    r   _check_default_executorz%BaseEventLoop._check_default_executor  s    ))BCC *r!   c                     | j                   j                  |       | j                         s+| j                  | j                  |j                                y y rP   )r   discardr  call_soon_threadsafer  acloser   agens     r   _asyncgen_finalizer_hookz&BaseEventLoop._asyncgen_finalizer_hook#  s?    %~~%%d&6&6F  r!   c                     | j                   r t        j                  d|dt        |        | j                  j                  |       y )Nzasynchronous generator z3 was scheduled after loop.shutdown_asyncgens() callsource)r   warningswarnResourceWarningr   addrF  s     r   _asyncgen_firstiter_hookz&BaseEventLoop._asyncgen_firstiter_hook(  sA    **MM)$ 21 2.
 	D!r!   c                   K   d| _         t        | j                        syt        | j                        }| j                  j	                          t        j                  |D cg c]  }|j                          c}ddi d{   }t        ||      D ].  \  }}t        |t              s| j                  d|||d       0 yc c}w 7 Gw)z,Shutdown all active asynchronous generators.TNreturn_exceptionsz;an error occurred during closing of asynchronous generator )messagerg   asyncgen)r   lenr   rW   clearr   gatherrE  zipr   	Exceptioncall_exception_handler)r   closing_agensagresultsresultrG  s         r   shutdown_asyncgensz BaseEventLoop.shutdown_asyncgens1  s     *.'4??# T__-$12bbiik2$"$ $  7 	LFD&),++"99= B!' $	- 	 3$s$   A C"C9
CC&C+!Cc                   K   d| _         | j                  y| j                         }t        j                  | j
                  |f      }|j                          	 t        j                  |      4 d{    | d{    ddd      d{    |j                          y7 /7 '7 # 1 d{  7  sw Y   )xY w# t        $ r? t        j                  d| dt        d       | j                  j                  d	       Y yw xY ww)
a  Schedule the shutdown of the default executor.

        The timeout parameter specifies the amount of time the executor will
        be given to finish joining. The default value is None, which means
        that the executor will be given an unlimited amount of time.
        TN)targetr2  z:The executor did not finishing joining its threads within z	 seconds.   )
stacklevelFwait)r   r   r   	threadingThread_do_shutdownstartr   timeoutjoinTimeoutErrorrL  rM  RuntimeWarningshutdown)r   rj  futurethreads       r   shutdown_default_executorz'BaseEventLoop.shutdown_default_executorJ  s      *.&!!)##%!!):):&K		''0    KKM    	8MM 007y	C(Q8 ""+++7		8s   AD	B> 3B#4B> 7B)=B%>B)B> B'B> D	#B> %B)'B> )B;/B20B;7B> >ADD	DD	c                 Z   	 | j                   j                  d       | j                         s"| j                  t        j
                  |d        y y # t        $ rP}| j                         s6|j                         s!| j                  |j                  |       Y d }~y Y d }~y Y d }~y d }~ww xY w)NTrd  )	r   rn  r  rD  r   _set_result_unless_cancelledrY  rf   r   )r   ro  exs      r   rh  zBaseEventLoop._do_shutdownb  s    	D""+++6>>#))'*N*N*0$8 $  	D>>#F,<,<,>))&*>*>CC -?#	Ds   AA 	B*<B%%B*c                 x    | j                         rt        d      t        j                         t        d      y )Nz"This event loop is already runningz7Cannot run the event loop while another loop is running)r  r   r   _get_running_loopr   s    r   _check_runningzBaseEventLoop._check_runningl  s>    ??CDD##%1IK K 2r!   c                    | j                          | j                          | j                  | j                         t	        j
                         }	 t        j                         | _        t	        j                  | j                  | j                         t        j                  |        	 | j                          | j                  rn	 d| _        d| _        t        j                  d       | j                  d       t	        j                  |  y# d| _        d| _        t        j                  d       | j                  d       t	        j                  |  w xY w)zRun until stop() is called.)	firstiter	finalizerFN)r  rw  _set_coroutine_origin_tracking_debugsysget_asyncgen_hooksrf  	get_identr   set_asyncgen_hooksrP  rH  r   _set_running_loop	_run_oncer   )r   old_agen_hookss     r   run_foreverzBaseEventLoop.run_forevers  s   ++DKK8//1	4'113DO""T-J-J-1-J-JL $$T* >>  "DN"DO$$T*//6""N3	 #DN"DO$$T*//6""N3s   A8D AEc                     | j                          | j                          t        j                  |       }t	        j
                  ||       }|rd|_        |j                  t               	 | j                          	 |j                  t               |j                         st        d      |j                         S #  |r0|j                         r |j                         s|j                           xY w# |j                  t               w xY w)a\  Run until the Future is done.

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

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

        Return the Future's result, or raise its exception.
        r  Fz+Event loop stopped before Future completed.)r  rw  r   isfuturer   ensure_future_log_destroy_pendingadd_done_callbackrn   r  r   rf   rg   remove_done_callbackr   r^  )r   ro  new_tasks      r   run_until_completez BaseEventLoop.run_until_complete  s     	''//$$V$7 +0F'  !78
	@ ''(>?{{}LMM}}	FKKM&2B2B2D   "''(>?s   -B> >5C33C6 6Dc                     d| _         y)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   r   s    r   rk   zBaseEventLoop.stop  s     r!   c                 l   | j                         rt        d      | j                  ry| j                  rt	        j
                  d|        d| _        | j                  j                          | j                  j                          d| _	        | j                  }|d| _
        |j                  d       yy)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 %rTFrd  )r  r   r   r|  r   debugr   rV  r   r   r   rn  r   executors     r   r   zBaseEventLoop.close  s     ??BCC<<;;LLT*)-&))%)D"5)  r!   c                     | j                   S )z*Returns True if the event loop was closed.)r   r   s    r   r  zBaseEventLoop.is_closed  s    ||r!   c                     | j                         s4 |d| t        |        | j                         s| j                          y y y )Nzunclosed event loop rJ  )r  rN  r  r   )r   _warns     r   __del__zBaseEventLoop.__del__  s=    ~~(1?4P??$

 %  r!   c                     | j                   duS )z*Returns True if the event loop is running.N)r   r   s    r   r  zBaseEventLoop.is_running  s    t+,r!   c                 *    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.
        )r   r   r   s    r   r   zBaseEventLoop.time  s     ~~r!   r  c                    |t        d       | j                  | j                         |z   |g|d|i}|j                  r|j                  d= |S )a;  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 is undefined which
        will be called first.

        Any positional arguments after the callback will be passed to
        the callback when it is called.
        zdelay must not be Noner	  r  )r>   call_atr   r  )r   delaycallbackr	  r2  timers         r   
call_laterzBaseEventLoop.call_later  s_      =455TYY[50( .T .%,.""''+r!   c                N   |t        d      | j                          | j                  r"| j                          | j	                  |d       t        j                  |||| |      }|j                  r|j                  d= 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when cannot be Noner  r  T)r>   r  r|  _check_thread_check_callbackr   TimerHandler  heapqheappushr   )r   whenr  r	  r2  r  s         r   r  zBaseEventLoop.call_at  s    
 <122;;   95""44wG""''+t.r!   c                    | j                          | j                  r"| j                          | j                  |d       | j	                  |||      }|j
                  r|j
                  d= |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.
        	call_soonr  )r  r|  r  r  
_call_soonr  r   r  r	  r2  r   s        r   r  zBaseEventLoop.call_soon  sa     	;;   ;749##((,r!   c                     t        j                  |      st        j                  |      rt        d| d      t	        |      st        d| d|      y )Nzcoroutines cannot be used with z()z"a callable object was expected by z(), got )r   iscoroutineiscoroutinefunctionr>   r  )r   r  methods      r   r  zBaseEventLoop._check_callback$  sg    ""8,..x81&<> >!4VH =l$% % "r!   c                     t        j                  ||| |      }|j                  r|j                  d= | j                  j	                  |       |S )Nr  )r   Handler  r   rB   )r   r  r2  r	  r   s        r   r  zBaseEventLoop._call_soon.  sD    xtW=##((,6"r!   c                 z    | j                   yt        j                         }|| j                   k7  rt        d      y)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)r   rf  r  r   )r   	thread_ids     r   r  zBaseEventLoop._check_thread5  sB     ??"'')	''( ( (r!   c                    | j                          | j                  r| j                  |d       | j                  |||      }|j                  r|j                  d= | j                          |S )z"Like call_soon(), but thread-safe.rD  r  )r  r|  r  r  r  r;  r  s        r   rD  z"BaseEventLoop.call_soon_threadsafeF  s`    ;;  +AB49##((,r!   c                 <   | j                          | j                  r| j                  |d       |E| j                  }| j	                          |'t
        j                  j                  d      }|| _        t        j                   |j                  |g| |       S )Nrun_in_executorasyncio)thread_name_prefixr  )
r  r|  r  r   rA  
concurrentr   ThreadPoolExecutorwrap_futuresubmit)r   r  funcr2  s       r   r  zBaseEventLoop.run_in_executorQ  s    ;;  '89--H((*%--@@'0 A  *2&""HOOD(4(t5 	5r!   c                 p    t        |t        j                  j                        st	        d      || _        y )Nz,executor must be ThreadPoolExecutor instance)r   r  r   r  r>   r   r  s     r   set_default_executorz"BaseEventLoop.set_default_executora  s,    (J$6$6$I$IJJKK!)r!   c                 "   | d|g}|r|j                  d|       |r|j                  d|       |r|j                  d|       |r|j                  d|       dj                  |      }t        j                  d|       | j	                         }t        j                  ||||||      }	| j	                         |z
  }
d| d	|
d
z  dd|	}|
| j                  k\  rt        j                  |       |	S t        j                  |       |	S )N:zfamily=ztype=zproto=zflags=, zGet address info %szGetting address info z took g     @@z.3fzms: )	rB   rk  r   r  r   r+   getaddrinfor   info)r   rD   rE   rF   rG   rH   flagsmsgt0addrinfodts              r   _getaddrinfo_debugz BaseEventLoop._getaddrinfo_debugf  s   q!"JJ
+,JJth'(JJy)*JJy)*iin*C0YY[%%dD&$uMYY[2%cU&c#d8,O,,,KK  LLr!   r   rF   rG   rH   r  c          
         K   | j                   r| j                  }nt        j                  }| j	                  d |||||||       d {   S 7 wrP   )r|  r  r+   r  r  )r   rD   rE   rF   rG   rH   r  getaddr_funcs           r   r  zBaseEventLoop.getaddrinfo~  sU     ;;22L!--L)),dFD%H H 	H Hs   AAAAc                 b   K   | j                  d t        j                  ||       d {   S 7 wrP   )r  r+   getnameinfo)r   sockaddrr  s      r   r  zBaseEventLoop.getnameinfo  s2     ))&$$h7 7 	7 7s   &/-/)fallbackc                Z  K   | j                   r|j                         dk7  rt        d      t        |       | j	                  ||||       	 | j                  ||||       d {   S 7 # t        j                  $ r}|s Y d }~nd }~ww xY w| j                  ||||       d {  7  S w)Nr   zthe socket must be non-blocking)	r|  
gettimeoutr,   rw   _check_sendfile_params_sock_sendfile_nativer   SendfileNotAvailableError_sock_sendfile_fallback)r   r1   fileoffsetcountr  rm   s          r   sock_sendfilezBaseEventLoop.sock_sendfile  s     ;;4??,1>??$##D$>	33D$4:EC C C C33 	 	 11$28%A A A 	AsN   A
B+A+ $A)%A+ (B+)A+ +B>BB+BB+%B(&B+c                 B   K   t        j                  d|d|d      w)Nz-syscall sendfile is not available for socket z
 and file z combinationr   r  r   r1   r  r  r  s        r   r  z#BaseEventLoop._sock_sendfile_native  s4      22;D8 Dx|-. 	.s   c                 8  K   |r|j                  |       |rt        |t        j                        nt        j                  }t	        |      }d}	 	 |rt        ||z
  |      }|dk  rnYt        |      d | }| j                  d |j                  |       d {   }	|	sn#| j                  ||d |	        d {    ||	z  }p||dkD  r"t        |d      r|j                  ||z          S S S 7 S7 5# |dkD  r"t        |d      r|j                  ||z          w w w xY ww)Nr   seek)
r  minr   !SENDFILE_FALLBACK_READBUFFER_SIZE	bytearray
memoryviewr  readintosock_sendallr*   )
r   r1   r  r  r  	blocksizebuf
total_sentviewreads
             r   r  z%BaseEventLoop._sock_sendfile_fallback  s1    IIf  yBBC#EE 	 	"
	/ #EJ$6	 BI A~!#z	2!11$tLL''d5Dk:::d"
  A~'$"7		&:-. #8~ M ; A~'$"7		&:-. #8~sC   ADAC. C*C. 6C,7C. (D*C. ,C. .)DDc                    dt        |dd      vrt        d      |j                  t        j                  k(  st        d      |It        |t              st        dj                  |            |dk  rt        dj                  |            t        |t              st        dj                  |            |dk  rt        dj                  |            y )Nbmodez$file should be opened in binary modez+only SOCK_STREAM type sockets are supportedz+count must be a positive integer (got {!r})r   z0offset must be a non-negative integer (got {!r}))	r   r,   rG   r+   r:   r   r=   r>   formatr  s        r   r  z$BaseEventLoop._check_sendfile_params  s    gdFC00CDDyyF...JKKeS)AHHOQ Qz AHHOQ Q&#&BII  A:BII  r!   c                   K   g } |j                   |       |\  }}}}}	d}
	 t        j                  |||      }
|
j                  d       |G|D ]!  \  }}}}}||k7  r	 |
j                  |        n" |r|j                         t	        d|d      | j                  |
|	       d{    |
dx}}S # t        $ rQ}d|d|j
                  j                          }t	        |j                  |      }|j                  |       Y d}~d}~ww xY w7 g# t        $ r)}|j                  |       |
|
j                           d}~w |
|
j                           xY w# dx}}w xY ww)z$Create, bind and connect one socket.NrF   rG   rH   F*error while attempting to bind on address : z&no matching local address with family=z found)rB   r+   setblockingbindr/   strerrorlowererrnopopsock_connectr   )r   r   	addr_infolocal_addr_infosmy_exceptionsrF   type_rH   _r)  r1   lfamilyladdrrm   r  s                  r   _connect_sockzBaseEventLoop._connect_sock  s    
-(+4(ua$	.==U%HDU#+/? Y+GQ1e&( 
2		%(Y  %+//11%(OyPV&WXX##D'222 *.-J3 # 2'',ir"||11346 
 &cii5%,,S112 3 	  %

	

)--Jsk   E$<D B409D )D*D /E$4	D=AD	D 	DD 	E$E  EE E!!E$)ru   rF   rH   r  r1   
local_addrr"  r   r   happy_eyeballs_delay
interleave
all_errorsc                D   K   |
|st        d      |
|r|st        d      |}
||st        d      ||st        d      |t        |       ||d}|||t        d       j                  ||f|t        j                  ||        d{   }|st        d	      |	: j                  |	|t        j                  ||        d{   st        d	      d|rt        ||      }g |%|D ]  }	  j                  |       d{   } n1 n/t        j                   fd
|D        |        d{   \  }}}|ʉD cg c]  }|D ]  }|  c}}	 |rt        d      t              dk(  rd   t        d         t        fdD              rd   t        dj                  dj                  d D                          |t        d      |j                   t        j                  k7  rt        d|       j#                  ||||
||       d{   \  }} j$                  r+|j'                  d      }t)        j*                  d|||||       ||fS 7 7 7 g# t
        $ r Y w xY w7 Kc c}}w # dw xY w7 kw)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 host1ssl_handshake_timeout is only meaningful with ssl0ssl_shutdown_timeout is only meaningful with sslr   8host/port and sock can not be specified at the same timerF   rG   rH   r  r   !getaddrinfo() returned empty listc              3   b   K   | ]&  }t        j                  j                  |       ( y wrP   )	functoolspartialr  )rR   r  r   laddr_infosr   s     r   rT   z2BaseEventLoop.create_connection.<locals>.<genexpr>W  s4      ,! &&t'9'9'18[J ,s   ,/r  zcreate_connection failedr   c              3   :   K   | ]  }t        |      k(    y wrP   r   )rR   rm   models     r   rT   z2BaseEventLoop.create_connection.<locals>.<genexpr>f  s     GSs3x50Gs   zMultiple exceptions: {}r  c              3   2   K   | ]  }t        |        y wrP   r  )rR   rm   s     r   rT   z2BaseEventLoop.create_connection.<locals>.<genexpr>k  s     %E3c#h%Es   z5host and port was not specified and no sock specified"A Stream Socket was expected, got )r   r   r+   z%r connected to %s:%r: (%r, %r))r,   rw   _ensure_resolvedr+   r:   r/   rd   r  r   staggered_raceExceptionGrouprU  r   allr  rk  rG   _create_connection_transportr|  get_extra_infor   r  )r   r   rD   rE   ru   rF   rH   r  r1   r   r"  r   r   r  r  r  infosr  r  subrm   r   r  r   r  r  s   `                      @@@r   create_connectionzBaseEventLoop.create_connection  so    ( &sJKK"s   "A B B"O ,SCE E  +CBD D d#+
0BJt/ NP P //tV''uE 0 N NE ABB%$($9$9v++5d %: %, , #!"EFF"-eZ@J#+ % !H!%)%7%7&+&?  ?	! $-#;#;,%*, )t	$5 5
a |-7Gc3GCcGcG
&!,-GTT:!+(m+ !$JqM 2GJGG",Q-/ &&?&F&F II%E*%EE'G H H | KM MyyF... !8AC C %)$E$E"C"7!5 %F %7 7	8 ;; ++H5DLL:tT9h@(""_N," ? # ! !5 H  "&J 7s   BJ I5;J I8*J >I>I;I>*J JJ J#J (A8J  AJ 2J3AJ 8J ;I>>	JJ 
JJ J JJ c           
      .  K   |j                  d        |       }| j                         }	|r.t        |t              rd n|}
| j	                  |||
|	||||      }n| j                  |||	      }	 |	 d {    ||fS 7 #  |j                           xY ww)NFr!  r"  r   r   )r  r   r   boolr'  r  r   )r   r1   r   ru   r"  r!  r   r   r  r   r&  r   s               r   r  z*BaseEventLoop._create_connection_transport  s      	#%##%!+C!6CJ00h
F'&;%9	 1 ;I 33D(FKI	LL
 ("" 	OOs0   A,B/A? 4A=5A? 9B=A? ?BBc                  K   |j                         rt        d      t        |dt        j                  j
                        }|t        j                  j
                  u rt        d|      |t        j                  j                  u r	 | j                  ||||       d{   S |st        d|      | j                  ||||       d{   S 7 0# t        j                  $ r}|s Y d}~Id}~ww xY w7 )w)a  Send a file to transport.

        Return the total number of bytes which were sent.

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

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

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

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

        Raise SendfileNotAvailableError if the system does not support
        sendfile syscall and fallback is False.
        zTransport is closing_sendfile_compatiblez(sendfile is not supported for transport NzHfallback is disabled and native sendfile is not supported for transport )r   r   r   r   _SendfileModeUNSUPPORTED
TRY_NATIVE_sendfile_nativer   r  _sendfile_fallback)r   r   r  r  r  r  r  rm   s           r   sendfilezBaseEventLoop.sendfile  s    0 !566y"8 ..::<9**666:9-HJ J9**555!229d395B B B ++4-9: : ,,Y-3U< < 	<B77   <sN   BC9
C !C"C %(C9C7C9C C4'C/*C9/C44C9c                 4   K   t        j                  d      w)Nz!sendfile syscall is not supportedr  )r   r   r  r  r  s        r   r$  zBaseEventLoop._sendfile_native  s     22/1 	1s   c                   K   |r|j                  |       |rt        |d      nd}t        |      }d}t        |      }	 	 |rSt        ||z
  |      }|dk  r?||dkD  r t	        |d      r|j                  ||z          |j                          d {    S t        |      d | }	| j                  d |j                  |	       d {   }
|
s?||dkD  r t	        |d      r|j                  ||z          |j                          d {    S |j                          d {    |j                  |	d |
        ||
z  }7 7 y7 ;7 $# |dkD  r t	        |d      r|j                  ||z          |j                          d {  7   w xY ww)Ni @  r   r  )r  r  r  ry   r*   r   r  r  r  r   write)r   r   r  r  r  r  r  r  rH   r  r  s              r   r%  z BaseEventLoop._sendfile_fallback  sx    IIf).Cu%E		"
)&1	" #EJ$6	 BI A~) A~'$"7		&:-.--/!! "#z	2!11$tLL%
 A~'$"7		&:-.--/!! kkm##T%4[)d"
  " M " $ A~'$"7		&:-.--/!!s   <FE 8FD;F.E D=E 8FD?F	E EE ;F=E ?FE 9F<E?=FFr  c                n  K   t         t        d      t        |t         j                        st	        d|      t        |dd      st	        d|d      | j                         }t        j                  | |||||||d	      }	|j                          |j                  |	       | j                  |	j                  |      }
| j                  |j                        }	 | d{    |	j"                  S 7 # t        $ r2 |j                          |
j!                          |j!                           w xY ww)	zzUpgrade transport to TLS.

        Return a new transport that *protocol* should start using
        immediately.
        Nz"Python ssl module is not availablez@sslcontext is expected to be an instance of ssl.SSLContext, got _start_tls_compatibleFz
transport z  is not supported by start_tls())r   r   r#  )ru   r   r   
SSLContextr>   r   r   r
   SSLProtocolr   r   r  r   r   BaseExceptionr   r   _app_transport)r   r   r  r&  r!  r"  r   r   r   ssl_protocol
conmade_cb	resume_cbs               r   	start_tlszBaseEventLoop.start_tls  s=     ;CDD*cnn5!n&' ' y"95AYM)IJL L ##%++(J"7!5!&( 	!|,^^L$@$@)L
NN9#;#;<		LL ***  	OO		s0   CD5C7 $C5%C7 )D55C7 7;D22D5)rF   rH   r  
reuse_portallow_broadcastr1   c          	      D  K   |	|	j                   t        j                  k(  rt        d|	      |s|s
|s|s|s|s|rGt	        |||||||      }
dj                  d |
j                         D              }t        d| d      |	j                  d       d}nb|s|s|d	k(  rt        d
      ||fdff}nt        t        d      r|t        j                  k(  r||fD ]   }|t        |t              rt        d       |rO|d	   dvrH	 t        j                  t        j                  |      j                         rt        j"                  |       ||f||fff}ni }d	|fd|ffD ]  \  }}|	t        |t,              rt/        |      dk(  st        d      | j1                  ||t        j2                  |||        d{   }|st'        d      |D ]  \  }}}}}||f}||vrddg||<   |||   |<   !  |j                         D cg c]  \  }}|r|d	   |r|d   ||f }}}|st        d      g }|D ]  \  \  }}\  }}d}	d}	 t        j                  |t        j2                  |      }	|rt5        |	       |r/|	j7                  t        j8                  t        j:                  d       |	j                  d       |r|	j=                  |       |r|s| j?                  |	|       d{    |} n |d	    |       }| jE                         }| jG                  |	|||      }| jH                  r4|rt)        jJ                  d||||       nt)        jL                  d|||       	 | d{    ||fS # t$        $ r Y 0t&        $ r"}t)        j*                  d||       Y d}~Ud}~ww xY w7 c c}}w 7 # t&        $ r/}|	|	jA                           |jB                  |       Y d}~d}~w |	|	jA                           xY w7 #  |jA                           xY ww)zCreate datagram connection.Nz$A datagram socket was expected, got )r   remote_addrrF   rH   r  r4  r5  r  c              3   6   K   | ]  \  }}|s	| d |   yw)=NrQ   )rR   kvs      r   rT   z9BaseEventLoop.create_datagram_endpoint.<locals>.<genexpr>3  s      $NDAqAs!A3Z$Ns   
zKsocket modifier keyword arguments can not be used when sock is specified. ()Fr   zunexpected address familyNNAF_UNIXzstring is expected)r    z2Unable to check or remove stale UNIX socket %r: %rr   rb  z2-tuple is expectedr  r	  zcan not get address informationr  z@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))'rG   r+   r:   r,   dictrk  itemsr  r*   r>  r   r   r>   statS_ISSOCKosst_moderemoveFileNotFoundErrorr/   r   errorr   rU  r  r;   r2   r-   r.   SO_BROADCASTr  r  r   rB   r   r*  r|  r  r  ) r   r   r   r7  rF   rH   r  r4  r5  r1   optsproblemsr_addraddr_pairs_infora   err
addr_infosidxr  famr  pror)  key	addr_pairr   local_addressremote_addressrm   r  r   r   s                                    r   create_datagram_endpointz&BaseEventLoop.create_datagram_endpoint!  s     yyF... :4(CE Ekeu/z{#)e'1,;=  99$NDJJL$NN 008z<= = U#F+Q;$%@AA%+UO\#B"D+&..0H'5 >D'
40E'(<==> *Q-{"B	6==)<)D)DEIIj1 &,UO%/$=$? #B  
#$j/A{3C!D ;IC' *4 7CIN"+,A"BB&*&;&; f6G6G"'u4 '< 'A !A  %")*M"NN7< ;3CCG#&*C"*437,
33:JsOC0	;;& <F;K;K;M#E)7i'IaL,@(Yq\-A )$#E #E
 '$%FGGJ 6E$ 2&%0-!==%F,=,=ULD!&t,&"--v/B/BAG$$U+!		-0"."&"3"3D."III!/ ;$> !m##%##%11(FF,	;; 0&YJ  (()X?	LL
 (""} - " 6 &5%/6 66 !A#E8 J +'

%J%%c**'

* 	OOs   C!P $P 5P AM6 P /AP  N/A
P N2'$P B!N:-N8.N:4A3P (P
 -P.P
 2P 6	N,?P N,
N'!P 'N,,P 2P 8N::	P$O-'P -PP P
 
PP c                   K   |d d \  }}t        |||||g|dd   }	|	|	gS |j                  ||||||       d {   S 7 w)Nrb  r  )rM   r  )
r   r)  rF   rG   rH   r  r   rD   rE   r  s
             r   r  zBaseEventLoop._ensure_resolved  st      Ra[
dD$eJgabkJ6M))$V$05U * D D D Ds   ;AAAc                    K   | j                  ||f|t        j                  ||        d {   }|st        d|d      |S 7 w)N)rF   rG   r  r   zgetaddrinfo(z) returned empty list)r  r+   r:   r/   )r   rD   rE   rF   r  r  s         r   _create_server_getaddrinfoz(BaseEventLoop._create_server_getaddrinfo  s]     ++T4L171C1C27d , D D L0EFGGDs   *AAAr   )
rF   r  r1   r   ru   reuse_addressr4  r   r   r   c       
   	      D  K   t        |t              rt        d      ||t        d      ||t        d      |t	        |       || |t        d      |	(t
        j                  dk(  xr t        j                  dk7  }	g }|dk(  rdg}n:t        |t              s$t        |t        j                  j                        s|g}n|}|D cg c]  }| j                  ||||	       }}t        j                  |  d{   }t!        t"        j$                  j'                  |            }d
}	 |D ]  }|\  }}}}}	 t)        j(                  |||      }|j3                  |       |	r/|j5                  t(        j6                  t(        j8                  d       |
rt;        |       t<        rR|t(        j>                  k(  r?tA        t(        d      r/|j5                  t(        jB                  t(        jD                  d       	 |jG                  |        |stI        d|D cg c]  }|d   	 c}      d}|sS|D ]  }|jU                           n;|t        d      |jV                  t(        jX                  k7  rt        d|      |g}|D ]  }|j[                  d
        t]        | ||||||      }|r-|j_                          t        j`                  d       d{    | j,                  rt/        jb                  d|       |S c c}w 7 	# t(        j*                  $ r* | j,                  rt/        j0                  d|||d       Y w xY w# tH        $ r}d|d|jJ                  jM                         }|jN                  tN        jP                  k(  rG|jS                          |jU                          | j,                  rt/        j0                  |       Y d}~tI        |jN                  |      dd}~ww xY wc c}w # |s|D ]  }|jU                           w w xY w7 Aw)a1  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. 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 NoneNr  r  r  posixcygwinr5   )rF   r  Fz:create_server() failed to create socket.socket(%r, %r, %r)Texc_infoIPPROTO_IPV6r  r  z%could not bind on any address out of    z)Neither host/port nor sock were specifiedr  r   z%r is serving)2r   r  r>   r,   rw   rD  r  r}  platformr   rU   abcIterablerZ  r   rW  setrZ   r[   r\   r+   rH  r|  r   warningrB   r-   r.   SO_REUSEADDRr2   rA   r   r*   ra  IPV6_V6ONLYr  r/   r  r  r  EADDRNOTAVAILr  r   rG   r:   r  r   r   r   r  )r   r   rD   rE   rF   r  r1   r   ru   r[  r4  r   r   r   r   hostsfsr  	completedresrL   socktyperH   	canonnamesarN  r  r  r  s                                r   create_serverzBaseEventLoop.create_server  s    8 c4 HII ,CE E  +BD D d#t/ NP P $ "7 2 Os||x7OGrzT3' {'?'?@ $% 11$V8= 2 ? %B %  ,,++E	55e<=EI2%  '@C9<6B%B!%}}R5A NN4($"--v/B/BDJ!&t, "&//1#FN;(;(;(.(:(:(,.@		"7'@R !:?%@$d1g%@#C D D !	  ' %

% | !LMMyyF... #EdX!NOOfG 	$DU#	$ g'7W&;,. !!# ++a.  ;;KK0_% , "<< !;;"NN ,G+-xO !!0 # @ #%cll&8&8&: < 99(;(;;#KKM JJL#{{ &s 3$%cii54?@ &A ! ' %

% !( !s   CP L*P L
.P 1O> ?LB'O> >MO> O9
)O> 4B(P P.P 9M
O> 	M

O> 	O6A>O1O> O11O66O> >PP )ru   r   r   c          	      r  K   |j                   t        j                  k7  rt        d|      ||st        d      ||st        d      |t	        |       | j                  |||dd||       d {   \  }}| j                  r)|j                  d      }t        j                  d|||       ||fS 7 @w)	Nr  r  r  r5   T)r!  r   r   r+   z%r handled: (%r, %r))
rG   r+   r:   r,   rw   r  r|  r  r   r  )r   r   r1   ru   r   r   r   r  s           r   connect_accepted_socketz%BaseEventLoop.connect_accepted_socketF  s     
 99***A$JKK ,SCE E  +CBD D d#$($E$E"C"7!5 %F %7 7	8 ;; ++H5DLL/y(K(""7s   A2B74B55AB7c                   K    |       }| j                         }| j                  |||      }	 | d {    | j                  r&t	        j
                  d|j                         ||       ||fS 7 :#  |j                           xY ww)Nz Read pipe %r connected: (%r, %r))r   r.  r   r|  r   r  filenor   r   r-  r  r   r   s         r   connect_read_pipezBaseEventLoop.connect_read_piped  s     #%##%2246J		LL
 ;;LL;	8=("" 	OO+   +BA0 A.A0 6B.A0 0BBc                   K    |       }| j                         }| j                  |||      }	 | d {    | j                  r&t	        j
                  d|j                         ||       ||fS 7 :#  |j                           xY ww)Nz!Write pipe %r connected: (%r, %r))r   r0  r   r|  r   r  rv  rw  s         r   connect_write_pipez BaseEventLoop.connect_write_pipet  s     #%##%33D(FK		LL
 ;;LL<	8=("" 	OOry  c                 r   |g}||j                  dt        |              |1|t        j                  k(  r|j                  dt        |              n>||j                  dt        |              ||j                  dt        |              t	        j
                  dj                  |             y )Nzstdin=zstdout=stderr=zstdout=zstderr= )rB   r'   r#   r%   r   r  rk  )r   r  r4  r5  r6  r  s         r   _log_subprocesszBaseEventLoop._log_subprocess  s    uKK&e!4 567&J,=,="=KK.f)=(>?@!gl6&:%;<=!gl6&:%;<=SXXd^$r!   )	r4  r5  r6  universal_newlinesr3  r7  encodingerrorstextc       	   	        K   t        |t        t        f      st        d      |rt        d      |st        d      |dk7  rt        d      |rt        d      |	t        d      |
t        d       |       }d }| j                  rd	|z  }| j                  ||||        | j                  ||d
||||fi | d {   }| j                  r|t        j                  d||       ||fS 7 -w)Nzcmd must be a string universal_newlines must be Falsezshell must be Truer   bufsize must be 0text must be Falseencoding must be Noneerrors must be Nonezrun shell command %rT%s: %r)	r   r<   r   r,   r|  r~  r9  r   r  )r   r   cmdr4  r5  r6  r  r3  r7  r  r  r  r8  r  	debug_logr   s                   r   subprocess_shellzBaseEventLoop.subprocess_shell  s     #s|,344?@@122a<011122455233#%	;; /4I  E66B9$99c4KCIK K	;;90KK)Y7(""	Ks   B=C/?C- .C/c       	   	        K   |rt        d      |rt        d      |dk7  rt        d      |rt        d      |	t        d      |
t        d      |f|z   } |       }d }| j                  rd|}| j                  ||||        | j                  ||d	||||fi | d {   }| j                  r|t	        j
                  d
||       ||fS 7 -w)Nr  zshell must be Falser   r  r  r  r  zexecute program Fr  )r,   r|  r~  r9  r   r  )r   r   programr4  r5  r6  r  r3  r7  r  r  r  r2  r8  
popen_argsr  r  r   s                     r   subprocess_execzBaseEventLoop.subprocess_exec  s     ?@@233a<011122455233Z$&
#%	;; +7+6I  E66B9$99j% 	 ;;90KK)Y7(""s   B"C$C%.Cc                     | j                   S )zKReturn an exception handler, or None if the default one is in use.
        )r   r   s    r   get_exception_handlerz#BaseEventLoop.get_exception_handler  s     &&&r!   c                 H    |t        |      st        d|      || _        y)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   handlers     r   set_exception_handlerz#BaseEventLoop.set_exception_handler  s5     x'8 ##*+/ 0 0")r!   c                    |j                  d      }|sd}|j                  d      }|t        |      ||j                  f}nd}d|vr;| j                  /| j                  j                  r| j                  j                  |d<   |g}t        |      D ]  }|dv r||   }|dk(  r:d	j                  t        j                  |            }d
}||j                         z  }nJ|dk(  r:d	j                  t        j                  |            }d}||j                         z  }nt        |      }|j                  | d|         t        j                  dj                  |      |       y)aE  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.

        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()`.
        rS  z!Unhandled exception in event looprg   NFsource_tracebackhandle_traceback>   rS  rg   r5   z+Object created at (most recent call last):
z+Handle created at (most recent call last):
r  
r_  )getrG   __traceback__r   r  sortedrk  	tracebackformat_listrstripr   rB   r   rH  )	r   r	  rS  rg   r`  	log_linesrS  valuetbs	            r   default_exception_handlerz'BaseEventLoop.default_exception_handler  s`    ++i(9GKK,	 YI4K4KLHHg-$$0$$66$$66 &' I	'? 	0C..CLE((WWY2259:F$**WWY2259:F$UuBug./	0  	TYYy)H=r!   c                    | j                   	 | j                  |       y	 d}|j                  d      }||j                  d      }||j                  d      }|t        |d      r|j                         }|*t        |d	      r|j                  | j                   | |       y| j                  | |       y# t        t        f$ r  t        $ r t        j                  dd       Y yw xY w# t        t        f$ r  t        $ r[}	 | j                  d
||d       n:# t        t        f$ r  t        $ r t        j                  dd       Y nw xY wY d}~yY d}~yd}~ww xY w)aD  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;
        - 'task' (optional): Task instance;
        - 'handle' (optional): Handle instance;
        - 'protocol' (optional): Protocol instance;
        - 'transport' (optional): Transport instance;
        - 'socket' (optional): Socket instance;
        - 'asyncgen' (optional): Asynchronous generator that caused
                                 the exception.

        New keys maybe introduced in the future.

        Note: do not overload this method in an event loop subclass.
        For custom exception handling, use the
        `set_exception_handler()` method.
        Nz&Exception in default exception handlerTr_  r  ro  r   get_contextrunz$Unhandled error in exception handler)rS  rg   r	  zeException in default exception handler while handling an unexpected error in custom exception handler)r   r  rh   ri   r.  r   rH  r  r*   r  r  )r   r	  ctxthingrm   s        r   rZ  z$BaseEventLoop.call_exception_handler  sq   , ""*	,..w7$0F+= $KK1E=#KK1E$)F++-C?wsE':GGD33T7C++D':3  12   , E&*,	,0  12   0022#I%(#*4 
 #$56 $ 0 LL "? +/000	0sM   B7 BC, $C, 7/C)(C),EDE/E
EEEEc                 T    |j                   s| j                  j                  |       yy)zAdd a Handle to _ready.N)
_cancelledr   rB   r   r   s     r   _add_callbackzBaseEventLoop._add_callbackg  s"      KKv& !r!   c                 F    | j                  |       | j                          y)z6Like _add_callback() but called from a signal handler.N)r  r;  r  s     r   _add_callback_signalsafez&BaseEventLoop._add_callback_signalsafel  s    6"r!   c                 H    |j                   r| xj                  dz  c_        yy)z3Notification that a TimerHandle has been cancelled.r   N)r   r   r  s     r   _timer_handle_cancelledz%BaseEventLoop._timer_handle_cancelledq  s!    ''1,' r!   c                 b   t        | j                        }|t        kD  rr| j                  |z  t        kD  r\g }| j                  D ]'  }|j
                  rd|_        |j                  |       ) t        j                  |       || _        d| _        n| j                  rz| j                  d   j
                  ra| xj                  dz  c_        t        j                  | j                        }d|_        | j                  r| j                  d   j
                  rad}| j                  s| j                  rd}nP| j                  rD| j                  d   j                  }t        t        d|| j                         z
        t               }| j"                  j%                  |      }| j'                  |       d}| j                         | j(                  z   }| j                  rm| j                  d   }|j                  |k\  rnNt        j                  | j                        }d|_        | j                  j                  |       | j                  rmt        | j                        }t+        |      D ]  }	| j                  j-                         }|j
                  r*| j.                  rr	 || _        | j                         }
|j3                          | j                         |
z
  }|| j4                  k\  r t7        j8                  dt;        |      |       d| _        |j3                           d}y# d| _        w xY w)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   NzExecuting %s took %.3f seconds)rU  r   _MIN_SCHEDULED_TIMER_HANDLESr   %_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr  rB   r  heapifyheappopr   r   _whenr  maxr   MAXIMUM_SELECT_TIMEOUT	_selectorselectr>  r   rangepopleftr|  r   _runr   r   rg  r    )r   sched_countnew_scheduledr   rj  r  r=  end_timentodoir  r  s               r   r  zBaseEventLoop._run_oncev  s    $//*66''+556 M// 1$$(-F%!((0	1 MM-(+DO*+D' //dooa&8&C&C++q0+t7$)! //dooa&8&C&C
 ;;$..G__??1%++D#a		!346LMG^^**73
Z(
 99;!7!77oo__Q'F||x']]4??3F %FKKv& oo DKK u 	A[[((*F  {{	0+1D(BKKMr)BT888'G'5f'=rC ,0D(!	"  ,0D(s   A)L%%	L.c                     t        |      t        | j                        k(  ry |rDt        j                         | _        t        j
                  t        j                         || _        y t        j
                  | j                         || _        y rP   )r  r   r}  #get_coroutine_origin_tracking_depthr   #set_coroutine_origin_tracking_depthr   DEBUG_STACK_DEPTHr   enableds     r   r{  z,BaseEventLoop._set_coroutine_origin_tracking  sw    =D!H!HII779 733++- 3:/ 33;;= 3:/r!   c                     | j                   S rP   )r|  r   s    r   r  zBaseEventLoop.get_debug  s    {{r!   c                 l    || _         | j                         r| j                  | j                  |       y y rP   )r|  r  rD  r{  r  s     r   r   zBaseEventLoop.set_debug  s.    ??%%d&I&I7S r!   rP   )NNNr=  )r   )r   N)FNN)Ur   r   r   r   r   r   r  r  r  r  r'  r*  r.  r0  r9  r;  r>  r  rA  rH  rP  r_  rq  rh  rw  r  r  rk   r   r  rL  rM  r  r  r   r  r  r  r  r  r  rD  r  r  r  r  r  r  r  r  r  r  r  r  r&  r$  r%  r3  rW  r+   r:   r  rZ  r?   
AI_PASSIVErr  rt  rx  r{  r~  r#   r$   r  r  r  r  r  rZ  r  r  r  r  r{  r  r   rQ   r!   r   r   r     s   /<
) )-d *%""%)$" 9=" $t"&!%!%" CG"
 @D(,"
 AE)-" 04"""7DG
"20DK40$L*. %MM -  :> 0 6: $ 26 &%(" =A 	5 *
2 "#!1H7A(,A./4**.Z 59J#14T"&!%!%$J#\ */"&!%	#8-<#'-<^1"4 %*(,.2-1	.+b EID#./q267;$	D#N '(f.@.@%&a
D 59I ####"&!%IZ "&!%	#<# # % &0__&0oo&0oo27%)1(,T"#J %/OOJOO%/__$)1'+Dt	 #D'
*"0>dF0P'

-
N`:Tr!   r   )r   r   )r   )8__doc__rU   collections.abcconcurrent.futuresr  r  r  r  rZ   rD  r+   rB  r#   rf  r   r  r}  rL  r   ru   ImportErrorr5   r   r   r   r   r   r	   r
   r   r   r   r   r   logr   __all__r  r  r*   rA   r  r    r'   r2   rM   rd   rn   rr   rw   Protocolry   AbstractServerr   AbstractEventLoopr   rQ   r!   r   <module>r     s0          	       
                $
  #  ), % FJ'	 # J8v," 6=!G>
A)	 2 2 A)HBV"" BJCTF,, CTk  
Cs   D DD