B -_If@sdZdZddlZddlZddlZddlZddlZddlZddlm Z Gddde Z Gdd d Z Gd d d e Z Gd d d ZGdddZGdddZGdddeZdaeZGdddejZeZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Z d(d)Z!d*d+Z"eZ#eZ$eZ%eZ&ydd,l'mZmZmZmZWne(k rjYnXeZ)eZ*eZ+eZ,dS)-z!Event loop and event loop policy.)AbstractEventLoopPolicyAbstractEventLoopAbstractServerHandle TimerHandleSendfileNotAvailableErrorget_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@seZdZdZdS)rz~Sendfile syscall is not available. Raised if OS does not support sendfile syscall for given socket or file type. N)__name__ __module__ __qualname____doc__rr$/usr/lib/python3.7/asyncio/events.pyrsrc@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_contextr!rrrrr get_debugr extract_stacksys _getframer)selfcallbackargsloopcontextrrr__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__rrappendrr_format_callback_sourcerr)r'infoframerrr _repr_info6s    zHandle._repr_infocCs(|jdk r|jS|}dd|S)Nz<{}> )rr5formatjoin)r'r3rrr__repr__Bs zHandle.__repr__cCs0|js,d|_|jr t||_d|_d|_dS)NT)rrr#reprrrr)r'rrrcancelHs   z Handle.cancelcCs|jS)N)r)r'rrrr-SszHandle.cancelledc Csy|jj|jf|jWndtk r~}zFt|j|j}d|}|||d}|jrb|j|d<|j |Wdd}~XYnXd}dS)NzException in callback )messageZ exceptionhandleZsource_traceback) r!runrr Exceptionrr2rrcall_exception_handler)r'exccbmsgr+rrr_runVs   z Handle._run)N) rrrr __slots__r,r5r9r;r-rDrrrrr s   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,rrGrF)r'whenr(r)r*r+)r0rrr,ms  zTimerHandle.__init__cs0t}|jrdnd}||d|j|S)Nrzwhen=)rIr5rinsertrG)r'r3pos)r0rrr5us zTimerHandle._repr_infocCs t|jS)N)hashrG)r'rrr__hash__{szTimerHandle.__hash__cCs |j|jkS)N)rG)r'otherrrr__lt__~szTimerHandle.__lt__cCs|j|jkrdS||S)NT)rG__eq__)r'rPrrr__le__s zTimerHandle.__le__cCs |j|jkS)N)rG)r'rPrrr__gt__szTimerHandle.__gt__cCs|j|jkrdS||S)NT)rGrR)r'rPrrr__ge__s zTimerHandle.__ge__cCs>t|tr:|j|jko8|j|jko8|j|jko8|j|jkStS)N) isinstancerrGrrrNotImplemented)r'rPrrrrRs      zTimerHandle.__eq__cCs||}|tkrtS| S)N)rRrW)r'rPZequalrrr__ne__s zTimerHandle.__ne__cs |js|j|tdS)N)rr_timer_handle_cancelledrIr;)r')r0rrr;s zTimerHandle.cancelcCs|jS)zReturn a scheduled callback time. The time is an absolute timestamp, using the same time reference as loop.time(). )rG)r'rrrrJszTimerHandle.when)N)rrrrrEr,r5rOrQrSrTrUrRrXr;rJ __classcell__rr)r0rrhs  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.N)NotImplementedError)r'rrrcloseszAbstractServer.closecCstdS)z4Get the event loop the Server object is attached to.N)r[)r'rrrget_loopszAbstractServer.get_loopcCstdS)z3Return True if the server is accepting connections.N)r[)r'rrr is_servingszAbstractServer.is_servingcstdS)zStart accepting connections. This method is idempotent, so it can be called when the server is already being serving. N)r[)r'rrr start_servingszAbstractServer.start_servingcstdS)zStart accepting connections until the coroutine is cancelled. The server is closed when the coroutine is cancelled. N)r[)r'rrr serve_foreverszAbstractServer.serve_forevercstdS)z*Coroutine to wait until service is closed.N)r[)r'rrr wait_closedszAbstractServer.wait_closedcs|S)Nr)r'rrr __aenter__szAbstractServer.__aenter__cs||IdHdS)N)r\ra)r'rArrr __aexit__szAbstractServer.__aexit__N) rrrrr\r]r^r_r`rarbrcrrrrrsrc @sLeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d$d$d$d%d&d'Zdtd(d)Zdud*d$d$d$d*d*d*d*d+d,d-Zdvejejd*d.d*d*d*d*d/d0 d1d2Zdwd/d3d4d5Zd6d*d*d7d8d9Zdxd*d*d*d*d:d;d<Zdyd*d.d*d*d/d=d>d?Zdzd$d$d$d*d*d*d*d@dAdBZ dCdDZ!dEdFZ"e#j$e#j$e#j$dGdHdIZ%e#j$e#j$e#j$dGdJdKZ&dLdMZ'dNdOZ(dPdQZ)dRdSZ*dTdUZ+dVdWZ,dXdYZ-dZd[Z.d\d]Z/d{d*d3d^d_Z0d`daZ1dbdcZ2dddeZ3dfdgZ4dhdiZ5djdkZ6dldmZ7dndoZ8dpdqZ9drdsZ:d*S)|rzAbstract event loop.cCstdS)z*Run the event loop until stop() is called.N)r[)r'rrr run_foreverszAbstractEventLoop.run_forevercCstdS)zpRun the event loop until a Future is done. Return the Future's result, or raise its exception. N)r[)r'Zfuturerrrrun_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. N)r[)r'rrrstopszAbstractEventLoop.stopcCstdS)z3Return whether the event loop is currently running.N)r[)r'rrr is_runningszAbstractEventLoop.is_runningcCstdS)z*Returns True if the event loop was closed.N)r[)r'rrr 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. N)r[)r'rrrr\s zAbstractEventLoop.closecstdS)z,Shutdown all active asynchronous generators.N)r[)r'rrrshutdown_asyncgenssz$AbstractEventLoop.shutdown_asyncgenscCstdS)z3Notification that a TimerHandle has been cancelled.N)r[)r'r=rrrrYsz)AbstractEventLoop._timer_handle_cancelledcGs|jd|f|S)Nr) call_later)r'r(r)rrr call_soonszAbstractEventLoop.call_sooncGstdS)N)r[)r'Zdelayr(r)rrrrj szAbstractEventLoop.call_latercGstdS)N)r[)r'rJr(r)rrrcall_at szAbstractEventLoop.call_atcCstdS)N)r[)r'rrrtimeszAbstractEventLoop.timecCstdS)N)r[)r'rrr create_futureszAbstractEventLoop.create_futurecCstdS)N)r[)r'cororrr create_taskszAbstractEventLoop.create_taskcGstdS)N)r[)r'r(r)rrrcall_soon_threadsafesz&AbstractEventLoop.call_soon_threadsafecstdS)N)r[)r'executorfuncr)rrrrun_in_executor sz!AbstractEventLoop.run_in_executorcCstdS)N)r[)r'rrrrrset_default_executor#sz&AbstractEventLoop.set_default_executorr)familytypeprotoflagscstdS)N)r[)r'hostportrvrwrxryrrr getaddrinfo(szAbstractEventLoop.getaddrinfocstdS)N)r[)r'Zsockaddrryrrr getnameinfo,szAbstractEventLoop.getnameinfoN)sslrvrxrysock local_addrserver_hostnamessl_handshake_timeoutc stdS)N)r[) r'protocol_factoryrzr{r~rvrxryrrrrrrrcreate_connection/sz#AbstractEventLoop.create_connectiondT) rvryrbacklogr~ reuse_address reuse_portrr_c 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. N)r[) r'rrzr{rvryrrr~rrrr_rrr create_server7s3zAbstractEventLoop.create_server)fallbackcstdS)zRSend a file through a transport. Return an amount of sent bytes. N)r[)r' transportfileoffsetcountrrrrsendfilelszAbstractEventLoop.sendfileF) server_siderrcstdS)z|Upgrade a transport to TLS. Return a new transport that *protocol* should start using immediately. N)r[)r'rZprotocolZ sslcontextrrrrrr start_tlsts zAbstractEventLoop.start_tls)r~rrrcstdS)N)r[)r'rpathr~rrrrrrcreate_unix_connectionsz(AbstractEventLoop.create_unix_connection)rrr~rr_cstdS)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. N)r[)r'rrrrr~rr_rrrcreate_unix_serversz$AbstractEventLoop.create_unix_server)rvrxryrrallow_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. N)r[) r'rrZ remote_addrrvrxryrrrrrrrcreate_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.N)r[)r'rpiperrrconnect_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.N)r[)r'rrrrrconnect_write_pipes z$AbstractEventLoop.connect_write_pipe)stdinstdoutstderrcstdS)N)r[)r'rcmdrrrkwargsrrrsubprocess_shellsz"AbstractEventLoop.subprocess_shellcstdS)N)r[)r'rrrrr)rrrrsubprocess_execsz!AbstractEventLoop.subprocess_execcGstdS)N)r[)r'fdr(r)rrr add_readerszAbstractEventLoop.add_readercCstdS)N)r[)r'rrrr remove_readerszAbstractEventLoop.remove_readercGstdS)N)r[)r'rr(r)rrr add_writerszAbstractEventLoop.add_writercCstdS)N)r[)r'rrrr remove_writerszAbstractEventLoop.remove_writercstdS)N)r[)r'rnbytesrrr sock_recvszAbstractEventLoop.sock_recvcstdS)N)r[)r'rZbufrrrsock_recv_into sz AbstractEventLoop.sock_recv_intocstdS)N)r[)r'rdatarrr sock_sendall szAbstractEventLoop.sock_sendallcstdS)N)r[)r'rZaddressrrr sock_connectszAbstractEventLoop.sock_connectcstdS)N)r[)r'rrrr sock_acceptszAbstractEventLoop.sock_acceptcstdS)N)r[)r'rrrrrrrr sock_sendfileszAbstractEventLoop.sock_sendfilecGstdS)N)r[)r'sigr(r)rrradd_signal_handlersz$AbstractEventLoop.add_signal_handlercCstdS)N)r[)r'rrrrremove_signal_handlersz'AbstractEventLoop.remove_signal_handlercCstdS)N)r[)r'factoryrrrset_task_factory#sz"AbstractEventLoop.set_task_factorycCstdS)N)r[)r'rrrget_task_factory&sz"AbstractEventLoop.get_task_factorycCstdS)N)r[)r'rrrget_exception_handler+sz'AbstractEventLoop.get_exception_handlercCstdS)N)r[)r'Zhandlerrrrset_exception_handler.sz'AbstractEventLoop.set_exception_handlercCstdS)N)r[)r'r+rrrdefault_exception_handler1sz+AbstractEventLoop.default_exception_handlercCstdS)N)r[)r'r+rrrr@4sz(AbstractEventLoop.call_exception_handlercCstdS)N)r[)r'rrrr#9szAbstractEventLoop.get_debugcCstdS)N)r[)r'Zenabledrrr set_debug<szAbstractEventLoop.set_debug)r)NN)NN)rN)N)N)NN)rN);rrrrrdrerfrgrhr\rirYrkrjrlrmrnrprqrtrur|r}rsocketZ AF_UNSPECZ AI_PASSIVErrrrrrrr subprocessPIPErrrrrrrrrrrrrrrrrrrr@r#rrrrrrs  / !  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.N)r[)r'rrrr Csz&AbstractEventLoopPolicy.get_event_loopcCstdS)z3Set the event loop for the current context to loop.N)r[)r'r*rrrr Msz&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.N)r[)r'rrrr Qsz&AbstractEventLoopPolicy.new_event_loopcCstdS)z$Get the watcher for child processes.N)r[)r'rrrr Ysz)AbstractEventLoopPolicy.get_child_watchercCstdS)z$Set the watcher for child processes.N)r[)r'watcherrrrr ]sz)AbstractEventLoopPolicy.set_child_watcherN) rrrrr r r r r rrrrr@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)rrrr _set_calledrrrr_LocalqsrcCs||_dS)N)r_local)r'rrrr,usz#BaseDefaultEventLoopPolicy.__init__cCsX|jjdkr2|jjs2tttjr2|||jjdkrPt dtj |jjS)zSGet the event loop. This may be None or an instance of EventLoop. Nz,There is no current event loop in thread %r.) rrrrV threadingZcurrent_threadZ _MainThreadr r RuntimeErrorname)r'rrrr xs  z)BaseDefaultEventLoopPolicy.get_event_loopcCs*d|j_|dkst|tst||j_dS)zSet the event loop.TN)rrrVrrHr)r'r*rrrr 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_factory)r'rrrr sz)BaseDefaultEventLoopPolicy.new_event_loop) rrrrrrlocalrr,r r r rrrrrbs rc@seZdZdZdS) _RunningLoop)NNN)rrrloop_pidrrrrrsrcCst}|dkrtd|S)zrReturn the running event loop. Raise a RuntimeError if there is none. This function is thread-specific. Nzno running event loop)rr)r*rrrrsrcCs&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_looppidrrrrs 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)rrrr)r*rrrrsrc Cs.t tdkr ddlm}|aWdQRXdS)Nr)DefaultEventLoopPolicy)_lock_event_loop_policyr)rrrr_init_event_loop_policys rcCstdkrttS)z"Get the current event loop policy.N)rrrrrrrsrcCs|dkst|tst|adS)zZSet the current event loop policy. If policy is None, the default policy is restored.N)rVrrHr)ZpolicyrrrrsrcCst}|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_looprrrr s r cCst|dS)zCEquivalent to calling get_event_loop_policy().set_event_loop(loop).N)rr )r*rrrr sr cCs tS)z?Equivalent to calling get_event_loop_policy().new_event_loop().)rr rrrrr sr cCs tS)zBEquivalent to calling get_event_loop_policy().get_child_watcher().)rr rrrrr sr cCs t|S)zMEquivalent to calling get_event_loop_policy().set_child_watcher(watcher).)rr )rrrrr sr )rrrr )-r__all__r"rrrr%rrrrrrrrrrrrZLockrrrrrrrrrrr r 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_looprrrrsX  H@*p"9