
    F\hu9                    F   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKrSSKrSSKrSSKr SSKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  Sr#Sr$Sr%\&" \	S5      r'Sr(S r)S r*S r+S&S jr,S'S jr-S r.\&" \	S5      (       a  S r/OS r/S r0 " S  S!\Rb                  5      r2 " S" S#\Rf                  5      r4 " S$ S%\Rj                  5      r6g! \ a    Sr Nf = f)(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                     U R                   n[        [        USS 5      [        R                  5      (       a  [        UR                  5      $ [        U 5      $ )N__self__)	_callback
isinstancegetattrr   Taskreprr   str)handlecbs     */usr/lib/python3.13/asyncio/base_events.py_format_handler    G   s@    			B'"j$/<<BKK  6{    c                 l    U [         R                  :X  a  gU [         R                  :X  a  g[        U 5      $ )Nz<pipe>z<stdout>)
subprocessPIPESTDOUTr   )fds    r   _format_piper'   P   s+    	Z__	z  	 Bxr!   c                     [        [        S5      (       d  [        S5      e U R                  [        R                  [        R
                  S5        g ! [         a    [        S5      ef = f)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   Y   sc    6>**DEE	JOOF--v/B/BAF 	J I J J	Js   /A A(c           	         [        [        S5      (       d  g US[        R                  [        R                  1;  d  U c  g U[        R                  :X  a  [        R                  nO&U[        R
                  :X  a  [        R                  nOg Uc  SnOH[        U[        5      (       a	  US:X  a  SnO*[        U[        5      (       a	  US:X  a  SnO [        U5      nU[        R                  :X  a<  [        R                  /n[        (       a  UR                  [        R                   5        OU/n[        U [        5      (       a  U R#                  S5      n SU ;   a  g U HJ  n [        R$                  " X5        [        (       a  U[        R                   :X  a
  XUSXXV44s  $ XUSX44s  $    g ! [        [        4 a     g f = f! [&         a     Mr  f = f)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   d   s    6;''Q**F,>,>??Lv!!!""	""	"""|	D%	 	 TS[	D#		42:	t9D !!!~~9JJv'h${{6"
d{ 	R&yR6??2T,KKKTL88  ; :& 		2  		s*   F* <G G *F=<F= 
GGc                    [         R                  " 5       nU  H$  nUS   nXB;  a  / X$'   X$   R                  U5        M&     [        UR	                  5       5      n/ nUS:  a%  UR                  US   SUS-
   5        US   SUS-
  2	 UR                  S [        R                  R                  [        R                  " U6 5       5       5        U$ )z-Interleave list of addrinfo tuples by family.r   r   Nc              3   0   #    U  H  nUc  M  Uv   M     g 7fN ).0as     r   	<genexpr>(_interleave_addrinfos.<locals>.<genexpr>   s       
a 	
 
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_addrinfosre      s     &113a,*,'#**40	 
 .5578OI!A%+,K-G!-KLMA> :Q >>? ??00!!?3
  r!   c                     U R                  5       (       d,  U R                  5       n[        U[        [        45      (       a  g [
        R                  " U 5      R                  5         g rP   )	cancelled	exceptionr   
SystemExitKeyboardInterruptr   	_get_loopstop)futexcs     r   _run_until_complete_cbro      sG    ==??mmocJ(9:;; c!r!   TCP_NODELAYc                 <   U R                   [        R                  [        R                  1;   an  U R                  [        R
                  :X  aO  U R                  [        R                  :X  a0  U R                  [        R                  [        R                  S5        g g g g )Nr   )
rF   r+   r@   r   rG   r:   rH   r8   r-   rp   r0   s    r   _set_nodelayrr      sj    KKFNNFOO<<		V///

f000OOF..0B0BAF 1 0 =r!   c                     g rP   rQ   r0   s    r   rr   rr      s    r!   c                 h    [         b+  [        U [         R                  5      (       a  [        S5      eg g )Nz"Socket cannot be of type SSLSocket)sslr   	SSLSocketr>   r0   s    r   _check_ssl_socketrw      s*    
:dCMM::<== ;r!   c                   J    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rSrg)_SendfileFallbackProtocol   c                    [        U[        R                  5      (       d  [        S5      eXl        UR                  5       U l        UR                  5       U l        UR                  U l
        UR                  5         UR                  U 5        U R                  (       a*  U R                  R                  R                  5       U l        g S U l        g )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__"_SendfileFallbackProtocol.__init__   s    &*">">??LMM ))+&,&7&7&9#&,&=&=#D!&&$(OO$9$9$G$G$ID!$(D!r!   c                    #    U R                   R                  5       (       a  [        S5      eU R                  nUc  g UI S h  vN   g  N7f)NzConnection closed by peer)r}   
is_closingConnectionErrorr   )r   rm   s     r   drain_SendfileFallbackProtocol.drain   s>     ??%%''!"=>>##;		s   A A
AA
c                     [        S5      e)Nz?Invalid state: connection should have been established already.RuntimeErrorr   	transports     r   connection_made)_SendfileFallbackProtocol.connection_made   s     N O 	Or!   c                     U R                   bC  Uc%  U R                   R                  [        S5      5        OU R                   R                  U5        U R                  R	                  U5        g )NzConnection is closed by peer)r   set_exceptionr   r   connection_lost)r   rn   s     r   r   )_SendfileFallbackProtocol.connection_lost   s[      , {%%33#$BCE %%33C8##C(r!   c                 r    U R                   b  g U R                  R                  R                  5       U l         g rP   )r   r}   r   r   r   s    r   pause_writing'_SendfileFallbackProtocol.pause_writing   s,      , $ 5 5 C C Er!   c                 d    U R                   c  g U R                   R                  S5        S U l         g NF)r   
set_resultr   s    r   resume_writing(_SendfileFallbackProtocol.resume_writing   s-      (((/ $r!   c                     [        S5      eNz'Invalid state: reading should be pausedr   )r   datas     r   data_received'_SendfileFallbackProtocol.data_received       DEEr!   c                     [        S5      er   r   r   s    r   eof_received&_SendfileFallbackProtocol.eof_received  r   r!   c                 R  #    U R                   R                  U R                  5        U R                  (       a  U R                   R	                  5         U R
                  b  U R
                  R                  5         U R                  (       a  U R                  R                  5         g g 7frP   )	r}   r   r   r   resume_readingr   cancelr   r   r   s    r   restore!_SendfileFallbackProtocol.restore  sr     $$T[[1&&OO**,  , !!((*&&KK&&( 's   B%B')r   r   r   r}   r   N)__name__
__module____qualname____firstlineno__r   r   r   r   r   r   r   r   r   __static_attributes__rQ   r!   r   ry   ry      s3    )O	)F
%FF
)r!   ry   c                   ~    \ rS rSr SS jrS rS rS rS rS r	S	 r
S
 r\S 5       rS rS rS rS rS rS rSrg)r   i  Nc                     Xl         X l        [        R                  " 5       U l        / U l        X0l        XPl        X@l        X`l	        Xpl
        SU l        S U l        g r   )r   _socketsweakrefWeakSet_clients_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   Server.__init__  sO    
  )!1'&;#%9"$(!r!   c                 R    SU R                   R                   SU R                  < S3$ )N<z	 sockets=>)	__class__r   r   r   s    r   __repr__Server.__repr__%  s'    4>>**+9T\\4DAFFr!   c                 X    U R                   c   eU R                  R                  U5        g rP   )r   r   addr   s     r   _attachServer._attach(  s$    }}((()$r!   c                     U R                   R                  U5        [        U R                   5      S:X  a  U R                  c  U R	                  5         g g g Nr   )r   discardlenr   _wakeupr   s     r   _detachServer._detach,  s?    i(t}}"t}}'<LLN (="r!   c                     U R                   nS U l         U H+  nUR                  5       (       a  M  UR                  S 5        M-     g rP   )r   doner   )r   waiterswaiters      r   r   Server._wakeup1  s5    --F;;==!!$' r!   c           
      4   U R                   (       a  g SU l         U R                   Ho  nUR                  U R                  5        U R                  R                  U R                  XR                  X R                  U R                  U R                  5        Mq     g )NT)
r   r   listenr   r   _start_servingr   r   r   r   )r   r1   s     r   r   Server._start_serving8  sl    ==MMDKK&JJ%%&&.?.?mmT%@%@**, "r!   c                     U R                   $ rP   )r   r   s    r   get_loopServer.get_loopC  s    zzr!   c                     U R                   $ rP   )r   r   s    r   
is_servingServer.is_servingF  s    }}r!   c                 V    U R                   c  g[        S U R                    5       5      $ )NrQ   c              3   N   #    U  H  n[         R                  " U5      v   M     g 7frP   )r   TransportSocket)rR   ss     r   rT   !Server.sockets.<locals>.<genexpr>M  s     F1V++A..s   #%)r   tupler   s    r   r   Server.socketsI  s$    == FFFFr!   c                 v   U R                   nUc  g S U l         U H  nU R                  R                  U5        M      SU l        U R                  b@  U R                  R                  5       (       d!  U R                  R                  5         S U l        [        U R                  5      S:X  a  U R                  5         g g )NFr   )
r   r   _stop_servingr   r   r   r   r   r   r   )r   r   r1   s      r   closeServer.closeO  s    --?DJJ$$T*  %%1--2244%%,,.(,D%t}}"LLN #r!   c                 f    U R                   R                  5        H  nUR                  5         M     g rP   )r   copyr   r   s     r   close_clientsServer.close_clientsb  #    ++-IOO .r!   c                 f    U R                   R                  5        H  nUR                  5         M     g rP   )r   r   abortr   s     r   abort_clientsServer.abort_clientsf  r   r!   c                 l   #    U R                  5         [        R                  " S5      I S h  vN   g  N7fr   )r   r   sleepr   s    r   start_servingServer.start_servingj  s$      kk!ns   *424c                   #    U R                   b  [        SU < S35      eU R                  c  [        SU < S35      eU R                  5         U R                  R                  5       U l          U R                   I S h  vN    S U l         g  N! [        R                   a1     U R                  5         U R                  5       I S h  vN    e ! e = ff = f! S U l         f = f7f)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_foreverServer.serve_foreverp  s     $$0$!MNP P== 
;<<$(JJ$<$<$>!		-++++ )-D% ,(( 	

&&(((	 )-D%s`   A*C -B <B
=B C 
B C!#CCC
CCCC 	CC c                    #    U R                   c  gU R                  R                  5       nU R                   R                  U5        UI Sh  vN   g N7f)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	  Server.wait_closed  s?     * == ))+V$s   A	AAA)r   r   r   r   r   r   r   r   r   r   r   rP   )r   r   r   r   r   r   r   r   r   r   r   r   propertyr   r   r   r  r  r
  r	  r   rQ   r!   r   r   r     se     >B) G%
(	, G G
&-*r!   r   c                   
   \ rS rSrS rS rS rSSS.S jrS rS	 r	S`SSS
.S jjr
 S`SSSSSSSS.S jjr SaS jr  SbS jr  SbS jr S`S jrS rS rS rS rS rS rS rS`S jrS rS rS rS rS  rS! rS" rS# rS$ r \!RD                  4S% jr#S& r$S' r%SS(.S) jr&SS(.S* jr'SS(.S+ jr(S, r)S- r*S. r+SS(.S/ jr,S0 r-S1 r.S2 r/S3S3S3S3S4.S5 jr0ScS6 jr1SdSS7.S8 jjr2S9 r3S: r4S; r5S`S< jr6 SbSS3S3S3SSSSSSSSS=.S> jjr7   SeS? jr8SdSS7.S@ jjr9SA r:SB r;SSSSSC.SD jr< SbS3S3S3SSSSE.SF jjr=S3\>R~                  S3S3S4.SG jr@SH rA Sb\>R                  \>R                  SSISSSSSSSSJ.SK jjrDSSSSL.SM jrESN rFSO rGSP rH\IR                  \IR                  \IR                  SSS3SSSSQ.	SR jrK\IR                  \IR                  \IR                  SSS3SSSSQ.	SS jrLST rMSU rNSV rOSW rPSX rQSY rRSZ rSS[ rTS\ rUS] rVS^ rWS_rXg)fr   i  c                    SU l         SU l        SU l        [        R                  " 5       U l        / U l        S U l        SU l        S U l	        [        R                  " S5      R                  U l        S U l        U R                  [         R"                  " 5       5        S U l        SU l        S U l        S U l        SU l        S U l        [0        R2                  " 5       U l        SU l        SU l        g )Nr   F	monotonicg?)_timer_cancelled_count_closed	_stoppingrV   deque_ready
_scheduled_default_executor_internal_fds
_thread_idtimeget_clock_info
resolution_clock_resolution_exception_handler	set_debugr   _is_debug_mode_old_agen_hooksslow_callback_duration_current_handle_task_factory"_coroutine_origin_tracking_enabled&_coroutine_origin_tracking_saved_depthr   r   
_asyncgens_asyncgens_shutdown_called_executor_shutdown_calledr   s    r   r   BaseEventLoop.__init__  s    &'#!'')!% !%!4!4[!A!L!L"&z0023# '*##!27/6:3 "//+*/').&r!   c           	          SU R                   R                   SU R                  5        SU R                  5        SU R	                  5        S3	$ )Nr   z	 running=z closed=z debug=r   )r   r   
is_running	is_closed	get_debugr   s    r   r   BaseEventLoop.__repr__  sP    ''(	$//2C1D Enn&'wt~~/?.@C	
r!   c                 *    [         R                  " U S9$ )z,Create a Future object attached to the loop.r   )r   Futurer   s    r   r   BaseEventLoop.create_future  s    ~~4((r!   N)namecontextc                   U R                  5         U R                  b,  Ub  X4S'   U R                  " X40 UD6nUR                  U5        O8[        R                  " U4XUS.UD6nUR
                  (       a  UR
                  S	  UA$ ! Af = f)z4Schedule a coroutine object.

Return a task object.
r6  )r   r5  r6  )_check_closedr%  set_namer   r   _source_traceback)r   coror5  r6  kwargstasks         r   create_taskBaseEventLoop.create_task  s    
 	)"$+y!%%d;F;DMM$ ::dT'TVTD%%**2.	 s   B B	c                 L    Ub  [        U5      (       d  [        S5      eXl        g)a  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, **kwargs)', where 'loop' will be a reference to the active
event loop, 'coro' will be a coroutine object, and **kwargs will be
arbitrary keyword arguments that should be passed on to Task.
The callable must return a Task.
Nz'task factory must be a callable or None)callabler>   r%  )r   factorys     r   set_task_factoryBaseEventLoop.set_task_factory  s&     x'8'8EFF$r!   c                     U R                   $ )z<Return a task factory, or None if the default one is in use.)r%  r   s    r   get_task_factoryBaseEventLoop.get_task_factory  s    !!!r!   )extraserverc                    [         e)zCreate socket transport.NotImplementedError)r   r1   protocolr   rI  rJ  s         r   _make_socket_transport$BaseEventLoop._make_socket_transport  
     "!r!   FT)server_sideserver_hostnamerI  rJ  r   r   call_connection_madec                    [         e)zCreate SSL transport.rL  )r   rawsockrN  
sslcontextr   rR  rS  rI  rJ  r   r   rT  s               r   _make_ssl_transport!BaseEventLoop._make_ssl_transport  s
     "!r!   c                     [         e)zCreate datagram transport.rL  )r   r1   rN  addressr   rI  s         r   _make_datagram_transport&BaseEventLoop._make_datagram_transport  rQ  r!   c                     [         e)zCreate read pipe transport.rL  r   piperN  r   rI  s        r   _make_read_pipe_transport'BaseEventLoop._make_read_pipe_transport  rQ  r!   c                     [         e)zCreate write pipe transport.rL  r_  s        r   _make_write_pipe_transport(BaseEventLoop._make_write_pipe_transport  rQ  r!   c	                    #    [         e7f)zCreate subprocess transport.rL  )
r   rN  argsshellstdinstdoutstderrbufsizerI  r=  s
             r   _make_subprocess_transport(BaseEventLoop._make_subprocess_transport  s      "!s   	c                     [         e)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.
rL  r   s    r   _write_to_selfBaseEventLoop._write_to_self  s
     "!r!   c                     [         e)zProcess selector events.rL  )r   
event_lists     r   _process_eventsBaseEventLoop._process_events&  s    !!r!   c                 <    U R                   (       a  [        S5      eg )NzEvent loop is closed)r  r   r   s    r   r9  BaseEventLoop._check_closed*  s    <<566 r!   c                 <    U R                   (       a  [        S5      eg )Nz!Executor shutdown has been called)r*  r   r   s    r   _check_default_executor%BaseEventLoop._check_default_executor.  s    ))BCC *r!   c                     U R                   R                  U5        U R                  5       (       d+  U R                  U R                  UR                  5       5        g g rP   )r(  r   r.  call_soon_threadsafer?  acloser   agens     r   _asyncgen_finalizer_hook&BaseEventLoop._asyncgen_finalizer_hook2  sB    %~~%%d&6&6F  r!   c                     U R                   (       a  [        R                  " SU< S3[        U S9  U R                  R                  U5        g )Nzasynchronous generator z3 was scheduled after loop.shutdown_asyncgens() callsource)r)  warningswarnResourceWarningr(  r   r~  s     r   _asyncgen_firstiter_hook&BaseEventLoop._asyncgen_firstiter_hook7  sA    **MM)$ 21 2.
 	D!r!   c                   #    SU l         [        U R                  5      (       d  g[        U R                  5      nU R                  R	                  5         [
        R                  " U Vs/ s H  o"R                  5       PM     snSS06I Sh  vN n[        X15       H5  u  pE[        U[        5      (       d  M  U R                  SU< 3UUS.5        M7     gs  snf  NN7f)z,Shutdown all active asynchronous generators.TNreturn_exceptionsz;an error occurred during closing of asynchronous generator )messagerh   asyncgen)r)  r   r(  rX   clearr   gatherr}  zipr   	Exceptioncall_exception_handler)r   closing_agensagresultsresultr  s         r   shutdown_asyncgens BaseEventLoop.shutdown_asyncgens@  s     *.'4??## T__-$12MbiikM2$"$ $  7LF&),,++"99= B!' $	-  8 3$s$   A&C(C
CC'C7$Cc                   #    SU l         U R                  c  gU R                  5       n[        R                  " U R
                  U4S9nUR                  5          [        R                  " U5       ISh  vN   UI Sh  vN   SSS5      ISh  vN   UR                  5         g N/ N' N! , ISh  vN  (       d  f       N.= f! [         a:    [        R                  " SU S3[        SS9  U R                  R                  SS	9   gf = f7f)
zSchedule 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)targetrg  z:The executor did not finishing joining its threads within z	 seconds.   )
stacklevelFwait)r*  r  r   	threadingThread_do_shutdownstartr   timeoutjoinTimeoutErrorr  r  RuntimeWarningshutdown)r   r  futurethreads       r   shutdown_default_executor'BaseEventLoop.shutdown_default_executorY  s      *.&!!)##%!!):):&K		''00 10 KKM 1 1000 	8MM 007y	C(Q8 ""+++7		8s   AD
C 3B#4C 7B)=B%>B)C B'C D
#C %B)'C )C /B20C <C ADD
DD
c                 t    U R                   R                  SS9  U R                  5       (       d"  U R                  [        R
                  US 5        g g ! [         aZ  nU R                  5       (       d;  UR                  5       (       d!  U R                  UR                  U5         S nAg  S nAg  S nAg S nAff = f)NTr  )	r  r  r.  r|  r   _set_result_unless_cancelledr  rg   r   )r   r  exs      r   r  BaseEventLoop._do_shutdownq  s    	D""+++6>>##))'*N*N*0$8 $  	D>>##F,<,<,>,>))&*>*>CC -?#	Ds   AA 
B7AB22B7c                     U R                  5       (       a  [        S5      e[        R                  " 5       b  [        S5      eg )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_runningBaseEventLoop._check_running{  sA    ??CDD##%1IK K 2r!   c                 `   U R                  5         U R                  5         U R                  U R                  5        [        R
                  " 5       U l        [        R                  " 5       U l	        [        R                  " U R                  U R                  S9  [        R                  " U 5        g)zPrepare the run loop to process events.

This method exists so that custom custom event loop subclasses (e.g., event loops
that integrate a GUI event loop with Python's event loop) have access to all the
loop setup logic.
)	firstiter	finalizerN)r9  r  _set_coroutine_origin_tracking_debugsysget_asyncgen_hooksr"  r  	get_identr  set_asyncgen_hooksr  r  r   _set_running_loopr   s    r   _run_forever_setup BaseEventLoop._run_forever_setup  s     	++DKK8"557#--/3333	

 	  &r!   c                     SU l         SU l        [        R                  " S5        U R	                  S5        U R
                  b%  [        R                  " U R
                  6   SU l        gg)zClean up after an event loop finishes the looping over events.

This method exists so that custom custom event loop subclasses (e.g., event loops
that integrate a GUI event loop with Python's event loop) have access to all the
loop cleanup logic.
FN)r  r  r   r  r  r"  r  r  r   s    r   _run_forever_cleanup"BaseEventLoop._run_forever_cleanup  s[       &++E2+""D$8$89#'D  ,r!   c                     U R                  5           U R                  5         U R                  (       a  OM$  U R                  5         g! U R                  5         f = f)zRun until stop() is called.N)r  	_run_oncer  r  r   s    r   run_foreverBaseEventLoop.run_forever  sJ    !	( >> 
 %%'D%%'s   %A Ac                 V   U R                  5         U R                  5         [        R                  " U5      (       + n[        R
                  " XS9nU(       a  SUl        UR                  [        5         U R                  5          UR                  [        5        UR                  5       (       d  [        S5      eUR                  5       $ !   U(       a:  UR                  5       (       a%  UR                  5       (       d  UR                  5         e = f! UR                  [        5        f = f)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.
r2  Fz+Event loop stopped before Future completed.)r9  r  r   isfuturer   ensure_future_log_destroy_pendingadd_done_callbackro   r  r   rg   rh   remove_done_callbackr   r  )r   r  new_tasks      r   run_until_complete BaseEventLoop.run_until_complete  s     	''//$$V7 +0F'  !78
	@ ''(>?{{}}LMM}}	FKKMM&2B2B2D2D   "''(>?s   4C
 
ADD D(c                     SU l         g)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   rl   BaseEventLoop.stop  s     r!   c                    U R                  5       (       a  [        S5      eU R                  (       a  gU R                  (       a  [        R
                  " SU 5        SU l        U R                  R                  5         U R                  R                  5         SU l	        U R                  nUb  SU l
        UR                  SS9  gg)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 %rTFr  )r-  r   r  r  r   debugr  r  r  r*  r  r  r   executors     r   r   BaseEventLoop.close  s     ??BCC<<;;LLT*)-&))%)D"5)  r!   c                     U R                   $ )z*Returns True if the event loop was closed.)r  r   s    r   r.  BaseEventLoop.is_closed  s    ||r!   c                     U R                  5       (       d7  U" SU < 3[        U S9  U R                  5       (       d  U R                  5         g g g )Nzunclosed event loop r  )r.  r  r-  r   )r   _warns     r   __del__BaseEventLoop.__del__  sC    ~~(1?4P??$$

 %  r!   c                     U R                   SL$ )z*Returns True if the event loop is running.N)r  r   s    r   r-  BaseEventLoop.is_running   s    t+,r!   c                 ,    [         R                  " 5       $ )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  BaseEventLoop.time  s     ~~r!   )r6  c                    Uc  [        S5      eU R                  " U R                  5       U-   U/UQ7SU06nUR                  (       a  UR                  S	 U$ )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 Noner6  r8  )r>   call_atr  r;  )r   delaycallbackr6  rg  timers         r   
call_laterBaseEventLoop.call_later  s]      =455TYY[50( .T .%,.""''+r!   c                d   Uc  [        S5      eU R                  5         U R                  (       a"  U R                  5         U R	                  US5        [
        R                  " XX@U5      nUR                  (       a  UR                  S	 [        R                  " U R                  U5        SUl
        U$ )zlLike call_later(), but uses an absolute time.

Absolute time corresponds to the event loop's time() method.
zwhen cannot be Noner  r8  T)r>   r9  r  _check_thread_check_callbackr   TimerHandler;  heapqheappushr  )r   whenr  r6  rg  r  s         r   r  BaseEventLoop.call_at%  s    
 <122;;   95""44wG""''+t.r!   c                    U R                  5         U R                  (       a"  U R                  5         U R                  US5        U R	                  XU5      nUR
                  (       a  UR
                  S	 U$ )a$  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_soonr8  )r9  r  r  r  
_call_soonr;  r   r  r6  rg  r   s        r   r  BaseEventLoop.call_soon7  s_     	;;   ;79##((,r!   c                     [         R                  " U5      (       d  [         R                  " U5      (       a  [        SU S35      e[	        U5      (       d  [        SU SU< 35      eg )Nzcoroutines cannot be used with z()z"a callable object was expected by z(), got )r   iscoroutineiscoroutinefunctionr>   rB  )r   r  methods      r   r  BaseEventLoop._check_callbackJ  sp    ""8,,..x881&<> >!!4VH =l$% % "r!   c                     [         R                  " XX5      nUR                  (       a  UR                  S	 U R                  R	                  U5        U$ )Nr8  )r   Handler;  r  rB   )r   r  rg  r6  r   s        r   r  BaseEventLoop._call_soonT  s@    xt=##((,6"r!   c                 ~    U R                   c  g[        R                  " 5       nXR                   :w  a  [        S5      eg)aG  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  r  r  r   )r   	thread_ids     r   r  BaseEventLoop._check_thread[  s@     ??"'')	''( ( (r!   c                    U R                  5         U R                  (       a  U R                  US5        U R                  XU5      nUR                  (       a  UR                  S	 U R                  5         U$ )z"Like call_soon(), but thread-safe.r|  r8  )r9  r  r  r  r;  rp  r  s        r   r|  "BaseEventLoop.call_soon_threadsafel  s^    ;;  +AB9##((,r!   c                 >   U R                  5         U R                  (       a  U R                  US5        UcB  U R                  nU R	                  5         Uc#  [
        R                  R                  SS9nXl        [        R                  " UR                  " U/UQ76 U S9$ )Nrun_in_executorasyncio)thread_name_prefixr2  )
r9  r  r  r  ry  
concurrentr   ThreadPoolExecutorwrap_futuresubmit)r   r  funcrg  s       r   r  BaseEventLoop.run_in_executorw  s    ;;  '89--H((*%--@@'0 A  *2&""OOD(4(t5 	5r!   c                 x    [        U[        R                  R                  5      (       d  [	        S5      eXl        g )Nz,executor must be ThreadPoolExecutor instance)r   r  r   r  r>   r  r  s     r   set_default_executor"BaseEventLoop.set_default_executor  s-    (J$6$6$I$IJJJKK!)r!   c                 X   U SU< 3/nU(       a  UR                  SU< 35        U(       a  UR                  SU< 35        U(       a  UR                  SU< 35        U(       a  UR                  SU< 35        SR                  U5      n[        R                  " SU5        U R	                  5       n[
        R                  " XX4XV5      n	U R	                  5       U-
  n
SU S	U
S
-  S SU	< 3nXR                  :  a  [        R                  " U5        U	$ [        R                  " U5        U	$ )N:zfamily=ztype=zproto=zflags=, zGet address info %szGetting address info z took g     @@z.3fzms: )	rB   r  r   r  r  r+   getaddrinfor#  info)r   rD   rE   rF   rG   rH   flagsmsgt0addrinfodts              r   _getaddrinfo_debug BaseEventLoop._getaddrinfo_debug  s   q!"JJ
+,JJth'(JJy)*JJy)*iin*C0YY[%%d&MYY[2%cU&c#d8,O,,,KK  LLr!   r   rF   rG   rH   r  c          
         #    U R                   (       a  U R                  nO[        R                  nU R	                  S XqX#XEU5      I S h  vN $  N7frP   )r  r  r+   r  r  )r   rD   rE   rF   rG   rH   r  getaddr_funcs           r   r  BaseEventLoop.getaddrinfo  sN     ;;22L!--L)),dDH H 	H Hs   AA	A
Ac                 `   #    U R                  S [        R                  X5      I S h  vN $  N7frP   )r  r+   getnameinfo)r   sockaddrr  s      r   r   BaseEventLoop.getnameinfo  s/     ))&$$h7 7 	7 7s   %.,.)fallbackc                f  #    U R                   (       a  UR                  5       S:w  a  [        S5      e[        U5        U R	                  XX45         U R                  XX45      I S h  vN $  N! [        R                   a  nU(       d  e  S nAOS nAff = fU R                  XX45      I S h  vN  $ 7f)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#  rn   s          r   sock_sendfileBaseEventLoop.sock_sendfile  s     ;;4??,1>??$##D>	33D4:C C C C33 	 	 11$28A A A 	AsN   AB1A- &A+'A- *B1+A- -BB	B1BB1+B.,B1c                 H   #    [         R                  " SU< SU< S35      e7f)Nz-syscall sendfile is not available for socket z
 and file z combinationr   r(  r   r1   r*  r+  r,  s        r   r'  #BaseEventLoop._sock_sendfile_native  s3      22;D8 Dx|-. 	.s    "c                 r  #    U(       a  UR                  U5        U(       a  [        U[        R                  5      O[        R                  n[	        U5      nSn  U(       a  [        XG-
  U5      nUS::  a  O][        U5      S U nU R                  S UR                  U5      I S h  vN n	U	(       d  O"U R                  XS U	 5      I S h  vN   Xy-  nMy  UUS:  a&  [        US5      (       a  UR                  X7-   5        $ $ $  N\ N:! US:  a&  [        US5      (       a  UR                  X7-   5        f f f = f7f)Nr   seek)
r4  minr   !SENDFILE_FALLBACK_READBUFFER_SIZE	bytearray
memoryviewr  readintosock_sendallr*   )
r   r1   r*  r+  r,  	blocksizebuf
total_sentviewreads
             r   r)  %BaseEventLoop._sock_sendfile_fallback  s+    IIf  yBBC#EE 	 	"
	/ #E$6	 BI A~!#z	2!11$tLL''5Dk:::"
  A~'$"7"7		&-. #8~ M ; A~'$"7"7		&-. #8~sC   AD7AD %D&#D 	D
D -D7D D .D44D7c                    S[        USS5      ;  a  [        S5      eUR                  [        R                  :X  d  [        S5      eUbO  [        U[        5      (       d  [        SR                  U5      5      eUS::  a  [        SR                  U5      5      e[        U[        5      (       d  [        SR                  U5      5      eUS:  a  [        SR                  U5      5      eg )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>   formatr1  s        r   r&  $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                   #    / nUR                   " U5        Uu  pVpxn	Sn
 [        R                  " XVUS9n
U
R                  S5        UbN  U H!  u  n    pX:w  a  M   U
R                  U5          O)   U(       a  UR                  5       e[	        SU< S35      eU R                  X5      I Sh  vN   U
S=p$ ! [         aR  nSU< S[        U5      R                  5        3n[	        UR                  U5      nUR                  U5         SnAM  SnAff = f Nh! [         a*  nUR                  U5        U
b  U
R                  5         e SnAf  U
b  U
R                  5         e = f! S=pf = f7f)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/   r   lowererrnopopsock_connectr   )r   r   	addr_infolocal_addr_infosmy_exceptionsrF   type_rH   _r[  r1   lfamilyladdrrn   r  s                  r   _connect_sockBaseEventLoop._connect_sock  s}    -(+4(u#	.==%HDU#+/?+GQ1( 	2		%( 0@ %+//11%(OyPV&WXX##D222 *.-J1 # 2'',ir#c(..2B1CE  &cii5%,,S112 3 	  %

	

)--Jsk   E):D B5,?D +D,D 1E)5
D?ADD DD 
E %EEE! !E&&E))ru   rF   rH   r  r1   
local_addrrS  r   r   happy_eyeballs_delay
interleave
all_errorsc          	        ^ ^^^#    U
b  U(       d  [        S5      eU
c  U(       a  U(       d  [        S5      eUn
Ub  U(       d  [        S5      eUb  U(       d  [        S5      eUb  [        U5        Ub  Uc  SnUc  UGb  Ub  [        S5      eT R                  X#4U[        R                  XgT S9I Sh  vN nU(       d  [        S	5      eU	b<  T R                  X[        R                  UUT S9I Sh  vN mT(       d  [        S	5      eOSmU(       a  [        UU5      n/ mUc&  U H  n T R                  TUT5      I Sh  vN n  O0   O-[        R                  " UUU 4S
 jU 5       UT S9I Sh  vN S   nUc  T VVs/ s H  nU  H  nUPM     M     snnm U(       a  [        ST5      e[        T5      S:X  a  TS   e[        TS   5      m[        U4S jT 5       5      (       a  TS   e[        SR                  SR                  S T 5       5      5      5      eO;Uc  [        S5      eUR                   [        R                  :w  a  [        SU< 35      eT R#                  XXJUUS9I Sh  vN u  nnT R$                  (       a+  UR'                  S5      n[(        R*                  " SXUUU5        UU4$  GN GN GN}! [
         a     GM  f = f GNcs  snnf ! Smf = f Nr7f)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   :   >#    U  H  nU4UUU4S  jjv   M     g7f)c                 *   > TR                  TU T5      $ rP   )rW  )r  r   laddr_infosr   s    r   <lambda>;BaseEventLoop.create_connection.<locals>.<genexpr>.<lambda>  s    $2D2D&+3r!   NrQ   )rR   r  r   re  r   s     r   rT   2BaseEventLoop.create_connection.<locals>.<genexpr>|  s&       ).H )1   ).s   r2  r   zcreate_connection failedc              3   @   >#    U  H  n[        U5      T:H  v   M     g 7frP   r   )rR   rn   models     r   rT   rh    s     GJSs3x50Js   zMultiple exceptions: {}r  c              3   8   #    U  H  n[        U5      v   M     g 7frP   rj  )rR   rn   s     r   rT   rh    s     %E*3c#hh*s   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/   re   rW  r   staggered_raceExceptionGroupr   r   allrD  r  rG   _create_connection_transportr  get_extra_infor   r  )r   r   rD   rE   ru   rF   rH   r  r1   rY  rS  r   r   rZ  r[  r\  infosr  subrn   r   rN  r   re  rk  s   `                     @@@r   create_connectionBaseEventLoop.create_connection"  sp    ( &sJKK"s   "A B B"O ,SCE E  +CBD D d#+
0BJt/ NP P //V''u 0 N NE ABB%$($9$9++5d %: %, , #!"EFF # #-eZ@J#+ %H!%)%7%7&+&?  ?	 !& (66 ). )   |-7GZc3Cc3cZG
&!,-GTT:!+(m+ !$JqM 2GJG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:T9h@(""mN," ? # ! ! H  "&J 7s   B.K$4J75=K$2J:36K$*K  J=K *K$/K0K$?KK$BK AK$/K"0AK$:K$=K  
K
K$KK$K$KK$c                 2  #    UR                  S5        U" 5       nU R                  5       n	U(       a-  [        U[        5      (       a  S OUn
U R	                  XXXTUUS9nOU R                  XU	5      n U	I S h  vN   X4$  N!   UR                  5         e = f7f)NFrR  rS  r   r   )rJ  r   r   boolrX  rO  r   )r   r1   r   ru   rS  rR  r   r   rN  r   rW  r   s               r   rr  *BaseEventLoop._create_connection_transport  s      	#%##%!+C!6!6CJ00
'&;%9	 1 ;I 33DFKI	LL
 "" 	OOs0   A/B2B 7A?8B <B?B BBc                  #    UR                  5       (       a  [        S5      e[        US[        R                  R
                  5      nU[        R                  R
                  L a  [        SU< 35      eU[        R                  R                  L a   U R                  XX45      I Sh  vN $ U(       d  [        SU< 35      eU R                  XX45      I Sh  vN $  N4! [        R                   a  nU(       d  e  SnANSSnAff = f N/7f)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#  rC  rn   s           r   sendfileBaseEventLoop.sendfile  s    0 !!566y"8 ..::<9**666:9-HJ J9**555!22939B B B ++4-9: : ,,Y-3< < 	<B77   <sN   BD	C 'C(C +,D	DD	C D2C?:D	?DD	c                 6   #    [         R                  " S5      e7f)Nz!sendfile syscall is not supportedr0  )r   r   r*  r+  r,  s        r   r  BaseEventLoop._sendfile_native   s     22/1 	1s   c                 X  #    U(       a  UR                  U5        U(       a  [        US5      OSn[        U5      nSn[        U5      n  U(       aX  [        XG-
  U5      nUS::  aD  UUS:  a$  [	        US5      (       a  UR                  X7-   5        UR                  5       I S h  vN   $ [        U5      S U n	U R                  S UR                  U	5      I S h  vN n
U
(       dD  UUS:  a$  [	        US5      (       a  UR                  X7-   5        UR                  5       I S h  vN   $ UR                  U	S U
 5        UR                  5       I S h  vN   Xz-  nGM   N N N< N! US:  a$  [	        US5      (       a  UR                  X7-   5        UR                  5       I S h  vN    f = f7f)Ni @  r   r4  )r4  r5  r7  ry   r*   r   r8  r  r9  writer   )r   r   r*  r+  r,  r;  r<  r=  rH   r>  r?  s              r   r   BaseEventLoop._sendfile_fallback  ss    IIf).Cu%E		"
)&1	" #E$6	 BI A~) A~'$"7"7		&-.--/!! "#z	2!11$tLL%
 A~'$"7"7		&-.--/!! T%4[)kkm##"
  " M " $ A~'$"7"7		&-.--/!!s   AF*	E" &=F*#E$F*).E" EE" $=F*!E"F*''E" E E" F*E" F* E" ">F' F#!F''F*ry  c                  #    [         c  [        S5      e[        U[         R                  5      (       d  [	        SU< 35      e[        USS5      (       d  [	        SU< S35      eU R                  5       n[        R                  " XX8XEUUSS9	n	UR                  5         UR                  U	5        U R                  U	R                  U5      n
U R                  UR                  5      n UI Sh  vN   U	R"                  $  N! [         a2    UR                  5         U
R!                  5         UR!                  5         e f = f7f)	zbUpgrade 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   rT  )ru   r   r   
SSLContextr>   r   r   r
   SSLProtocolr   r   r  r   r   BaseExceptionr   r   _app_transport)r   r   rN  rW  rR  rS  r   r   r   ssl_protocol
conmade_cb	resume_cbs               r   	start_tlsBaseEventLoop.start_tls  s<     ;CDD*cnn55!n&' ' y"95AAYM)IJL L ##%++J"7!5!&( 	!|,^^L$@$@)L
NN9#;#;<		LL ***  	OO		s0   C$D>'C? ,C=-C? 1D>=C? ?<D;;D>)rF   rH   r  
reuse_portallow_broadcastr1   c          
      n	  #    U	b  U	R                   [        R                  :X  a  [        SU	< 35      eU(       d*  U(       d#  U(       d  U(       d  U(       d  U(       d  U(       aB  [	        X#XEUUUS9n
SR                  S U
R                  5        5       5      n[        SU S35      eU	R                  S5        SnGOU(       d   U(       d  US	:X  a  [        S
5      eXE4S44nGO[        [        S5      (       a  U[        R                  :X  a  X#4 H(  nUc  M  [        U[        5      (       a  M  [        S5      e   U(       aY  US	   S;  aP   [        R                  " [        R                  " U5      R                   5      (       a  [        R"                  " U5        XE4X#444nGO0 nS	U4SU44 H  u  nnUc  M  [        U[,        5      (       a  [/        U5      S:X  d  [        S5      eU R1                  X[        R2                  XVU S9I Sh  vN nU(       d  ['        S5      eU H"  u  nnnnnUU4nUU;  a  SS/UU'   UUU   U'   M$     M     UR                  5        VVs/ s H(  u  nnU(       a  US	   c  M  U(       a  US   c  M$  UU4PM*     nnnU(       d  [        S5      e/ nU H  u  u  pEu  nnSn	Sn [        R                  " U[        R2                  US9n	U(       a  [5        U	5        U(       a/  U	R7                  [        R8                  [        R:                  S5        U	R                  S5        U(       a  U	R=                  U5        U(       a#  U(       d  U R?                  U	U5      I Sh  vN   Un  O   US	   eU" 5       nU RE                  5       nU RG                  U	UUU5      nU RH                  (       a:  U(       a  [(        RJ                  " SX#UU5        O[(        RL                  " SUUU5         UI Sh  vN   UU4$ ! [$         a     GNx[&         a"  n[(        R*                  " SX/5         SnAGNSnAff = f GN6s  snnf  N! [&         a1  nU	b  U	RA                  5         URB                  " U5         SnAGM  SnAf  U	b  U	RA                  5         e = f N!   URA                  5         e = f7f)zCreate datagram connection.Nz$A datagram socket was expected, got )rY  remote_addrrF   rH   r  r  r  r  c              3   F   #    U  H  u  pU(       d  M  U S U 3v   M     g7f)=NrQ   )rR   kvs      r   rT   9BaseEventLoop.create_datagram_endpoint.<locals>.<genexpr>_  s      $NLDAAZs!A3ZLs   !!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   r  z2-tuple is expectedra  rb  zcan not get address informationrG  z@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))'rG   r+   r:   r,   dictr  itemsrJ  r*   r  r   r   r>   statS_ISSOCKosst_moderemoveFileNotFoundErrorr/   r   errorr   r   rn  r;   r2   r-   r.   SO_BROADCASTrK  rO  r   rB   r   r\  r  r  r  ) r   r   rY  r  rF   rH   r  r  r  r1   optsproblemsr_addraddr_pairs_inforb   err
addr_infosidxrt  famrT  pror[  key	addr_pairr   local_addressremote_addressrn   rN  r   r   s                                    r   create_datagram_endpoint&BaseEventLoop.create_datagram_endpointM  s     yyF... :4(CE Ekeu/z#)e'1,;=  99$NDJJL$NN 008z<= = U#F+Q;$%@AA%+O\#B"D++&..0H'5D'
40E0E'(<== 6 *Q-{"B	6==)<)D)DEEIIj1 &,O%/$=$? #B  
#$j/A{3C!DIC' *4 7 7CIN"+,A"BB&*&;&; f6G6G"'4 '< 'A !A  %")*M"NN7<3CCG#&*C"*437,
33:JsOC0	 8= "E& <F;K;K;M#E;Mi'IaL %(Yq\ %S)$;M   #E
 '$%FGGJ 6E2&0-!==%F,=,=ULD!&t,&"--v/B/BAG$$U+!		-0"."&"3"3D."III!/ 9 6E< !m##%##%11(FF,	;; 0&YJ  (()X?	LL
 (""} - " 6 &5%/6 66 !A#E8 J +'

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

* 	OOs   DR5R5-R5AP R58AR5
Q AR5 Q8QQ(R58B8Q0Q	1Q7A?R57R <R=R R5
P=R5	P=P82R58P==R5R5	Q
R%R:R5RR5R R22R5c          	      |   #    US S u  px[        XxX#U/USS  Q76 n	U	b  U	/$ UR                  XxX#XES9I S h  vN $  N7f)Nr  r  )rM   r  )
r   r[  rF   rG   rH   r  r   rD   rE   r  s
             r   rn  BaseEventLoop._ensure_resolved  sg      Ra[
DeJgabkJ6M))$V05 * D D D Ds   3<:<c                    #    U R                  X4U[        R                  X@S9I S h  vN nU(       d  [        SU< S35      eU$  N7f)N)rF   rG   r  r   zgetaddrinfo(z) returned empty list)rn  r+   r:   r/   )r   rD   rE   rF   r  rt  s         r   _create_server_getaddrinfo(BaseEventLoop._create_server_getaddrinfo  sX     ++TL171C1C27 , D D L0EFGGDs   %AAAr   )rF   r  r1   r   ru   reuse_addressr  
keep_aliver   r   r  c          
      	  #    [        U[        5      (       a  [        S5      eUb  Uc  [        S5      eUb  Uc  [        S5      eUb  [	        U5        Uc  UGb  Ub  [        S5      eU	c-  [
        R                  S:H  =(       a    [        R                  S:g  n	/ nUS:X  a  S/nOD[        U[        5      (       d)  [        U[        R                  R                  5      (       d  U/nOUnU Vs/ s H  nU R                  X#UUS	9PM     nn[        R                  " U6 I Sh  vN n[!        ["        R$                  R'                  U5      5      nS
n U GHM  nUu  nnnnn [(        R(                  " UUU5      nUR3                  U5        U	(       a/  UR5                  [(        R6                  [(        R8                  S5        U
(       a/  U[(        R:                  [(        R<                  4;   a  [?        U5        U(       a/  UR5                  [(        R6                  [(        R@                  S5        [B        (       aX  U[(        R<                  :X  aD  [E        [(        S5      (       a/  UR5                  [(        RF                  [(        RH                  S5         URK                  U5        GMP     U(       d#  [M        SU Vs/ s H  nUS   PM
     sn< 35      eSnU(       d  U H  nURW                  5         M     O>Uc  [        S5      eURX                  [(        RZ                  :w  a  [        SU< 35      eU/nU H  nUR]                  S
5        M     [_        XUXUU5      nU(       a.  URa                  5         [        Rb                  " S5      I Sh  vN   U R,                  (       a  [.        Rd                  " SU5        U$ s  snf  GN! [(        R*                   a.    U R,                  (       a  [.        R0                  " SUUUSS9   GM  f = f! [L         a  nSU< S[        U5      RO                  5       < 3nURP                  [P        RR                  :X  aN  URU                  5         URW                  5         U R,                  (       a  [.        R0                  " U5         SnAGMI  [M        URP                  U5      SeSnAff = fs  snf ! U(       d  U H  nURW                  5         M     f f = f GN]7f)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. 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_IPV6rH  rI  z%could not bind on any address out of    z)Neither host/port nor sock were specifiedrm  r   z%r is serving)3r   rz  r>   r,   rw   r  r5  r  platformr   rV   abcIterabler  r   r  setr[   r\   r]   r+   r  r  r   warningrB   r-   r.   SO_REUSEADDRr@   r   r2   SO_KEEPALIVErA   r*   r  IPV6_V6ONLYrK  r/   rL  rM  EADDRNOTAVAILrN  r   rG   r:   rJ  r   r   r  r  )r   r   rD   rE   rF   r  r1   r   ru   r  r  r  r   r   r  r   hostsfsrt  	completedresrL   socktyperH   	canonnamesar  r  r  rJ  s                                 r   create_serverBaseEventLoop.create_server  sE    : c4  HII ,CE E  +BD D d#t/ NP P $ "7 2 Os||x7OGrzT3'' {'?'?@@ $%#d 11$V8= 2 ?#  %  ,,++E	55e<=EI7% C9<6B%B!%}}R5A NN4($"--v/B/BDJ "bV^^V__,M&M&t,!"--v/B/BDJ
 "	&//1#FN;;(;(;(.(:(:(,.@		"A !\ !:?%@%$d1g%%@#C D D !	  '

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

 !( !( !s   C*S',N6S'N; .S'R> N>6DR> PR> 4R9
R> B8S'S$4S'>=P ;R> ?P  R> 
R6BR1R> R11R66R> >#S!!S')ru   r   r   c          
        #    UR                   [        R                  :w  a  [        SU< 35      eUb  U(       d  [        S5      eUb  U(       d  [        S5      eUb  [	        U5        U R                  X!USSUUS9I S h  vN u  pgU R                  (       a)  UR                  S5      n[        R                  " SX&U5        Xg4$  NC7f)	Nrm  r^  r_  r5   T)rR  r   r   r+   z%r handled: (%r, %r))
rG   r+   r:   r,   rw   rr  r  rs  r   r  )r   r   r1   ru   r   r   r   rN  s           r   connect_accepted_socket%BaseEventLoop.connect_accepted_socketx  s     
 99***A$JKK ,SCE E  +CBD D d#$($E$EC"7!5 %F %7 7	 ;; ++H5DLL/(K""7s   A=C?C ACc                   #    U" 5       nU R                  5       nU R                  X#U5      n UI S h  vN   U R                  (       a&  [        R
                  " SUR                  5       XS5        XS4$  N>!   UR                  5         e = f7f)Nz Read pipe %r connected: (%r, %r))r   ra  r   r  r   r  filenor   r   r`  rN  r   r   s         r   connect_read_pipeBaseEventLoop.connect_read_pipe  s}     #%##%2246J		LL
 ;;LL;	="" 	OO+   *B	A3 A1A3 :B	1A3 3BB	c                   #    U" 5       nU R                  5       nU R                  X#U5      n UI S h  vN   U R                  (       a&  [        R
                  " SUR                  5       XS5        XS4$  N>!   UR                  5         e = f7f)Nz!Write pipe %r connected: (%r, %r))r   rd  r   r  r   r  r  r  s         r   connect_write_pipe BaseEventLoop.connect_write_pipe  s}     #%##%33DFK		LL
 ;;LL<	="" 	OOr  c                 ~   U/nUb  UR                  S[        U5       35        Ub2  U[        R                  :X  a  UR                  S[        U5       35        O@Ub  UR                  S[        U5       35        Ub  UR                  S[        U5       35        [        R
                  " SR                  U5      5        g )Nzstdin=zstdout=stderr=zstdout=zstderr= )rB   r'   r#   r%   r   r  r  )r   r  ri  rj  rk  r  s         r   _log_subprocessBaseEventLoop._log_subprocess  s    uKK&e!4 567&J,=,="=KK.f)=(>?@!gl6&:%;<=!gl6&:%;<=SXXd^$r!   )	ri  rj  rk  universal_newlinesrh  rl  encodingerrorstextc       	   	        #    [        U[        [        45      (       d  [        S5      eU(       a  [        S5      eU(       d  [        S5      eUS:w  a  [        S5      eU(       a  [        S5      eU	b  [        S5      eU
b  [        S5      eU" 5       nS nU R                  (       a  S	U-  nU R                  XXE5        U R                  " XS
X4XX40 UD6I S h  vN nU R                  (       a  Ub  [        R                  " SX5        X4$  N27f)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  rm  r   r  )r   r   cmdri  rj  rk  r  rh  rl  r  r  r  r=  rN  	debug_logr   s                   r   subprocess_shell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  6B994KCIK K	;;90KK)7""	Ks   CDD	3Dc       	   	        #    U(       a  [        S5      eU(       a  [        S5      eUS:w  a  [        S5      eU(       a  [        S5      eU	b  [        S5      eU
b  [        S5      eU4U-   nU" 5       nS nU R                  (       a  SU< 3nU R                  UX4U5        U R                  " XS	X4UU40 UD6I S h  vN nU R                  (       a  Ub  [        R
                  " S
UU5        UU4$  N47f)Nr  zshell must be Falser   r  r  r  r  zexecute program Fr  )r,   r  r  rm  r   r  )r   r   programri  rj  rk  r  rh  rl  r  r  r  rg  r=  
popen_argsrN  r  r   s                     r   subprocess_execBaseEventLoop.subprocess_exec  s     ?@@233a<011122455233Z$&
#%	;; +7+6I  E6B99% 	 ;;90KK)Y7(""s   B7C09C.:5C0c                     U R                   $ )zKReturn an exception handler, or None if the default one is in use.
        )r  r   s    r   get_exception_handler#BaseEventLoop.get_exception_handler	  s     &&&r!   c                 T    Ub  [        U5      (       d  [        SU< 35      eXl        g)as  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 )rB  r>   r  )r   handlers     r   set_exception_handler#BaseEventLoop.set_exception_handler  s6     x'8'8 ##*+/ 0 0")r!   c                    UR                  S5      nU(       d  SnUR                  S5      nUb  [        U5      X3R                  4nOSnSU;  aA  U R                  b4  U R                  R                  (       a  U R                  R                  US'   U/n[        U5       H  nUS;   a  M  X   nUS:X  a:  S	R                  [        R                  " U5      5      nS
nXxR                  5       -  nOKUS:X  a:  S	R                  [        R                  " U5      5      nSnXxR                  5       -  nO[        U5      nUR                  U SU 35        M     [        R                  " SR                  U5      US9  g)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.

This default handler logs the error message and other
context-dependent information.  In debug mode, a truncated
stack trace is also appended showing where the given object
(e.g. a handle or future or task) was created, if any.

The context parameter has the same meaning as in
`call_exception_handler()`.
r  z!Unhandled exception in event looprh   NFsource_tracebackhandle_traceback>   r  rh   r5   z+Object created at (most recent call last):
z+Handle created at (most recent call last):
rI  
r  )getrG   __traceback__r$  r;  sortedr  	tracebackformat_listrstripr   rB   r   r  )	r   r6  r  rh   r  	log_linesr  valuetbs	            r   default_exception_handler'BaseEventLoop.default_exception_handler  sS    ++i(9GKK,	 Y4K4KLHHg-$$0$$66$$66 &' I	'?C..LE((WWY2259:F$**WWY2259:F$UuBug./ #  	TYYy)H=r!   c                    U R                   c   U R                  U5        g SnUR                  S5      nUc  UR                  S5      nUc  UR                  S5      nUb!  [        US5      (       a  UR                  5       nUb.  [        US	5      (       a  UR                  U R                   X5        gU R                  X5        g! [        [        4 a    e [         a    [
        R                  " SSS9   gf = f! [        [        4 a    e [         aY  n U R                  S
UUS.5         SnAg! [        [        4 a    e [         a    [
        R                  " SSS9    SnAgf = fSnAff = f)a8  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;
- 'source_traceback' (optional): Traceback of the source;
- 'handle_traceback' (optional): Traceback of the handle;
- '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>  r  r   get_contextrunz$Unhandled error in exception handler)r  rh   r6  zeException in default exception handler while handling an unexpected error in custom exception handler)r  r  ri   rj   r  r   r  r
  r*   r  r  )r   r6  ctxthingrn   s        r   r  $BaseEventLoop.call_exception_handlerQ  sr   0 ""*	,..w7$0F+= $KK1E=#KK1E$)F)F++-C?wsE':':GGD33TC++D:3  12   , E&*,	,0  12   0022#I%(#*4  
 #$56 $ 0 LL "? +/0 000sG   C BC9 2C9 /C65C69E,D../E$E'#E$$E''E,c                 ^    UR                   (       d  U R                  R                  U5        gg)zAdd a Handle to _ready.N)
_cancelledr  rB   r   r   s     r   _add_callbackBaseEventLoop._add_callback  s"      KKv& !r!   c                 F    U R                  U5        U R                  5         g)z6Like _add_callback() but called from a signal handler.N)r  rp  r  s     r   _add_callback_signalsafe&BaseEventLoop._add_callback_signalsafe  s    6"r!   c                 R    UR                   (       a  U =R                  S-  sl        gg)z3Notification that a TimerHandle has been cancelled.r   N)r  r  r  s     r   _timer_handle_cancelled%BaseEventLoop._timer_handle_cancelled  s!    ''1,' r!   c                    [        U R                  5      nU[        :  a{  U R                  U-  [        :  ad  / nU R                   H.  nUR
                  (       a	  SUl        M  UR                  U5        M0     [        R                  " U5        X l        SU l        OU R                  (       a  U R                  S   R
                  (       am  U =R                  S-  sl        [        R                  " U R                  5      nSUl        U R                  (       a   U R                  S   R
                  (       a  Mm  SnU R                  (       d  U R                  (       a  SnOTU R                  (       aC  U R                  S   R                  U R                  5       -
  nU[        :  a  [        nOUS:  a  SnU R                  R!                  U5      nU R#                  U5        SnU R                  5       U R$                  -   nU R                  (       au  U R                  S   nUR                  U:  a  OU[        R                  " U R                  5      nSUl        U R                  R                  U5        U R                  (       a  Mu  [        U R                  5      n['        U5       H  nU R                  R)                  5       nUR
                  (       a  M0  U R*                  (       as   X0l        U R                  5       n	UR/                  5         U R                  5       U	-
  n
XR0                  :  a!  [2        R4                  " S[7        U5      U
5        SU l        M  UR/                  5         M     Sng! SU l        f = f)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)r   r  _MIN_SCHEDULED_TIMER_HANDLESr  %_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr  rB   r  heapifyheappopr  r  _whenr  MAXIMUM_SELECT_TIMEOUT	_selectorselectrt  r  rangepopleftr  r$  _runr#  r   r  r    )r   sched_countnew_scheduledr   r  rs  end_timentodoir  r  s              r   r  BaseEventLoop._run_once  s    $//*66''+556 M//$$(-F%!((0	 * MM-(+O*+D' //dooa&8&C&C++q0+t7$)! //dooa&8&C&C&C
 ;;$..G__ooa(..<G//01^^**73
Z(
 99;!7!77oo__Q'F||x']]4??3F %FKKv& ooo DKK uA[[((*F  {{	0+1(BKKMr)B888'G'5f'=rC ,0D(! "  ,0D(s   %A)M..	M7c                 "   [        U5      [        U R                  5      :X  a  g U(       a?  [        R                  " 5       U l        [        R
                  " [        R                  5        O [        R
                  " U R                  5        Xl        g rP   )rz  r&  r  #get_coroutine_origin_tracking_depthr'  #set_coroutine_origin_tracking_depthr   DEBUG_STACK_DEPTHr   enableds     r   r  ,BaseEventLoop._set_coroutine_origin_tracking  sk    =D!H!HII779 733++- 33;;= 3:/r!   c                     U R                   $ rP   )r  r   s    r   r/  BaseEventLoop.get_debug  s    {{r!   c                 t    Xl         U R                  5       (       a  U R                  U R                  U5        g g rP   )r  r-  r|  r  r<  s     r   r   BaseEventLoop.set_debug  s/    ??%%d&I&I7S r!   )r(  r)  r  r  r&  r'  r$  r  r  r  r*  r  r"  r  r  r  r%  r  r  r#  rP   )NNNr  )r   )r   N)FNN)Yr   r   r   r   r   r   r   r?  rD  rG  rO  rX  r\  ra  rd  rm  rp  rt  r9  ry  r  r  r  r  r  r  r  r  r  r  rl   r   r.  r  r  r  r-  r  r  r  r  r  r  r  r|  r  r  r  r  r   r-  r'  r)  r&  rW  rv  rr  r  r  r  r  r  r+   r:   rn  r  r?   
AI_PASSIVEr  r  r  r  r  r#   r$   r  r  r   r  r  r  r  r!  r$  r  r  r/  r   r   rQ   r!   r   r   r     s    /@
) )-d 2%""%)$" 9=" $t"&!%!%" CG"
 @D(,"
 AE)-" 04"""7DG
"20DK'(( 	($L*. %MM -  :> 0 6: $ 26 &%(" =A 	5 *
2 "#!1H7A(,A./4*).X 59Q#14T"&!%!%$Q#j */"&!%	#8-<#'-<^1"4 %*(,.2-1	.+b EID#./q267;$	D#N '(f.@.@%&a
D 59O ####"&!%Of "&!%	#<# # % &0__&0oo&0oo27%)1(,T"#J %/OOJOO%/__$)1'+Dt	 #D'
*"0>dH0T'

-
Qf:Tr!   r   )r   r   )r   )7__doc__rV   collections.abcconcurrent.futuresr  rM  r  r[   r  r+   r  r#   r  r  r  r  r  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   re   ro   rr   rw   Protocolry   AbstractServerr   AbstractEventLoopr   rQ   r!   r   <module>rM     s0         	       
                $
  #  ), % FJ'	 # J8v," 6=!!G>
A)	 2 2 A)HKV"" K\rTF,, rT}  
Cs   D D D 