U if4f@s|dZdZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z GdddZ Gd d d e Z Gd d d Z Gd ddZGdddZGdddeZdaeZGdddejZeZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Z d)d*Z!eZ"eZ#eZ$eZ%zdd+l&mZmZmZmZWne'k rfYnXeZ(eZ)eZ*eZ+dS),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_helpers) exceptionsc@sFeZdZdZdZdddZddZdd Zd d Zd d Z ddZ dS)rz1Object returned by callback registration methods.) _callback_args _cancelled_loop_source_traceback_repr __weakref___contextNcCs\|dkrt}||_||_||_||_d|_d|_|jrRt t d|_ nd|_ dS)NFr) contextvarsZ copy_contextrrrrrr get_debugr extract_stacksys _getframer)selfcallbackargsloopcontextr&3/opt/alt/python38/lib64/python3.8/asyncio/events.py__init__ s zHandle.__init__cCsl|jjg}|jr|d|jdk r:|t|j|j|jrh|jd}|d|dd|d|S)N cancelledz created at r:r) __class____name__rappendrr_format_callback_sourcerr)r!infoframer&r&r' _repr_info/s    zHandle._repr_infocCs(|jdk r|jS|}dd|S)Nz<{}> )rr2formatjoin)r!r0r&r&r'__repr__;s zHandle.__repr__cCs0|js,d|_|jr t||_d|_d|_dSNT)rrrreprrrrr!r&r&r'cancelAs   z Handle.cancelcCs|jSN)rr9r&r&r'r)LszHandle.cancelledc Csz|jj|jf|jWn|ttfk r4Yndtk r}zFt|j|j}d|}|||d}|j rz|j |d<|j |W5d}~XYnXd}dS)NzException in callback )messageZ exceptionhandleZsource_traceback) rrunrr SystemExitKeyboardInterrupt BaseExceptionrr/rrcall_exception_handler)r!exccbmsgr%r&r&r'_runOs$  z Handle._run)N) r- __module__ __qualname____doc__ __slots__r(r2r6r:r)rFr&r&r&r'rs   rcseZdZdZddgZdfdd ZfddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ fddZddZZS)rz7Object returned by timed callback registration methods. _scheduled_whenNcs<|dk s tt|||||jr,|jd=||_d|_dS)Nr*F)AssertionErrorsuperr(rrLrK)r!whenr"r#r$r%r,r&r'r(hs  zTimerHandle.__init__cs0t}|jrdnd}||d|j|S)Nrzwhen=)rNr2rinsertrL)r!r0posrPr&r'r2ps zTimerHandle._repr_infocCs t|jSr;)hashrLr9r&r&r'__hash__vszTimerHandle.__hash__cCs |j|jkSr;rLr!otherr&r&r'__lt__yszTimerHandle.__lt__cCs|j|jkrdS||Sr7rL__eq__rWr&r&r'__le__|s zTimerHandle.__le__cCs |j|jkSr;rVrWr&r&r'__gt__szTimerHandle.__gt__cCs|j|jkrdS||Sr7rZrWr&r&r'__ge__s zTimerHandle.__ge__cCs>t|tr:|j|jko8|j|jko8|j|jko8|j|jkStSr;) isinstancerrLrrrNotImplementedrWr&r&r'r[s     zTimerHandle.__eq__cCs||}|tkrtS| Sr;)r[r`)r!rXZequalr&r&r'__ne__s zTimerHandle.__ne__cs |js|j|tdSr;)rr_timer_handle_cancelledrNr:r9rPr&r'r:s zTimerHandle.cancelcCs|jS)zReturn a scheduled callback time. The time is an absolute timestamp, using the same time reference as loop.time(). rVr9r&r&r'rOszTimerHandle.when)N)r-rGrHrIrJr(r2rUrYr\r]r^r[rar:rO __classcell__r&r&rPr'rcs  rc@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)rz,Abstract server returned by create_server().cCstdS)z5Stop serving. This leaves existing connections open.NNotImplementedErrorr9r&r&r'closeszAbstractServer.closecCstdS)z4Get the event loop the Server object is attached to.Nrdr9r&r&r'get_loopszAbstractServer.get_loopcCstdS)z3Return True if the server is accepting connections.Nrdr9r&r&r' is_servingszAbstractServer.is_servingcstdS)zStart accepting connections. This method is idempotent, so it can be called when the server is already being serving. Nrdr9r&r&r' start_servingszAbstractServer.start_servingcstdS)zStart accepting connections until the coroutine is cancelled. The server is closed when the coroutine is cancelled. Nrdr9r&r&r' serve_foreverszAbstractServer.serve_forevercstdS)z*Coroutine to wait until service is closed.Nrdr9r&r&r' wait_closedszAbstractServer.wait_closedcs|Sr;r&r9r&r&r' __aenter__szAbstractServer.__aenter__cs||IdHdSr;)rfrk)r!rCr&r&r' __aexit__szAbstractServer.__aexit__N) r-rGrHrIrfrgrhrirjrkrlrmr&r&r&r'rsrc @sVeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddddZd d!Zd"d#Zd$d%Zd&d&d&d&d'd(d)Zdud*d+Zdvdd&d&d&ddddddd, d-d.Zdwejejdd/ddddd0d1 d2d3Zdxd0d4d5d6Zd7ddd8d9d:Zdyddddd;dd?d@Zd{d&d&d&dddddAdBdCZ dDdEZ!dFdGZ"e#j$e#j$e#j$dHdIdJZ%e#j$e#j$e#j$dHdKdLZ&dMdNZ'dOdPZ(dQdRZ)dSdTZ*dUdVZ+dWdXZ,dYdZZ-d[d\Z.d]d^Z/d|dd4d_d`Z0dadbZ1dcddZ2dedfZ3dgdhZ4didjZ5dkdlZ6dmdnZ7dodpZ8dqdrZ9dsdtZ:dS)}rzAbstract event loop.cCstdS)z*Run the event loop until stop() is called.Nrdr9r&r&r' run_foreverszAbstractEventLoop.run_forevercCstdS)zpRun the event loop until a Future is done. Return the Future's result, or raise its exception. Nrd)r!Zfuturer&r&r'run_until_completesz$AbstractEventLoop.run_until_completecCstdS)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. Nrdr9r&r&r'stopszAbstractEventLoop.stopcCstdS)z3Return whether the event loop is currently running.Nrdr9r&r&r' is_runningszAbstractEventLoop.is_runningcCstdS)z*Returns True if the event loop was closed.Nrdr9r&r&r' is_closedszAbstractEventLoop.is_closedcCstdS)zClose the loop. The loop should not be running. This is idempotent and irreversible. No other methods should be called after this one. Nrdr9r&r&r'rfs zAbstractEventLoop.closecstdS)z,Shutdown all active asynchronous generators.Nrdr9r&r&r'shutdown_asyncgenssz$AbstractEventLoop.shutdown_asyncgenscCstdS)z3Notification that a TimerHandle has been cancelled.Nrd)r!r=r&r&r'rbsz)AbstractEventLoop._timer_handle_cancelledcGs|jd|f|S)Nr) call_laterr!r"r#r&r&r' call_soonszAbstractEventLoop.call_sooncGstdSr;rd)r!Zdelayr"r#r&r&r'rtszAbstractEventLoop.call_latercGstdSr;rd)r!rOr"r#r&r&r'call_atszAbstractEventLoop.call_atcCstdSr;rdr9r&r&r'time szAbstractEventLoop.timecCstdSr;rdr9r&r&r' create_futureszAbstractEventLoop.create_futureN)namecCstdSr;rd)r!cororzr&r&r' create_taskszAbstractEventLoop.create_taskcGstdSr;rdrur&r&r'call_soon_threadsafesz&AbstractEventLoop.call_soon_threadsafecGstdSr;rd)r!executorfuncr#r&r&r'run_in_executorsz!AbstractEventLoop.run_in_executorcCstdSr;rd)r!r~r&r&r'set_default_executorsz&AbstractEventLoop.set_default_executorr)familytypeprotoflagscstdSr;rd)r!hostportrrrrr&r&r' getaddrinfo#szAbstractEventLoop.getaddrinfocstdSr;rd)r!Zsockaddrrr&r&r' getnameinfo'szAbstractEventLoop.getnameinfo) sslrrrsock local_addrserver_hostnamessl_handshake_timeouthappy_eyeballs_delay interleavec stdSr;rd)r!protocol_factoryrrrrrrrrrrrrr&r&r'create_connection*sz#AbstractEventLoop.create_connectiondT) rrrbacklogr reuse_address reuse_portrric stdS)adA 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. 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. Nrd) r!rrrrrrrrrrrrir&r&r' create_server3s3zAbstractEventLoop.create_server)fallbackcstdS)zRSend a file through a transport. Return an amount of sent bytes. Nrd)r! transportfileoffsetcountrr&r&r'sendfilehszAbstractEventLoop.sendfileF) server_siderrcstdS)z|Upgrade a transport to TLS. Return a new transport that *protocol* should start using immediately. Nrd)r!rZprotocolZ sslcontextrrrr&r&r' start_tlsps zAbstractEventLoop.start_tls)rrrrcstdSr;rd)r!rpathrrrrr&r&r'create_unix_connection{sz(AbstractEventLoop.create_unix_connection)rrrrricstdS)aA 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 systsem 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). 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. Nrd)r!rrrrrrrir&r&r'create_unix_serversz$AbstractEventLoop.create_unix_server)rrrrrallow_broadcastrc stdS)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. Nrd) r!rrZ remote_addrrrrrrrrr&r&r'create_datagram_endpoints!z*AbstractEventLoop.create_datagram_endpointcstdS)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.Nrdr!rpiper&r&r'connect_read_pipes z#AbstractEventLoop.connect_read_pipecstdS)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.Nrdrr&r&r'connect_write_pipes z$AbstractEventLoop.connect_write_pipe)stdinstdoutstderrcstdSr;rd)r!rcmdrrrkwargsr&r&r'subprocess_shellsz"AbstractEventLoop.subprocess_shellcstdSr;rd)r!rrrrr#rr&r&r'subprocess_execsz!AbstractEventLoop.subprocess_execcGstdSr;rdr!fdr"r#r&r&r' add_readerszAbstractEventLoop.add_readercCstdSr;rdr!rr&r&r' remove_readerszAbstractEventLoop.remove_readercGstdSr;rdrr&r&r' add_writerszAbstractEventLoop.add_writercCstdSr;rdrr&r&r' remove_writerszAbstractEventLoop.remove_writercstdSr;rd)r!rnbytesr&r&r' sock_recvszAbstractEventLoop.sock_recvcstdSr;rd)r!rZbufr&r&r'sock_recv_intosz AbstractEventLoop.sock_recv_intocstdSr;rd)r!rdatar&r&r' sock_sendallszAbstractEventLoop.sock_sendallcstdSr;rd)r!rZaddressr&r&r' sock_connect szAbstractEventLoop.sock_connectcstdSr;rd)r!rr&r&r' sock_acceptszAbstractEventLoop.sock_acceptcstdSr;rd)r!rrrrrr&r&r' sock_sendfileszAbstractEventLoop.sock_sendfilecGstdSr;rd)r!sigr"r#r&r&r'add_signal_handlersz$AbstractEventLoop.add_signal_handlercCstdSr;rd)r!rr&r&r'remove_signal_handlersz'AbstractEventLoop.remove_signal_handlercCstdSr;rd)r!factoryr&r&r'set_task_factorysz"AbstractEventLoop.set_task_factorycCstdSr;rdr9r&r&r'get_task_factory"sz"AbstractEventLoop.get_task_factorycCstdSr;rdr9r&r&r'get_exception_handler'sz'AbstractEventLoop.get_exception_handlercCstdSr;rd)r!Zhandlerr&r&r'set_exception_handler*sz'AbstractEventLoop.set_exception_handlercCstdSr;rdr!r%r&r&r'default_exception_handler-sz+AbstractEventLoop.default_exception_handlercCstdSr;rdrr&r&r'rB0sz(AbstractEventLoop.call_exception_handlercCstdSr;rdr9r&r&r'r5szAbstractEventLoop.get_debugcCstdSr;rd)r!Zenabledr&r&r' set_debug8szAbstractEventLoop.set_debug)r)NN)NN)rN)N)N)NN)rN);r-rGrHrIrnrorprqrrrfrsrbrvrtrwrxryr|r}rrrrrsocketZ AF_UNSPECZ AI_PASSIVErrrrrrrr subprocessPIPErrrrrrrrrrrrrrrrrrrrBrrr&r&r&r'rs     5    ! %    rc@s8eZdZdZddZddZddZdd Zd d Zd S) rz-Abstract policy for accessing the event loop.cCstdS)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.Nrdr9r&r&r'r?sz&AbstractEventLoopPolicy.get_event_loopcCstdS)z3Set the event loop for the current context to loop.Nrdr!r$r&r&r'r Isz&AbstractEventLoopPolicy.set_event_loopcCstdS)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.Nrdr9r&r&r'r Msz&AbstractEventLoopPolicy.new_event_loopcCstdS)z$Get the watcher for child processes.Nrdr9r&r&r'r Usz)AbstractEventLoopPolicy.get_child_watchercCstdS)z$Set the watcher for child processes.Nrd)r!watcherr&r&r'r Ysz)AbstractEventLoopPolicy.set_child_watcherN) r-rGrHrIrr r r r r&r&r&r'r<s  rc@sFeZdZdZdZGdddejZddZddZ d d Z d d Z 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). Nc@seZdZdZdZdS)z!BaseDefaultEventLoopPolicy._LocalNF)r-rGrHr _set_calledr&r&r&r'_LocalmsrcCs||_dSr;)r_localr9r&r&r'r(qsz#BaseDefaultEventLoopPolicy.__init__cCsX|jjdkr2|jjs2tttjr2|||jjdkrPt dtj |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.) rrrr_ threadingZcurrent_threadZ _MainThreadr r RuntimeErrorrzr9r&r&r'rts  z)BaseDefaultEventLoopPolicy.get_event_loopcCs*d|j_|dkst|tst||j_dS)zSet the event loop.TN)rrr_rrMrrr&r&r'r sz)BaseDefaultEventLoopPolicy.set_event_loopcCs|S)zvCreate a new event loop. You must call set_event_loop() to make this the current event loop. ) _loop_factoryr9r&r&r'r sz)BaseDefaultEventLoopPolicy.new_event_loop) r-rGrHrIrrlocalrr(rr r r&r&r&r'r^s rc@seZdZdZdS) _RunningLoop)NNN)r-rGrHloop_pidr&r&r&r'rsrcCst}|dkrtd|S)zrReturn the running event loop. Raise a RuntimeError if there is none. This function is thread-specific. Nzno running event loop)rrr$r&r&r'rsrcCs&tj\}}|dk r"|tkr"|SdS)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_looprosgetpid)Z running_looppidr&r&r'rs rcCs|tft_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)rrrrrr&r&r'r sr c Cs.t tdkr ddlm}|aW5QRXdS)NrDefaultEventLoopPolicy)_lock_event_loop_policyrrr&r&r'_init_event_loop_policys rcCstdkrttS)z"Get the current event loop policy.N)rrr&r&r&r'rsrcCs|dkst|tst|adS)zZSet the current event loop policy. If policy is None, the default policy is restored.N)r_rrMr)Zpolicyr&r&r'rsrcCst}|dk r|StS)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. N)rrr)Z current_loopr&r&r'rs rcCst|dS)zCEquivalent to calling get_event_loop_policy().set_event_loop(loop).N)rr rr&r&r'r sr cCs tS)z?Equivalent to calling get_event_loop_policy().new_event_loop().)rr r&r&r&r'r sr cCs tS)zBEquivalent to calling get_event_loop_policy().get_child_watcher().)rr r&r&r&r'r sr cCs t|S)zMEquivalent to calling get_event_loop_policy().set_child_watcher(watcher).)rr )rr&r&r'r sr )rr rr),rI__all__rrrrrrrrrrrrrrrrZLockrrrrrrr rrrrr r r r Z_py__get_running_loopZ_py__set_running_loopZ_py_get_running_loopZ_py_get_event_loopZ_asyncio ImportErrorZ_c__get_running_loopZ_c__set_running_loopZ_c_get_running_loopZ_c_get_event_loopr&r&r&r'sX   J@*q"9