\dodZdZddlZddlZddlZddlZddlZddlZddlm Z GddZ Gdd e Z Gd d Z Gd d Z GddZGddeZdaejZGddejZeZdZdZdZdZdZdZdZd"dZdZdZdZ d Z!eZ"eZ#eZ$eZ%eZ& dd!l'mZmZmZmZmZeZ(eZ)eZ*eZ+eZ,dS#e-$rYdSwxYw)#z!Event loop and event loop policy.)AbstractEventLoopPolicyAbstractEventLoopAbstractServerHandle TimerHandleget_event_loop_policyset_event_loop_policyget_event_loopset_event_loopnew_event_loopget_child_watcherset_child_watcher_set_running_loopget_running_loop_get_running_loopN)format_helpersc<eZdZdZdZd dZdZdZdZdZ d Z dS) rz1Object returned by callback registration methods.) _callback_args _cancelled_loop_source_traceback_repr __weakref___contextNc|tj}||_||_||_||_d|_d|_|jr-tj tj d|_ dSd|_ dS)NFr) contextvars copy_contextrrrrrr get_debugr extract_stacksys _getframer)selfcallbackargsloopcontexts ..\python\lib\asyncio\events.py__init__zHandle.__init__s ?!.00G  !  :   ! ! *%3%A a  &"&"D " " "&*D " " "c@|jjg}|jr|d|j2|t j|j|j|jr4|jd}|d|dd|d|S)N cancelledz created at r:r) __class____name__rappendrr_format_callback_sourcerr)r$infoframes r) _repr_infozHandle._repr_info.s'( ? % KK $ $ $ > % KK> ,, - - -  ! =*2.E KK;eAh;;q;; < < < r+c|j|jS|}dd|S)Nz<{}> )rr6formatjoin)r$r4s r)__repr__zHandle.__repr__:s= : !:   }}SXXd^^,,,r+c|jsDd|_|jrt||_d|_d|_dSdS)NT)rrr reprrrrr$s r)cancelz Handle.cancel@sT "DOz##%% ("$ZZ !DNDJJJ  r+c|jSN)rr>s r)r-zHandle.cancelledKs r+cB |jj|jg|jRn}#tt f$rt $r_}tj|j|j}d|}|||d}|j r |j |d<|j |Yd}~nd}~wwxYwd}dS)NzException in callback )message exceptionhandlesource_traceback) rrunrr SystemExitKeyboardInterrupt BaseExceptionrr3rrcall_exception_handler)r$exccbmsgr(s r)_runz Handle._runNs 7 DM dn :tz : : : : :-.     7 7 77 ,,B/2//C G % E.2.D*+ J - -g 6 6 6 6 6 6 6 6 7s BABBrA) r1 __module__ __qualname____doc__ __slots__r*r6r;r?r-rOr+r)rrs;;I * * * *   ---   r+rcjeZdZdZddgZdfd ZfdZdZdZd Z d Z d Z d Z fd Z dZxZS)rz7Object returned by timed callback registration methods. _scheduled_whenNct|||||jr|jd=||_d|_dS)Nr.F)superr*rrWrV)r$whenr%r&r'r(r0s r)r*zTimerHandle.__init__gsI 4w777  ! +&r* r+ct}|jrdnd}||d|j|S)Nrzwhen=)rYr6rinsertrW)r$r4posr0s r)r6zTimerHandle._repr_infonsLww!!##?)aa C---... r+c*t|jSrA)hashrWr>s r)__hash__zTimerHandle.__hash__tsDJr+cZt|tr|j|jkStSrA isinstancerrWNotImplementedr$others r)__lt__zTimerHandle.__lt__w) e[ ) ) ,: + +r+ct|tr%|j|jkp||StSrArdrrW__eq__rerfs r)__le__zTimerHandle.__le__|; e[ ) ) B: +At{{5/A/A Ar+cZt|tr|j|jkStSrArcrfs r)__gt__zTimerHandle.__gt__rir+ct|tr%|j|jkp||StSrArkrfs r)__ge__zTimerHandle.__ge__rnr+ct|tr@|j|jko/|j|jko|j|jko|j|jkSt SrA)rdrrWrrrrerfs r)rlzTimerHandle.__eq__sc e[ ) ) 9J%+-8Neo58J%+-8Ou'77 9r+c|js|j|tdSrA)rr_timer_handle_cancelledrYr?)r$r0s r)r?zTimerHandle.cancels= 5 J . .t 4 4 4 r+c|jS)zReturn a scheduled callback time. The time is an absolute timestamp, using the same time reference as loop.time(). )rWr>s r)rZzTimerHandle.whens zr+rA)r1rPrQrRrSr*r6rarhrmrprrrlr?rZ __classcell__)r0s@r)rrbsAAw'I               r+rcBeZdZdZdZdZdZdZdZdZ dZ d Z d S) rz,Abstract server returned by create_server().ct)z5Stop serving. This leaves existing connections open.NotImplementedErrorr>s r)closezAbstractServer.close!!r+ct)z4Get the event loop the Server object is attached to.rzr>s r)get_loopzAbstractServer.get_loopr}r+ct)z3Return True if the server is accepting connections.rzr>s r) is_servingzAbstractServer.is_servingr}r+cKt)zStart accepting connections. This method is idempotent, so it can be called when the server is already being serving. rzr>s r) start_servingzAbstractServer.start_serving "!r+cKt)zStart accepting connections until the coroutine is cancelled. The server is closed when the coroutine is cancelled. rzr>s r) serve_foreverzAbstractServer.serve_forever "!r+cKt)z*Coroutine to wait until service is closed.rzr>s r) wait_closedzAbstractServer.wait_closed !!r+c K|SrArTr>s r) __aenter__zAbstractServer.__aenter__s  r+cfK||d{VdSrA)r|r)r$rLs r) __aexit__zAbstractServer.__aexit__s=            r+N) r1rPrQrRr|rrrrrrrrTr+r)rrs66""""""""""""""""""!!!!!r+rc eZdZdZdZdZdZdZdZdZ dZ d Z d Z d d d Z d d dZd d dZdZdZd d ddZd d dZdZdZddddddZdJdZ dKd dddd d d d d d d d dZ dKejejd dd d d d d dd d ZdLdd!d"Zd#d d d d$d%Z dMd d d d d d&d'Z dMd dd d d dd(d)Z d d d d*d+Z! dKdddd d d d d,d-Z"d.Z#d/Z$e%j&e%j&e%j&d0d1Z'e%j&e%j&e%j&d0d2Z(d3Z)d4Z*d5Z+d6Z,d7Z-d8Z.d9Z/dJd:Z0d;Z1d<Z2d=Z3d>Z4dLd d!d?Z5d@Z6dAZ7dBZ8dCZ9dDZ:dEZ;dFZdIZ?d S)NrzAbstract event loop.ct)z*Run the event loop until stop() is called.rzr>s r) run_foreverzAbstractEventLoop.run_foreverr}r+ct)zpRun the event loop until a Future is done. Return the Future's result, or raise its exception. rz)r$futures r)run_until_completez$AbstractEventLoop.run_until_completes "!r+ct)zStop the event loop as soon as reasonable. Exactly how soon that is may depend on the implementation, but no more I/O callbacks should be scheduled. rzr>s r)stopzAbstractEventLoop.stops "!r+ct)z3Return whether the event loop is currently running.rzr>s r) is_runningzAbstractEventLoop.is_runningr}r+ct)z*Returns True if the event loop was closed.rzr>s r) is_closedzAbstractEventLoop.is_closedr}r+ct)zClose the loop. The loop should not be running. This is idempotent and irreversible. No other methods should be called after this one. rzr>s r)r|zAbstractEventLoop.closes "!r+cKt)z,Shutdown all active asynchronous generators.rzr>s r)shutdown_asyncgensz$AbstractEventLoop.shutdown_asyncgensrr+cKt)z.Schedule the shutdown of the default executor.rzr>s r)shutdown_default_executorz+AbstractEventLoop.shutdown_default_executorrr+ct)z3Notification that a TimerHandle has been cancelled.rz)r$rEs r)ruz)AbstractEventLoop._timer_handle_cancelledr}r+N)r(c&|jd|g|Rd|iS)Nrr() call_laterr$r%r(r&s r) call_soonzAbstractEventLoop.call_soons&tq(CTCCC7CCCr+ctrArz)r$delayr%r(r&s r)rzAbstractEventLoop.call_later!!r+ctrArz)r$rZr%r(r&s r)call_atzAbstractEventLoop.call_at rr+ctrArzr>s r)timezAbstractEventLoop.time rr+ctrArzr>s r) create_futurezAbstractEventLoop.create_futurerr+)namer(ctrArz)r$cororr(s r) create_taskzAbstractEventLoop.create_taskrr+ctrArzrs r)call_soon_threadsafez&AbstractEventLoop.call_soon_threadsaferr+ctrArz)r$executorfuncr&s r)run_in_executorz!AbstractEventLoop.run_in_executorrr+ctrArz)r$rs r)set_default_executorz&AbstractEventLoop.set_default_executor rr+r)familytypeprotoflagscKtrArz)r$hostportrrrrs r) getaddrinfozAbstractEventLoop.getaddrinfo%rr+cKtrArz)r$sockaddrrs r) getnameinfozAbstractEventLoop.getnameinfo) !!r+) sslrrrsock local_addrserver_hostnamessl_handshake_timeoutssl_shutdown_timeouthappy_eyeballs_delay interleavec KtrArz)r$protocol_factoryrrrrrrrrrrrrrs r)create_connectionz#AbstractEventLoop.create_connection,s"!r+dT) rrrbacklogr reuse_address reuse_portrrrc Kt)a#A coroutine which creates a TCP server bound to host and port. The return value is a Server object which can be used to stop the service. If host is an empty string or None all interfaces are assumed and a list of multiple sockets will be returned (most likely one for IPv4 and another one for IPv6). The host parameter can also be a sequence (e.g. list) of hosts to bind to. family can be set to either AF_INET or AF_INET6 to force the socket to use IPv4 or IPv6. If not set it will be determined from host (defaults to AF_UNSPEC). flags is a bitmask for getaddrinfo(). sock can optionally be specified in order to use a preexisting socket object. backlog is the maximum number of queued connections passed to listen() (defaults to 100). ssl can be set to an SSLContext to enable SSL over the accepted connections. reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified will automatically be set to True on UNIX. reuse_port tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are bound to, so long as they all set this flag when being created. This option is not supported on Windows. ssl_handshake_timeout is the time in seconds that an SSL server will wait for completion of the SSL handshake before aborting the connection. Default is 60s. ssl_shutdown_timeout is the time in seconds that an SSL server will wait for completion of the SSL shutdown procedure before aborting the connection. Default is 30s. start_serving set to True (default) causes the created server to start accepting connections immediately. When set to False, the user should await Server.start_serving() or Server.serve_forever() to make the server to start accepting connections. rz)r$rrrrrrrrrrrrrs r) create_serverzAbstractEventLoop.create_server6sp"!r+)fallbackcKt)zRSend a file through a transport. Return an amount of sent bytes. rz)r$ transportfileoffsetcountrs r)sendfilezAbstractEventLoop.sendfileprr+F) server_siderrrcKt)z|Upgrade a transport to TLS. Return a new transport that *protocol* should start using immediately. rz)r$rprotocol sslcontextrrrrs r) start_tlszAbstractEventLoop.start_tlsxs"!r+)rrrrrcKtrArz)r$rpathrrrrrs r)create_unix_connectionz(AbstractEventLoop.create_unix_connectionrr+)rrrrrrcKt)aWA coroutine which creates a UNIX Domain Socket server. The return value is a Server object, which can be used to stop the service. path is a str, representing a file system path to bind the server socket to. sock can optionally be specified in order to use a preexisting socket object. backlog is the maximum number of queued connections passed to listen() (defaults to 100). ssl can be set to an SSLContext to enable SSL over the accepted connections. ssl_handshake_timeout is the time in seconds that an SSL server will wait for the SSL handshake to complete (defaults to 60s). ssl_shutdown_timeout is the time in seconds that an SSL server will wait for the SSL shutdown to finish (defaults to 30s). start_serving set to True (default) causes the created server to start accepting connections immediately. When set to False, the user should await Server.start_serving() or Server.serve_forever() to make the server to start accepting connections. rz) r$rrrrrrrrs r)create_unix_serverz$AbstractEventLoop.create_unix_serversD"!r+)rrrcKt)aHandle an accepted connection. This is used by servers that accept connections outside of asyncio, but use asyncio to handle connections. This method is a coroutine. When completed, the coroutine returns a (transport, protocol) pair. rz)r$rrrrrs r)connect_accepted_socketz)AbstractEventLoop.connect_accepted_sockets"!r+)rrrrrallow_broadcastrcKt)aA coroutine which creates a datagram endpoint. This method will try to establish the endpoint in the background. When successful, the coroutine returns a (transport, protocol) pair. protocol_factory must be a callable returning a protocol instance. socket family AF_INET, socket.AF_INET6 or socket.AF_UNIX depending on host (or family if specified), socket type SOCK_DGRAM. reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified it will automatically be set to True on UNIX. reuse_port tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are bound to, so long as they all set this flag when being created. This option is not supported on Windows and some UNIX's. If the :py:data:`~socket.SO_REUSEPORT` constant is not defined then this capability is unsupported. allow_broadcast tells the kernel to allow this endpoint to send messages to the broadcast address. sock can optionally be specified in order to use a preexisting socket object. rz) r$rr remote_addrrrrrrrrs r)create_datagram_endpointz*AbstractEventLoop.create_datagram_endpointsB"!r+cKt)aRegister read pipe in event loop. Set the pipe to non-blocking mode. protocol_factory should instantiate object with Protocol interface. pipe is a file-like object. Return pair (transport, protocol), where transport supports the ReadTransport interface.rzr$rpipes r)connect_read_pipez#AbstractEventLoop.connect_read_pipe"!r+cKt)aRegister write pipe in event loop. protocol_factory should instantiate object with BaseProtocol interface. Pipe is file-like object already switched to nonblocking. Return pair (transport, protocol), where transport support WriteTransport interface.rzrs r)connect_write_pipez$AbstractEventLoop.connect_write_piperr+)stdinstdoutstderrcKtrArz)r$rcmdrrrkwargss r)subprocess_shellz"AbstractEventLoop.subprocess_shellrr+cKtrArz)r$rrrrr&rs r)subprocess_execz!AbstractEventLoop.subprocess_execrr+ctrArzr$fdr%r&s r) add_readerzAbstractEventLoop.add_readerrr+ctrArzr$rs r) remove_readerzAbstractEventLoop.remove_readerrr+ctrArzrs r) add_writerzAbstractEventLoop.add_writerrr+ctrArzrs r) remove_writerzAbstractEventLoop.remove_writerrr+cKtrArz)r$rnbytess r) sock_recvzAbstractEventLoop.sock_recvrr+cKtrArz)r$rbufs r)sock_recv_intoz AbstractEventLoop.sock_recv_into"rr+cKtrArz)r$rbufsizes r) sock_recvfromzAbstractEventLoop.sock_recvfrom%rr+cKtrArz)r$rr r s r)sock_recvfrom_intoz$AbstractEventLoop.sock_recvfrom_into(rr+cKtrArz)r$rdatas r) sock_sendallzAbstractEventLoop.sock_sendall+rr+cKtrArz)r$rraddresss r) sock_sendtozAbstractEventLoop.sock_sendto.rr+cKtrArz)r$rrs r) sock_connectzAbstractEventLoop.sock_connect1rr+cKtrArz)r$rs r) sock_acceptzAbstractEventLoop.sock_accept4rr+cKtrArz)r$rrrrrs r) sock_sendfilezAbstractEventLoop.sock_sendfile7rr+ctrArz)r$sigr%r&s r)add_signal_handlerz$AbstractEventLoop.add_signal_handler=rr+ctrArz)r$r!s r)remove_signal_handlerz'AbstractEventLoop.remove_signal_handler@rr+ctrArz)r$factorys r)set_task_factoryz"AbstractEventLoop.set_task_factoryErr+ctrArzr>s r)get_task_factoryz"AbstractEventLoop.get_task_factoryHrr+ctrArzr>s r)get_exception_handlerz'AbstractEventLoop.get_exception_handlerMrr+ctrArz)r$handlers r)set_exception_handlerz'AbstractEventLoop.set_exception_handlerPrr+ctrArzr$r(s r)default_exception_handlerz+AbstractEventLoop.default_exception_handlerSrr+ctrArzr0s r)rKz(AbstractEventLoop.call_exception_handlerVrr+ctrArzr>s r)r zAbstractEventLoop.get_debug[rr+ctrArz)r$enableds r) set_debugzAbstractEventLoop.set_debug^rr+)rNN)rNrA)@r1rPrQrRrrrrrr|rrrurrrrrrrrrrrrsocket AF_UNSPEC AI_PASSIVErrrrrrrrr subprocessPIPErrrrrrr rrrrrrrrr"r$r'r)r+r.r1rKr r6rTr+r)rrs """"""""""""""" " " """"""" """26DDDDD:>"""""6:""""""""""" )-d""""" =A""""""""""" "#!1"""""""""59"$4 "&!%!%$"""""598"&#$DT"&!%8"8"8"8"8"t"#'"""""%*(,.2-1 " " " " "*."4 "&!% """""*.""s"&!% """"""""""L"&!% " " " " " EI!"./q59d7;$ !"!"!"!"!"J " " " " " "&0_&0o&0o"""""%/O%/_%/_""""""""""""""""" """"""""""""""""""""""""""(,""""" """""" """""" """""""""""" """"""""r+rc0eZdZdZdZdZdZdZdZdS)rz-Abstract policy for accessing the event loop.ct)a:Get the event loop for the current context. Returns an event loop object implementing the BaseEventLoop interface, or raises an exception in case no event loop has been set for the current context and the current policy does not specify to create one. It should never return None.rzr>s r)r z&AbstractEventLoopPolicy.get_event_loopes "!r+ct)z3Set the event loop for the current context to loop.rzr$r's r)r z&AbstractEventLoopPolicy.set_event_loopor}r+ct)zCreate and return a new event loop object according to this policy's rules. If there's need to set this loop as the event loop for the current context, set_event_loop must be called explicitly.rzr>s r)r z&AbstractEventLoopPolicy.new_event_loopss "!r+ct)z$Get the watcher for child processes.rzr>s r)r z)AbstractEventLoopPolicy.get_child_watcher{r}r+ct)z$Set the watcher for child processes.rz)r$watchers r)r z)AbstractEventLoopPolicy.set_child_watcherr}r+N) r1rPrQrRr r r r r rTr+r)rrbse77"""""""""""""""""r+rcTeZdZdZdZGddejZdZdZ dZ dZ dS) BaseDefaultEventLoopPolicyaDefault policy implementation for accessing the event loop. In this policy, each thread has its own event loop. However, we only automatically create an event loop by default for the main thread; other threads by default have no event loop. Other policies may have different rules (e.g. a single global event loop, or automatically creating an event loop per thread, or using some other notion of context to which an event loop is associated). NceZdZdZdZdS)!BaseDefaultEventLoopPolicy._LocalNF)r1rPrQr _set_calledrTr+r)_LocalrHs r+rJc8||_dSrA)rJ_localr>s r)r*z#BaseDefaultEventLoopPolicy.__init__skkmm r+cL|jjY|jjsMtjtjur'|||jj(tdtjj z|jjS)zvGet the event loop for the current context. Returns an instance of EventLoop or raises an exception. Nz,There is no current event loop in thread %r.) rLrrI threadingcurrent_thread main_threadr r RuntimeErrorrr>s r)r z)BaseDefaultEventLoopPolicy.get_event_loops K  %K+ &(**i.C.E.EEE    3 3 5 5 6 6 6 ;  $M!*!9!;!;!@ ABB B{  r+cd|j_|:t|ts%t dt |jd||j_dS)zSet the event loop.TNzs r)r z)BaseDefaultEventLoopPolicy.new_event_loops !!###r+) r1rPrQrRrVrNlocalrJr*r r r rTr+r)rFrFs  M$$$!!! !!!$$$$$r+rFceZdZdZdS) _RunningLoopr7N)r1rPrQloop_pidrTr+r)rYrYsHHHr+rYcDt}|td|S)zrReturn the running event loop. Raise a RuntimeError if there is none. This function is thread-specific. Nzno running event loop)rrQr's r)rrs(   D |2333 Kr+c^tj\}}||tjkr|SdSdS)zReturn the running event loop or None. This is a low-level function intended to be used by event loops. This function is thread-specific. N) _running_looprZosgetpid) running_looppids r)rrs;&.L#C29;;$6$6 $6$6r+cD|tjft_dS)zSet the running event loop. This is a low-level function intended to be used by event loops. This function is thread-specific. N)r_r`r^rZr\s r)rrs#BIKK0Mr+ctt5tddlm}|addddS#1swxYwYdS)NrDefaultEventLoopPolicy)_lock_event_loop_policyrfres r)_init_event_loop_policyrjs ::  % 0 0 0 0 0 0!7!7!9!9 ::::::::::::::::::s -11c:tttS)z"Get the current event loop policy.)rhrjrTr+r)rrs!!!! r+c|:t|ts%tdt|jd|adS)zZSet the current event loop policy. If policy is None, the default policy is restored.NzDpolicy must be an instance of AbstractEventLoopPolicy or None, not 'rS)rdrrTrr1rh)policys r)rrsM *V5L"M"Mw_cdj_k_k_twwwxxxr+ctS)aGReturn an asyncio event loop. When called from a coroutine or a callback (e.g. scheduled with call_soon or similar API), this function will always return the running event loop. If there is no running event loop set, the function will return the result of `get_event_loop_policy().get_event_loop()` call. )_py__get_event_looprTr+r)r r s   r+cft}||StSrA)rrr ) stacklevel current_loops r)_get_event_looprts3 %&&L " " 1 1 3 33r+cHt|dS)zCEquivalent to calling get_event_loop_policy().set_event_loop(loop).N)rr r\s r)r r s"**400000r+cBtS)z?Equivalent to calling get_event_loop_policy().new_event_loop().)rr rTr+r)r r $s " " 1 1 3 33r+cBtS)zBEquivalent to calling get_event_loop_policy().get_child_watcher().)rr rTr+r)r r )s " " 4 4 6 66r+cDt|S)zMEquivalent to calling get_event_loop_policy().set_child_watcher(watcher).)rr )rDs r)r r .s ! " " 4 4W = ==r+)rrrr rt)rp).rR__all__rr_r8r;r"rNrirrrrrrrFrhLockrgrWrYr^rrrrjrrr rtr r r r _py__get_running_loop_py__set_running_loop_py_get_running_loop_py_get_event_loopro_asyncio_c__get_running_loop_c__set_running_loop_c_get_running_loop_c_get_event_loop_c__get_event_loop ImportErrorrTr+r)rs>''   GGGGGGGGT<<<<<&<<<~'!'!'!'!'!'!'!'!TT"T"T"T"T"T"T"T"n """"""""D3$3$3$3$3$!83$3$3$t  9?        111:::    ! ! !4444111 444 777 >>>*)'#%)MMMMMMMMMMMMMM -,*&(   DD sC++C43C4