a DOg!@sdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZz ddlZWneydZYn0ddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddl m!Z!dZ"dZ#dZ$e%e dZ&dZ'e(Z)ddZ*ddZ+ddZ,d-ddZ-d.ddZ.dd Z/e%e d!rd"d#Z0nd$d#Z0d%d&Z1Gd'd(d(ej2Z3Gd)d*d*ej4Z5Gd+d,d,ej6Z7dS)/aBase 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) transports)trsock)logger) BaseEventLoopServerdg?AF_INET6iQcCs0|j}tt|ddtjr$t|jSt|SdS)N__self__)Z _callback isinstancegetattrr Taskreprrstr)handlecbr8/opt/alt/python39/lib64/python3.9/asyncio/base_events.py_format_handleJs rcCs(|tjkrdS|tjkrdSt|SdS)Nzz) subprocessPIPESTDOUTr)fdrrr _format_pipeSs   r"cCsJttdstdn2z|tjtjdWntyDtdYn0dS)N SO_REUSEPORTz)reuse_port not supported by socket modulerzTreuse_port not supported by socket module, SO_REUSEPORT defined but not implemented.)hasattrsocket ValueError setsockopt SOL_SOCKETr#OSErrorsockrrr_set_reuseport\s    r,c CsttdsdS|dtjtjhvs(|dur,dS|tjkr>tj}n|tjkrPtj}ndS|durbd}nVt|trz|dkrzd}n>t|tr|dkrd}n&z t |}Wnt t fyYdS0|tj krtj g}tr|tjn|g}t|tr|d}d|vrdS|D]r}zVt||trH|tjkrH|||d||||ffWS|||d||ffWSWntyvYn0qdS)N inet_ptonrZidna%)r$r% IPPROTO_TCPZ IPPROTO_UDP SOCK_STREAM SOCK_DGRAMrbytesrint TypeErrorr& AF_UNSPECAF_INET _HAS_IPv6appendrdecoder-r)) hostportfamilytypeprotoZflowinfoZscopeidZafsafrrr _ipaddr_infogsN          rBcCst}|D]*}|d}||vr(g||<|||q t|}g}|dkr|||dd|d|dd|d=|ddtjtj |D|S)z-Interleave list of addrinfo tuples by family.rrNcss|]}|dur|VqdSNr).0arrr sz(_interleave_addrinfos..) collections OrderedDictr:listvaluesextend itertoolschain from_iterable zip_longest)Z addrinfosZfirst_address_family_countZaddrinfos_by_familyaddrr>Zaddrinfos_listsZ reorderedrrr_interleave_addrinfoss"  rQcCs4|s"|}t|ttfr"dSt|dSrC) cancelled exceptionr SystemExitKeyboardInterruptrZ _get_loopstop)futexcrrr_run_until_complete_cbs rY TCP_NODELAYcCs@|jtjtjhvr<|jtjkr<|jtjkr<|tjtj ddSNr) r>r%r8rr?r2r@r1r'rZr*rrr _set_nodelays   r\cCsdSrCrr*rrrr\scCs tdurt|tjrtddS)Nz"Socket cannot be of type SSLSocket)sslrZ SSLSocketr6r*rrr_check_ssl_socketsr^c@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)_SendfileFallbackProtocolcCsht|tjstd||_||_||_|j |_ | | ||j r^|jj |_nd|_dS)Nz.transport should be _FlowControlMixin instance)rr Z_FlowControlMixinr6 _transportZ get_protocol_protoZ is_reading_should_resume_readingZ_protocol_paused_should_resume_writing pause_reading set_protocol_loop create_future_write_ready_fut)selftransprrr__init__s    z"_SendfileFallbackProtocol.__init__cs2|jrtd|j}|dur$dS|IdHdS)NzConnection closed by peer)r` is_closingConnectionErrorrh)rirWrrrdrains  z_SendfileFallbackProtocol.draincCs tddS)Nz?Invalid state: connection should have been established already. RuntimeError)ri transportrrrconnection_madesz)_SendfileFallbackProtocol.connection_madecCs@|jdur0|dur$|jtdn |j||j|dS)NzConnection is closed by peer)rh set_exceptionrmraconnection_lost)rirXrrrrts  z)_SendfileFallbackProtocol.connection_lostcCs |jdurdS|jj|_dSrC)rhr`rfrgrirrr pause_writings z'_SendfileFallbackProtocol.pause_writingcCs$|jdurdS|jdd|_dS)NF)rh set_resultrurrrresume_writings  z(_SendfileFallbackProtocol.resume_writingcCs tddSNz'Invalid state: reading should be pausedro)ridatarrr data_receivedsz'_SendfileFallbackProtocol.data_receivedcCs tddSryrorurrr eof_receivedsz&_SendfileFallbackProtocol.eof_receivedcsF|j|j|jr|j|jdur2|j|jrB|jdSrC) r`rerarbresume_readingrhcancelrcrxrurrrrestore s   z!_SendfileFallbackProtocol.restoreN) __name__ __module__ __qualname__rkrnrrrtrvrxr{r|rrrrrr_s r_c@sxeZdZddZddZddZddZd d Zd d Zd dZ ddZ e ddZ ddZ ddZddZddZdS)rcCs@||_||_d|_g|_||_||_||_||_d|_d|_ dS)NrF) rf_sockets _active_count_waiters_protocol_factory_backlog _ssl_context_ssl_handshake_timeout_serving_serving_forever_fut)riloopsocketsprotocol_factoryZ ssl_contextbacklogssl_handshake_timeoutrrrrkszServer.__init__cCsd|jjd|jdS)N) __class__rrrurrr__repr__%szServer.__repr__cCs|jd7_dSr[)rrurrr_attach(szServer._attachcCs.|jd8_|jdkr*|jdur*|dS)Nrr)rr_wakeuprurrr_detach,szServer._detachcCs,|j}d|_|D]}|s||qdSrC)rdonerw)riwaiterswaiterrrrr2s zServer._wakeupc CsJ|jr dSd|_|jD].}||j|j|j||j||j|jqdS)NT) rrZlistenrrf_start_servingrrr)rir+rrrr9s    zServer._start_servingcCs|jSrC)rfrurrrget_loopCszServer.get_loopcCs|jSrC)rrurrr is_servingFszServer.is_servingcCs"|jdurdStdd|jDS)Nrcss|]}t|VqdSrC)r ZTransportSocket)rDsrrrrFMr.z!Server.sockets..)rtuplerurrrrIs zServer.socketscCsn|j}|durdSd|_|D]}|j|qd|_|jdurX|jsX|jd|_|jdkrj|dS)NFr) rrfZ _stop_servingrrrr~rr)rirr+rrrcloseOs   z Server.closecs|tdIdHdS)Nr)rr sleeprurrr start_servingbszServer.start_servingc s|jdurtd|d|jdur4td|d||j|_zRz|jIdHWn6tjyz|| IdHWn0Yn0Wd|_nd|_0dS)Nzserver z, is already being awaited on serve_forever()z is closed) rrprrrfrgrZCancelledErrorr wait_closedrurrr serve_foreverhs     zServer.serve_forevercs<|jdus|jdurdS|j}|j||IdHdSrC)rrrfrgr:)rirrrrr}s   zServer.wait_closedN)rrrrkrrrrrrrpropertyrrrrrrrrrrs   rc @sheZdZddZddZddZddd d Zd d Zd dZddddddZ ddddddddddZ dddZ dddZ dddZ dddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zejfd=d>Z d?d@Z!dAdBZ"ddCdDdEZ#ddCdFdGZ$ddCdHdIZ%dJdKZ&dLdMZ'dNdOZ(ddCdPdQZ)dRdSZ*dTdUZ+dVdWZ,dXdXdXdXdYdZd[Z-dd\d]Z.ddd^d_d`Z/dadbZ0dcddZ1dedfZ2ddgdhZ3dddXdXdXdddddddi djdkZ4ddldmZ5ddd^dndoZ6dpdqZ7drdsZ8ddddtdudvZ9ddXdXdXe:ddddwdxdyZ;dXed|d}Z?de$r.z4BaseEventLoop.shutdown_asyncgens..)Zreturn_exceptionsrz;an error occurred during closing of asynchronous generator )messagerSZasyncgen) rlenrrIclearr _gatherzipr Exceptioncall_exception_handler)riZ closing_agensZresultsresultrrrrshutdown_asyncgenss&     z BaseEventLoop.shutdown_asyncgenscs\d|_|jdurdS|}tj|j|fd}|z|IdHW|n |0dS)z.Schedule the shutdown of the default executor.TN)targetr)rrrg threadingZThread _do_shutdownstartjoin)rifuturethreadrrrshutdown_default_executor1s  z'BaseEventLoop.shutdown_default_executorc CsXz |jjdd||jdWn2tyR}z||j|WYd}~n d}~00dS)NTwait)rshutdownrrwrrs)rirZexrrrr>s zBaseEventLoop._do_shutdowncCs(|rtdtdur$tddS)Nz"This event loop is already runningz7Cannot run the event loop while another loop is running)rrprZ_get_running_looprurrr_check_runningEs  zBaseEventLoop._check_runningc Cs||||jt|_t}tj |j |j dzJt |||jrLq^qLWd|_d|_t d|dtj |n,d|_d|_t d|dtj |0dS)zRun until stop() is called.) firstiter finalizerFN)rr _set_coroutine_origin_tracking_debugr get_identrsysget_asyncgen_hooksset_asyncgen_hooksrrrZ_set_running_loop _run_oncer)riZold_agen_hooksrrr run_foreverLs.        zBaseEventLoop.run_foreverc Cs||t| }tj||d}|r4d|_|tzFz | Wn*|rp| rp| sp| Yn0W| tn | t0| std|S)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. rFz+Event loop stopped before Future completed.)rr rZisfuturer Z ensure_futureZ_log_destroy_pendingZadd_done_callbackrYrrrRrSZremove_done_callbackrpr)rirZnew_taskrrrrun_until_completecs"     z BaseEventLoop.run_until_completecCs d|_dS)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)rrurrrrVszBaseEventLoop.stopcCsp|rtd|jrdS|jr,td|d|_|j|jd|_ |j }|durld|_ |j dddS)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 loopNzClose %rTFr) rrprrrdebugrrrrrr riexecutorrrrrs   zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)rrurrrrszBaseEventLoop.is_closedcCs0|s,|d|t|d|s,|dS)Nzunclosed event loop r)rrrr)riZ_warnrrr__del__szBaseEventLoop.__del__cCs |jduS)z*Returns True if the event loop is running.N)rrurrrrszBaseEventLoop.is_runningcCstS)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. )rrrurrrrszBaseEventLoop.time)contextcGs4|j|||g|Rd|i}|jr0|jd=|S)a8Arrange 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 undefined which will be called first. Any positional arguments after the callback will be passed to the callback when it is called. rr)call_atrr)riZdelaycallbackrrtimerrrr call_laters zBaseEventLoop.call_latercGsZ||jr"|||dt|||||}|jrB|jd=t|j |d|_ |S)z|Like call_later(), but uses an absolute time. Absolute time corresponds to the event loop's time() method. rrT) rr _check_thread_check_callbackrZ TimerHandlerheapqheappushr)riwhenrrrrrrrrs zBaseEventLoop.call_atcGsB||jr"|||d||||}|jr>|jd=|S)aTArrange for a callback to be called as soon as possible. This operates as a FIFO queue: callbacks are called in the order in which they are registered. Each callback will be called exactly once. Any positional arguments after the callback will be passed to the callback when it is called. call_soonr)rrrr  _call_soonrrirrrrrrrr$s  zBaseEventLoop.call_sooncCsDt|st|r$td|dt|s@td|d|dS)Nzcoroutines cannot be used with z()z"a callable object was expected by z(), got )rZ iscoroutineZiscoroutinefunctionr6r)rirmethodrrrr s  zBaseEventLoop._check_callbackcCs.t||||}|jr|jd=|j||S)Nr)rZHandlerrr:)rirrrrrrrr%s  zBaseEventLoop._call_sooncCs,|jdurdSt}||jkr(tddS)aoCheck 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)rrrrp)riZ thread_idrrrr s  zBaseEventLoop._check_threadcGsB||jr||d||||}|jr6|jd=||S)z"Like call_soon(), but thread-safe.rr)rrr r%rrr&rrrrs z"BaseEventLoop.call_soon_threadsafecGsh||jr||d|durL|j}||durLtjjdd}||_tj|j |g|R|dS)Nrun_in_executorZasyncio)Zthread_name_prefixr) rrr rr concurrentrThreadPoolExecutorZ wrap_futureZsubmit)rirfuncrrrrr(%s zBaseEventLoop.run_in_executorcCs&t|tjjstdtd||_dS)Nz{Using the default executor that is not an instance of ThreadPoolExecutor is deprecated and will be prohibited in Python 3.9)rr)rr*rrDeprecationWarningrrrrrset_default_executor5s z"BaseEventLoop.set_default_executorc Cs|d|g}|r$|d||r8|d||rL|d||r`|d|d|}td||}t||||||} ||} d|d | d d d | }| |jkrt|n t|| S) N:zfamily=ztype=zproto=zflags=, zGet address info %szGetting address info z took g@@z.3fzms: ) r:rrrrr% getaddrinforinfo) rir<r=r>r?r@flagsmsgt0addrinfodtrrr_getaddrinfo_debug>s&      z BaseEventLoop._getaddrinfo_debugrr>r?r@r3c s2|jr|j}ntj}|d|||||||IdHSrC)rr8r%r1r()rir<r=r>r?r@r3Z getaddr_funcrrrr1Vs zBaseEventLoop.getaddrinfocs|dtj||IdHSrC)r(r% getnameinfo)riZsockaddrr3rrrr:`s zBaseEventLoop.getnameinfo)fallbackc s|jr|dkrtdt||||||z|||||IdHWStjyv}z|sbWYd}~n d}~00|||||IdHS)Nrzthe socket must be non-blocking) rZ gettimeoutr&r^_check_sendfile_params_sock_sendfile_nativerSendfileNotAvailableError_sock_sendfile_fallback)rir+fileoffsetcountr;rXrrr sock_sendfileds zBaseEventLoop.sock_sendfilecstd|d|ddS)Nz-syscall sendfile is not available for socket z and file z combinationrr>rir+r@rArBrrrr=ss z#BaseEventLoop._sock_sendfile_nativec s|r|||rt|tjntj}t|}d}z|rNt|||}|dkrNqt|d|}|d|j|IdH} | szq|||d| IdH|| 7}q2|W|dkrt |dr|||Sn&|dkrt |dr|||0dS)Nrseek) rFminrZ!SENDFILE_FALLBACK_READBUFFER_SIZE bytearray memoryviewr(readintoZ sock_sendallr$) rir+r@rArB blocksizebuf total_sentviewreadrrrr?zs6  z%BaseEventLoop._sock_sendfile_fallbackcCsdt|ddvrtd|jtjks,td|durbt|tsLtd||dkrbtd|t|tsztd||dkrtd|dS)Nbmodez$file should be opened in binary modez+only SOCK_STREAM type sockets are supportedz+count must be a positive integer (got {!r})rz0offset must be a non-negative integer (got {!r})) rr&r?r%r2rr5r6formatrErrrr<s2   z$BaseEventLoop._check_sendfile_paramsc sDg}|||\}}}}} d} ztj|||d} | d|dur|D]t\}}}}} z| | WqWqHty} z8d| d| j} t| j| } || WYd} ~ qHd} ~ 00qH|| | | IdH| WSty } z*|| | dur | WYd} ~ n(d} ~ 0| dur8| Yn0dS)z$Create, bind and connect one socket.Nr>r?r@Fz*error while attempting to bind on address : ) r:r% setblockingbindr)strerrorlowererrnopop sock_connectr)rirZ addr_infoZlocal_addr_infosZ my_exceptionsr>type_r@_rr+ZladdrrXr4rrr _connect_socksB     "   zBaseEventLoop._connect_sock) r]r>r@r3r+ local_addrrrhappy_eyeballs_delay interleavec  sz| dur|std| dur0|r0|s,td|} | durD|sDtd|durTt|| durh| durhd} |dusz|dur|durtdj||f|tj||dIdH}|std| durj| |tj||dIdHstdnd| rt|| }g| durV|D]B}z |IdH}WqWntyNYqYn0qn.tj fd d |D| d IdH\}}}|dur.d d Dt dkrdnJt dt fdd Drdtd ddd Dn.|durtd|jtjkr.td|j|||| | dIdH\}}jrr|d}td|||||||fS)aConnect 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 sslr8host/port and sock can not be specified at the same timer>r?r@r3r!getaddrinfo() returned empty listc3s |]}tj|VqdSrC) functoolspartialr^)rDr6)r laddr_infosrirrrF!sz2BaseEventLoop.create_connection..rcSsg|]}|D]}|q qSrr)rDsubrXrrrr'r.z3BaseEventLoop.create_connection..rc3s|]}t|kVqdSrCrrDrX)modelrrrF-r.zMultiple exceptions: {}r0css|]}t|VqdSrCrjrkrrrrF2r.z5host and port was not specified and no sock specified"A Stream Socket was expected, got )rr%z%r connected to %s:%r: (%r, %r))r&r^_ensure_resolvedr%r2r)rQr^r Zstaggered_racerrallrRrr?_create_connection_transportrget_extra_inforr)rirr<r=r]r>r@r3r+r_rrr`rainfosr6r]rqrr)rrhrlrircreate_connections                zBaseEventLoop.create_connectionc s|d|}|}|rHt|tr*dn|} |j||| ||||d} n||||} z|IdHWn| Yn0| |fS)NFrrr)rUrgrboolrrr) rir+rr]rrrrrrrqrrrrpMs" z*BaseEventLoop._create_connection_transportc s|rtdt|dtjj}|tjjur:td||tjjurz|||||IdHWStj y}z|svWYd}~n d}~00|std|| ||||IdHS)aSend 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. zTransport is closingZ_sendfile_compatiblez(sendfile is not supported for transport NzHfallback is disabled and native sendfile is not supported for transport ) rlrprrZ _SendfileModeZ UNSUPPORTEDZ TRY_NATIVE_sendfile_nativerr>_sendfile_fallback)rirqr@rArBr;rQrXrrrsendfilegs4   zBaseEventLoop.sendfilecstddS)Nz!sendfile syscall is not supportedrD)rirjr@rArBrrrrvszBaseEventLoop._sendfile_nativec s||r|||rt|dnd}t|}d}t|}z |rt|||}|dkr|W|dkrvt|drv||||IdHSt|d|} |d|j| IdH} | s|W|dkrt|dr||||IdHS| IdH| | d| || 7}q8W|dkr4t|dr4||||IdHn4|dkrht|drh||||IdH0dS)Ni@rrF) rFrGrHr_r$rrIr(rJrnwrite) rirjr@rArBrKrLrMr@rNrOrrrrws@   z BaseEventLoop._sendfile_fallbackrtc stdurtdt|tjs*td|t|ddsFtd|d|}tj|||||||dd}| | || |j |} | |j } z|IdHWn,ty|| | Yn0|jS) zzUpgrade transport to TLS. Return a new transport that *protocol* should start using immediately. Nz"Python ssl module is not availablez@sslcontext is expected to be an instance of ssl.SSLContext, got Z_start_tls_compatibleFz transport z is not supported by start_tls())rr)r]rprZ SSLContextr6rrgr Z SSLProtocolrdrer$rrr} BaseExceptionrr~Z_app_transport) rirqrrrrrrZ ssl_protocolZ conmade_cbZ resume_cbrrr start_tlss>       zBaseEventLoop.start_tls)r>r@r3 reuse_address reuse_portallow_broadcastr+c s| dur| jtjkr"td| s>s>|s>|s>|s>|s>| r~t|||||| d} ddd| D} td| d| d d} nss|d krtd ||fd ff}nttd r|tj krfD]}|durt |t st dqڈrxd dvrxz"t t jr.tWnFtyDYn4tyv}ztd|WYd}~n d}~00||ffff}ni}d fdffD]\}}|durt |trt|dkst d|j||tj|||dIdH}|std|D]:\}}}}}||f}||vr0ddg||<||||<qqfdd|D}|sjtdg}|tur|rtdntjdtdd|D]\\}}\}}d} d} zxtj|tj|d} |rt| | r| tjtj d| d r| !|r*| s&|"| |IdH|} Wn`tyn}z(| durP| #|$|WYd}~n.d}~0| dur| #Yn0qq|d |}|%}|&| || |}|j'rrt(d||nt)d||z|IdHWn|#Yn0||fS)zCreate datagram connection.NzA UDP Socket was expected, got )r_ remote_addrr>r@r3r|r}r~r0css$|]\}}|r|d|VqdS)=Nr)rDkvrrrrFr.z9BaseEventLoop.create_datagram_endpoint..zKsocket modifier keyword arguments can not be used when sock is specified. ()Frzunexpected address family)NNAF_UNIXzstring is expected)rz2Unable to check or remove stale UNIX socket %r: %rrr,z2-tuple is expectedrdrecs8g|]0\}}r|ddusr,|ddus||fqS)rNrr)rDkeyZ addr_pairr_rrrr&sz:BaseEventLoop.create_datagram_endpoint..zcan not get address informationz~Passing `reuse_address=True` is no longer supported, as the usage of SO_REUSEPORT in UDP poses a significant security concern.zdThe *reuse_address* parameter has been deprecated as of 3.5.10 and is scheduled for removal in 3.11.) stacklevelrSz@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))*r?r%r3r&dictritemsrUr$rrrr6statS_ISSOCKosst_moderemoveFileNotFoundErrorr)rerrorrrrn_unsetrrr-r,r'r(Z SO_BROADCASTrVr[rr:rgrrr2r) rirr_rr>r@r3r|r}r~r+ZoptsZproblemsZr_addrZaddr_pairs_inforPerrZ addr_infosidxrrZfamr]ZprorrrZ local_addressZremote_addressrXrrrqrrrcreate_datagram_endpoints                  z&BaseEventLoop.create_datagram_endpointc s^|dd\}}t|||||g|ddR} | dur>| gS|j||||||dIdHSdS)Nr,r9)rBr1) rirr>r?r@r3rr<r=r2rrrrnts  zBaseEventLoop._ensure_resolvedcs8|j||f|tj||dIdH}|s4td|d|S)N)r>r?r3rz getaddrinfo(z) returned empty list)rnr%r2r))rir<r=r>r3rrrrr_create_server_getaddrinfos  z(BaseEventLoop._create_server_getaddrinfor) r>r3r+rr]r|r}rrc  st|trtd| dur*|dur*td|dur:t||dusLdurL|dur\td| durxtjdkovtjdk} g} |dkrdg}n$t|t st|t j j s|g}n|}fdd |D}t j|d iIdH}ttj|}d }z8|D]}|\}}}}}zt|||}Wn6tjyVjrNtjd |||d dYqYn0| || rz|tjtjd | rt|tr|tjkrttdr|tj tj!d z|"|Wqt#y}z(t#|j$d||j%&fdWYd}~qd}~00qd }W|sJ| D]}|'qn|sH| D]}|'q80n4|dur^td|j(tj)krztd||g} | D]}|*d qt+| |||| }| r|,t -dIdHjrt.d||S)a1Create 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 NoneNrbrcposixcygwinr/csg|]}j|dqS))r>r3)r)rDr<r>r3r=rirrrs z/BaseEventLoop.create_server..rFz:create_server() failed to create socket.socket(%r, %r, %r)Texc_info IPPROTO_IPV6z0error while attempting to bind on address %r: %sz)Neither host/port nor sock were specifiedrmrz %r is serving)/rrur6r&r^rrrplatformrrGabcIterabler rsetrLrMrNr%rrrwarningr:r'r(Z SO_REUSEADDRr,r9rr$rZ IPV6_V6ONLYrVr)rYrWrXrr?r2rUrrrr2)rirr<r=r>r3r+rr]r|r}rrrZhostsZfsrrZ completedresrAZsocktyper@Z canonnameZsarrrrr create_servers          zBaseEventLoop.create_server)r]rcs|jtjkrtd||dur.|s.td|dur>t||j|||dd|dIdH\}}|jr~|d}t d|||||fS) aHandle an accepted connection. This is used by servers that accept connections outside of asyncio but that use asyncio to handle connections. This method is a coroutine. When completed, the coroutine returns a (transport, protocol) pair. rmNrbr/T)rrr%z%r handled: (%r, %r)) r?r%r2r&r^rprrqrr)rirr+r]rrqrrrrconnect_accepted_sockets    z%BaseEventLoop.connect_accepted_socketcsd|}|}||||}z|IdHWn|Yn0|jr\td|||||fS)Nz Read pipe %r connected: (%r, %r))rgrrrrrfilenorirrrrrqrrrconnect_read_pipe s zBaseEventLoop.connect_read_pipecsd|}|}||||}z|IdHWn|Yn0|jr\td|||||fS)Nz!Write pipe %r connected: (%r, %r))rgrrrrrrrrrrconnect_write_pipe0s z BaseEventLoop.connect_write_pipecCs|g}|dur"|dt||durJ|tjkrJ|dt|n8|durf|dt||dur|dt|td|dS)Nzstdin=zstdout=stderr=zstdout=zstderr= )r:r"rr rrr)rir4rrrr2rrr_log_subprocess@szBaseEventLoop._log_subprocess) rrruniversal_newlinesrrencodingerrorstextc st|ttfstd|r"td|s.td|dkr>td| rJtd| durZtd| durjtd|} d}|jrd |}||||||j| |d ||||fi| IdH}|jr|durtd |||| fS) Nzcmd must be a string universal_newlines must be Falsezshell must be Truerbufsize must be 0text must be Falseencoding must be Noneerrors must be Nonezrun shell command %rT%s: %r) rr4rr&rrrrr2)rircmdrrrrrrrrrrr debug_logrqrrrsubprocess_shellMs6 zBaseEventLoop.subprocess_shellc s|r td|rtd|dkr(td| r4td| durDtd| durTtd|f| }|}d}|jrd|}||||||j||d ||||fi| IdH}|jr|durtd ||||fS) Nrzshell must be Falserrrrrzexecute program Fr)r&rrrrr2)rirZprogramrrrrrrrrrrrZ popen_argsrrrqrrrsubprocess_execqs6    zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use. )rrurrrget_exception_handlersz#BaseEventLoop.get_exception_handlercCs(|durt|std|||_dS)aSet 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 )rr6r)riZhandlerrrrset_exception_handlers z#BaseEventLoop.set_exception_handlerc Cs|d}|sd}|d}|dur6t|||jf}nd}d|vr`|jdur`|jjr`|jj|d<|g}t|D]}|dvr|qn||}|dkrd t|}d }|| 7}n2|dkrd t|}d }|| 7}nt |}| |d |qnt j d ||ddS)aEDefault 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()`. rz!Unhandled exception in event looprSNFZsource_tracebackZhandle_traceback>rSrr/z+Object created at (most recent call last): z+Handle created at (most recent call last): rT r)getr? __traceback__rrsortedr traceback format_listrstriprr:rr) rirrrSrZ log_linesrvaluetbrrrdefault_exception_handlers<   z'BaseEventLoop.default_exception_handlerc Cs|jdurRz||Wqttfy0YqtyNtjdddYq0nz|||WnttfyzYnrty}zZz|d||dWn6ttfyYn tytjdddYn0WYd}~n d}~00dS)aDCall the current event loop's exception handler. The context argument is a dict containing the following keys: - 'message': Error message; - 'exception' (optional): Exception object; - 'future' (optional): Future instance; - 'task' (optional): Task instance; - 'handle' (optional): Handle instance; - 'protocol' (optional): Protocol instance; - 'transport' (optional): Transport instance; - 'socket' (optional): Socket instance; - 'asyncgen' (optional): Asynchronous generator that caused the exception. New keys maybe introduced in the future. Note: do not overload this method in an event loop subclass. For custom exception handling, use the `set_exception_handler()` method. Nz&Exception in default exception handlerTrz$Unhandled error in exception handler)rrSrzeException in default exception handler while handling an unexpected error in custom exception handler)rrrTrUrzrr)rirrXrrrrs4    z$BaseEventLoop.call_exception_handlercCs|jr dS|j|dS)z3Add a Handle to _scheduled (TimerHandle) or _ready.N) _cancelledrr:rirrrr _add_callbackszBaseEventLoop._add_callbackcCs|||dS)z6Like _add_callback() but called from a signal handler.N)rrrrrr_add_callback_signalsafes z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)rrrrrr_timer_handle_cancelled!sz%BaseEventLoop._timer_handle_cancelledc Cst|j}|tkr`|j|tkr`g}|jD]}|jrsf                   ;   Do