a  ze7 @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#Z0Gd%d&d&ej1Z2Gd'd(d(ej3Z4Gd)d*d*ej5Z6dS)-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) BaseEventLoopdg?AF_INET6iQcCs0|j}tt|ddtjr$t|jSt|SdS)N__self__) _callback isinstancegetattrr Taskreprrstr)handlecbrG/opt/bitninja-python-dojo/embedded/lib/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_TCP IPPROTO_UDP SOCK_STREAM SOCK_DGRAMrbytesrint TypeErrorr& AF_UNSPECAF_INET _HAS_IPv6appendrdecoder-r)) hostportfamilytypeprotoZflowinfoZscopeidZafsafrrr _ipaddr_infogsN          rCcCst}|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"  rRcCs4|s"|}t|ttfr"dSt|dSrD) cancelled exceptionr SystemExitKeyboardInterruptrZ _get_loopstop)futexcrrr_run_until_complete_cbs rZ TCP_NODELAYcCs@|jtjtjhvr<|jtjkr<|jtjkr<|tjtj ddSNr) r?r%r9rr@r3rAr1r'r[r*rrr _set_nodelays   r]cCsdSrDrr*rrrr]sc@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_FlowControlMixinr7 _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_closingConnectionErrorrg)rhrXrrrdrains  z_SendfileFallbackProtocol.draincCs tddS)Nz?Invalid state: connection should have been established already. RuntimeError)rh transportrrrconnection_madesz)_SendfileFallbackProtocol.connection_madecCs@|jdur0|dur$|jtdn |j||j|dS)NzConnection is closed by peer)rg set_exceptionrlr`connection_lost)rhrYrrrrss  z)_SendfileFallbackProtocol.connection_lostcCs |jdurdS|jj|_dSrD)rgr_rerfrhrrr pause_writings z'_SendfileFallbackProtocol.pause_writingcCs$|jdurdS|jdd|_dS)NF)rg set_resultrtrrrresume_writings  z(_SendfileFallbackProtocol.resume_writingcCs tddSNz'Invalid state: reading should be pausedrn)rhdatarrr data_receivedsz'_SendfileFallbackProtocol.data_receivedcCs tddSrxrnrtrrr eof_receivedsz&_SendfileFallbackProtocol.eof_receivedcsF|j|j|jr|j|jdur2|j|jrB|jdSrD) r_rdr`raresume_readingrgcancelrbrwrtrrrrestores   z!_SendfileFallbackProtocol.restoreN) __name__ __module__ __qualname__rjrmrqrsrurwrzr{r~rrrrr^s r^c@sxeZdZddZddZddZddZd d Zd d Zd dZ ddZ e ddZ ddZ ddZddZddZdS)ServercCs@||_||_d|_g|_||_||_||_||_d|_d|_ dS)NrF) re_sockets _active_count_waiters_protocol_factory_backlog _ssl_context_ssl_handshake_timeout_serving_serving_forever_fut)rhloopsocketsprotocol_factoryZ ssl_contextbacklogssl_handshake_timeoutrrrrjszServer.__init__cCsd|jjd|jdS)N) __class__rrrtrrr__repr__ szServer.__repr__cCs|jd7_dSr\)rrtrrr_attach#szServer._attachcCs.|jd8_|jdkr*|jdur*|dS)Nrr)rr_wakeuprtrrr_detach'szServer._detachcCs,|j}d|_|D]}|s||qdSrD)rdonerv)rhwaiterswaiterrrrr-s zServer._wakeupc CsJ|jr dSd|_|jD].}||j|j|j||j||j|jqdS)NT) rrlistenrre_start_servingrrr)rhr+rrrr4s    zServer._start_servingcCs|jSrD)rertrrrget_loop>szServer.get_loopcCs|jSrD)rrtrrr is_servingAszServer.is_servingcCs"|jdurdStdd|jDS)Nrcss|]}t|VqdSrD)r ZTransportSocket)rEsrrrrGHr.z!Server.sockets..)rtuplertrrrrDs zServer.socketscCsn|j}|durdSd|_|D]}|j|qd|_|jdurX|jsX|jd|_|jdkrj|dS)NFr) rreZ _stop_servingrrrr}rr)rhrr+rrrcloseJs   z Server.closecs|tdIdHdS)Nr)rr sleeprtrrr start_serving]szServer.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) rrorrrerfrCancelledErrorr wait_closedrtrrr serve_forevercs     zServer.serve_forevercs<|jdus|jdurdS|j}|j||IdHdSrD)rrrerfr;)rhrrrrrxs   zServer.wait_closedN)rrrrjrrrrrrrpropertyrrrrrrrrrrs   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?der.z4BaseEventLoop.shutdown_asyncgens..)Zreturn_exceptionsrz;an error occurred during closing of asynchronous generator )messagerTZasyncgen) rlenrrJclearr _gatherzipr Exceptioncall_exception_handler)rhZ closing_agensresultsresultrrrrshutdown_asyncgenss&     z BaseEventLoop.shutdown_asyncgenscs\d|_|jdurdS|}tj|j|fd}|z|IdHW|n |0dS)z.Schedule the shutdown of the default executor.TN)targetr)rrrf threadingThread _do_shutdownstartjoin)rhfuturethreadrrrshutdown_default_executor,s  z'BaseEventLoop.shutdown_default_executorc CsXz |jjdd||jdWn2tyR}z||j|WYd}~n d}~00dS)NTwait)rshutdownrrvrrr)rhr exrrrr9s zBaseEventLoop._do_shutdowncCs(|rtdtdur$tddS)Nz"This event loop is already runningz7Cannot run the event loop while another loop is running)rrorZ_get_running_looprtrrr_check_running@s  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)rhZold_agen_hooksrrr run_foreverGs.        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.)rrrZisfuturer Z ensure_futureZ_log_destroy_pendingadd_done_callbackrZrrrSrTZremove_done_callbackror)rhr Znew_taskrrrrun_until_complete^s"     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)rrtrrrrWszBaseEventLoop.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 ) rrorrrdebugrrrrrrrhexecutorrrrrs   zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)rrtrrrrszBaseEventLoop.is_closedcCs0|s,|d|t|d|s,|dS)Nzunclosed event loop r)rrrr)rh_warnrrr__del__szBaseEventLoop.__del__cCs |jduS)z*Returns True if the event loop is running.N)rrtrrrrszBaseEventLoop.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. )rrrtrrrrszBaseEventLoop.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. r#r)call_atrr)rhdelaycallbackr#rtimerrrr 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. r$rT) rr _check_thread_check_callbackrZ TimerHandlerheapqheappushr)rhwhenr&r#rr'rrrr$s 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)rrr)r* _call_soonrrhr&r#rrrrrr.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 iscoroutineZiscoroutinefunctionr7r)rhr&methodrrrr*s  zBaseEventLoop._check_callbackcCs.t||||}|jr|jd=|j||S)Nr)rHandlerrr;)rhr&rr#rrrrr/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)rrrro)rhZ thread_idrrrr)s  zBaseEventLoop._check_threadcGsB||jr||d||||}|jr6|jd=||S)z"Like call_soon(), but thread-safe.rr)rrr*r/rrr0rrrrs 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_futuresubmit)rhr funcrrrrr3 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)rr4rr5rrDeprecationWarningrrrrrset_default_executor0s 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;r rrrr% getaddrinforinfo) rhr=r>r?r@rAflagsmsgt0addrinfodtrrr_getaddrinfo_debug9s&      z BaseEventLoop._getaddrinfo_debugrr?r@rAr?c s2|jr|j}ntj}|d|||||||IdHSrD)rrDr%r=r3)rhr=r>r?r@rAr?Z getaddr_funcrrrr=Qs zBaseEventLoop.getaddrinfocs|dtj||IdHSrD)r3r% getnameinfo)rhZsockaddrr?rrrrF[s zBaseEventLoop.getnameinfo)fallbackc s|jr|dkrtd|||||z|||||IdHWStjyn}z|sZWYd}~n d}~00|||||IdHS)Nrzthe socket must be non-blocking)r gettimeoutr&_check_sendfile_params_sock_sendfile_nativerSendfileNotAvailableError_sock_sendfile_fallback)rhr+fileoffsetcountrGrYrrr sock_sendfile_s zBaseEventLoop.sock_sendfilecstd|ddS)Nz-syscall sendfile is not available for socket z and file {file!r} combinationrrKrhr+rMrNrOrrrrJms 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) rSminrZ!SENDFILE_FALLBACK_READBUFFER_SIZE bytearray memoryviewr3readintoZ sock_sendallr$) rhr+rMrNrO blocksizebuf total_sentviewreadrrrrLts6  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%r3rr6r7formatrRrrrrIs2   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@rAFz*error while attempting to bind on address : ) r;r% setblockingbindr)strerrorlowererrnopop sock_connectr)rhrZ addr_infoZlocal_addr_infosZ my_exceptionsr?type_rA_rr+laddrrYr@rrr _connect_socksB     "   zBaseEventLoop._connect_sock) sslr?rAr?r+ local_addrrrhappy_eyeballs_delay interleavec  sj| dur|std| dur0|r0|s,td|} | durD|sDtd| durX| durXd} |dusj|dur|durztdj||f|tj||dIdH}|std| dur܈j| |tj||dIdHstdnd| rt|| }g| durF|D]B}z |IdH}WqtWnty>YqYn0qn.tjfd d |D| d IdH\}}}|durd d Dt dkrdnJt dt fdd DrЈdtd d dd Dn.|durtd|jtjkrtd|j|||| | dIdH\}}jrb|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@rAr?r!getaddrinfo() returned empty listc3s |]}tj|VqdSrD) functoolspartialrl)rErB)r laddr_infosrhrrrGsz2BaseEventLoop.create_connection..rcSsg|]}|D]}|q qSrr)rEsubrYrrrrr.z3BaseEventLoop.create_connection..rc3s|]}t|kVqdSrDrrErY)modelrrrG$r.zMultiple exceptions: {}r<css|]}t|VqdSrDryrzrrrrG)r.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&_ensure_resolvedr%r3r)rRrlr Zstaggered_racerrallr_r r@_create_connection_transportrget_extra_inforr)rhrr=r>rmr?rAr?r+rnrrrorpinfosrBrjrprr)rrwr{rhrcreate_connections                zBaseEventLoop.create_connectionc s|d|}|}|rHt|tr*dn|} |j||| ||||d} n||||} z|IdHWn| Yn0| |fS)NFrrr)rbrfrboolrrr) rhr+rrmrrrrrrrprrrrDs" 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 ) rkrorrZ _SendfileModeZ UNSUPPORTEDZ TRY_NATIVE_sendfile_nativerrK_sendfile_fallback)rhrprMrNrOrGr^rYrrrsendfile^s4   zBaseEventLoop.sendfilecstddS)Nz!sendfile syscall is not supportedrQ)rhrirMrNrOrrrrszBaseEventLoop._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@rrS) rSrTrUr^r$r~rVr3rWrmwrite) rhrirMrNrOrXrYrZrAr[r\rrrrs@   z BaseEventLoop._sendfile_fallbackrc 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)rmrorZ SSLContextr7rrfr Z SSLProtocolrcrdr.rqr| BaseExceptionrr}Z_app_transport) rhrprrrrrrZ ssl_protocolZ conmade_cbZ resume_cbrrr start_tlss>       zBaseEventLoop.start_tls)r?rAr? 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]\}}|dur|j||tj|||dIdH}|std|D]:\}}}}}||f}||vrddg||<||||<qqfdd|D}|sHtdg}|turv|rftdntjdtdd|D]\\}}\}}d} d} zxtj|tj|d} |rt| | r| tjtjd| d r| |r| s| | |IdH|} Wn`tyL}z(| dur.| !|"|WYd}~n.d}~0| durd| !Yn0q~qz|d |}|#}|$| || |}|j%rΈrt&d||nt'd||z|IdHWn|!Yn0||fS)zCreate datagram connection.NzA UDP Socket was expected, got )rn remote_addrr?rAr?rrrr<css$|]\}}|r|d|VqdS)=Nr)rEkvrrrrGr.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: %rrrsrtcs8g|]0\}}r|ddusr,|ddus||fqS)rNrr)rEkeyZ addr_pairrnrrrrsz: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.r8) stacklevelr`z@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))(r@r%r4r&dictr itemsrbr$rrrr7statS_ISSOCKosst_moderemoveFileNotFoundErrorr)rerrorr}_unsetrrr9r,r'r( SO_BROADCASTrcrhrr;rfrrr>r) rhrrnrr?rAr?rrrr+ZoptsZproblemsZr_addrZaddr_pairs_inforQerrZ addr_infosidxrZfamrjZprorrrZ local_addressZremote_addressrYrrrprrrcreate_datagram_endpoints                  z&BaseEventLoop.create_datagram_endpointc s^|dd\}}t|||||g|ddR} | dur>| gS|j||||||dIdHSdS)Nr8rE)rCr=) rhrr?r@rAr?rr=r>r>rrrr}ks  zBaseEventLoop._ensure_resolvedcs8|j||f|tj||dIdH}|s4td|d|S)N)r?r@r?rz getaddrinfo(z) returned empty list)r}r%r3r))rhr=r>r?r?rrrr_create_server_getaddrinfows  z(BaseEventLoop._create_server_getaddrinfor) r?r?r+rrmrrrrc  st|trtd| dur*|dur*td|dus<dur<|durLtd| durhtjdkoftjdk} g} |dkr|dg}n$t|tst|t j j s|g}n|}fdd |D}t j |d iIdH}ttj|}d }z8|D]}|\}}}}}zt|||}Wn6tjyFjr>tjd |||d dYqYn0| || rj|tjtjd | rxt|tr|tjkrttdr|tjtj d z|!|Wqt"y}z(t"|j#d||j$%fdWYd}~qd}~00qd }W|s:| D]}|&q n|s8| D]}|&q(0n4|durNtd|j'tj(krjtd||g} | D]}|)d qtt*| |||| }| 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 NoneNrqrrposixcygwinr/csg|]}j|dqS))r?r?)r)rEr=r?r?r>rhrrrs 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 specifiedr|rz %r is serving).rrr7r&rrrplatformrrHabcIterabler rsetrMrNrOr%rrrwarningr;r'r( SO_REUSEADDRr,r:rr$r IPV6_V6ONLYrcr)rfrdrerr@r3rbrrrr>)rhrr=r>r?r?r+rrmrrrrrZhostsfsrZ completedresrBsocktyperA canonnamesarrrrr create_servers          zBaseEventLoop.create_server)rmrcsv|jtjkrtd||dur.|s.td|j|||dd|dIdH\}}|jrn|d}td|||||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. r|Nrqr/T)rrr%z%r handled: (%r, %r)) r@r%r3r&rrrrr)rhrr+rmrrprrrrconnect_accepted_sockets    z%BaseEventLoop.connect_accepted_socketcsd|}|}||||}z|IdHWn|Yn0|jr\td|||||fS)Nz Read pipe %r connected: (%r, %r))rfrrrrrfilenorhrrrrrprrrconnect_read_pipes zBaseEventLoop.connect_read_pipecsd|}|}||||}z|IdHWn|Yn0|jr\td|||||fS)Nz!Write pipe %r connected: (%r, %r))rfrrrrrrrrrrconnect_write_pipe!s 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 )rhr@rrrr>rrr_log_subprocess1szBaseEventLoop._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) rr5rr&rrrrr>)rhrcmdrrrrrrrrrrr debug_logrprrrsubprocess_shell>s6 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&rrrrr>)rhrZprogramrrrrrrrrrrrZ popen_argsrrrprrrsubprocess_execbs6    zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use. )rrtrrrget_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 )rr7r)rhhandlerrrrset_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 looprTNFZsource_tracebackZhandle_traceback>rTrr/z+Object created at (most recent call last): z+Handle created at (most recent call last): ra r)getr@ __traceback__rrsortedr  traceback format_listrstriprr;rr) rhr#rrTrZ 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)rrTr#zeException in default exception handler while handling an unexpected error in custom exception handler)rrrUrVrrr)rhr#rYrrrrs4    z$BaseEventLoop.call_exception_handlercCs|jr dS|j|dS)z3Add a Handle to _scheduled (TimerHandle) or _ready.N) _cancelledrr;rhrrrr _add_callbackszBaseEventLoop._add_callbackcCs|||dS)z6Like _add_callback() but called from a signal handler.N)rrrrrr_add_callback_signalsafe s z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)rrrrrr_timer_handle_cancelledsz%BaseEventLoop._timer_handle_cancelledc Cst|j}|tkr`|j|tkr`g}|jD]}|jrsd                   ;   Do