U e5d­ã@sædZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZz ddlZWnek r¨dZYnXddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddl m!Z!dZ"dZ#dZ$e%e dƒZ&dZ'e(ƒZ)dd„Z*dd„Z+dd„Z,d+dd„Z-d,dd„Z.dd „Z/e%e d!ƒ�r¤d"d#„Z0nd$d#„Z0Gd%d&„d&ej1ƒZ2Gd'd(„d(ej3ƒZ4Gd)d*„d*ej5ƒZ6dS)-a™Base 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)Ú BaseEventLoopédgà?ÚAF_INET6i€QcCs0|j}tt|ddƒtjƒr$t|jƒSt|ƒSdS)NÚ__self__)Z _callbackÚ isinstanceÚgetattrr ÚTaskÚreprrÚstr)ÚhandleÚcb©rú+/usr/lib64/python3.8/asyncio/base_events.pyÚ_format_handleJs rcCs(|tjkrdS|tjkrdSt|ƒSdS)Nzz)Ú subprocessÚPIPEÚSTDOUTr)ÚfdrrrÚ _format_pipeSs   r!cCsLttdƒstdƒ‚n4z| tjtjd¡Wntk rFtdƒ‚YnXdS)NÚ SO_REUSEPORTz)reuse_port not supported by socket modulerzTreuse_port not supported by socket module, SO_REUSEPORT defined but not implemented.)ÚhasattrÚsocketÚ ValueErrorÚ setsockoptÚ SOL_SOCKETr"ÚOSError©ÚsockrrrÚ_set_reuseport\s   r+c Cs„ttdƒsdS|dtjtjhks(|dkr,dS|tjkr>tj}n|tjkrPtj}ndS|dkrbd}nXt|tƒrz|dkrzd}n@t|tƒr’|dkr’d}n(z t |ƒ}Wnt t fk r¸YdSX|tj krÞtj g}trä| tj¡n|g}t|tƒrø| d¡}d|k�rdS|D]t}zVt ||¡t�rJ|tjk�rJ|||d||||ffWS|||d||ffWSWntk �rzYnX�q dS)NÚ inet_ptonróÚZidnaú%)r#r$Ú IPPROTO_TCPZ IPPROTO_UDPÚ SOCK_STREAMÚ SOCK_DGRAMrÚbytesrÚintÚ TypeErrorr%Ú AF_UNSPECÚAF_INETÚ _HAS_IPv6ÚappendrÚdecoder,r() ÚhostÚportÚfamilyÚtypeÚprotoZflowinfoZscopeidZafsÚafrrrÚ _ipaddr_infogsN ÿ         rAcCs¢t ¡}|D]*}|d}||kr(g||<|| |¡q t| ¡ƒ}g}|dkr|| |dd|d…¡|dd|d…=| dd„tj tj |Ž¡Dƒ¡|S)z-Interleave list of addrinfo tuples by family.rrNcss|]}|dk r|VqdS©Nr)Ú.0ÚarrrÚ ±sþz(_interleave_addrinfos..) Ú collectionsÚ OrderedDictr9ÚlistÚvaluesÚextendÚ itertoolsÚchainÚ from_iterableÚ zip_longest)Z addrinfosZfirst_address_family_countZaddrinfos_by_familyÚaddrr=Zaddrinfos_listsZ reorderedrrrÚ_interleave_addrinfos¢s"  ÿÿrPcCs4| ¡s"| ¡}t|ttfƒr"dSt |¡ ¡dSrB)Ú cancelledÚ exceptionrÚ SystemExitÚKeyboardInterruptrZ _get_loopÚstop)ÚfutÚexcrrrÚ_run_until_complete_cb¸s rXÚ TCP_NODELAYcCs@|jtjtjhkr<|jtjkr<|jtjkr<| tjtj d¡dS©Nr) r=r$r7rr>r1r?r0r&rYr)rrrÚ _set_nodelayÃs  ÿ þr[cCsdSrBrr)rrrr[Ésc@sTeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS)Ú_SendfileFallbackProtocolcCsht|tjƒstdƒ‚||_| ¡|_| ¡|_|j |_ |  ¡|  |¡|j r^|jj  ¡|_nd|_dS)Nz.transport should be _FlowControlMixin instance)rr Z_FlowControlMixinr5Ú _transportZ get_protocolÚ_protoZ is_readingÚ_should_resume_readingZ_protocol_pausedÚ_should_resume_writingÚ pause_readingÚ set_protocolÚ_loopÚ create_futureÚ_write_ready_fut)ÚselfÚtransprrrÚ__init__Îs    z"_SendfileFallbackProtocol.__init__cÃs2|j ¡rtdƒ‚|j}|dkr$dS|IdHdS)NzConnection closed by peer)r]Ú is_closingÚConnectionErrorre)rfrVrrrÚdrainÜs  z_SendfileFallbackProtocol.draincCs tdƒ‚dS)Nz?Invalid state: connection should have been established already.©Ú RuntimeError)rfÚ transportrrrÚconnection_madeäsz)_SendfileFallbackProtocol.connection_madecCs@|jdk r0|dkr$|j tdƒ¡n |j |¡|j |¡dS)NzConnection is closed by peer)reZ set_exceptionrjr^Úconnection_lost)rfrWrrrrpès ÿ z)_SendfileFallbackProtocol.connection_lostcCs |jdk rdS|jj ¡|_dSrB)rer]rcrd©rfrrrÚ pause_writingós z'_SendfileFallbackProtocol.pause_writingcCs$|jdkrdS|j d¡d|_dS)NF)reÚ set_resultrqrrrÚresume_writingøs  z(_SendfileFallbackProtocol.resume_writingcCs tdƒ‚dS©Nz'Invalid state: reading should be pausedrl)rfÚdatarrrÚ data_receivedþsz'_SendfileFallbackProtocol.data_receivedcCs tdƒ‚dSrurlrqrrrÚ eof_receivedsz&_SendfileFallbackProtocol.eof_receivedcÃsF|j |j¡|jr|j ¡|jdk r2|j ¡|jrB|j ¡dSrB) r]rbr^r_Úresume_readingreÚcancelr`rtrqrrrÚrestores   z!_SendfileFallbackProtocol.restoreN) Ú__name__Ú __module__Ú __qualname__rhrkrorprrrtrwrxr{rrrrr\Ís r\c@sxeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z e dd„ƒZ dd„Z dd„Zdd„Zdd„ZdS)ÚServercCs@||_||_d|_g|_||_||_||_||_d|_d|_ dS)NrF) rcÚ_socketsÚ _active_countÚ_waitersÚ_protocol_factoryÚ_backlogÚ _ssl_contextÚ_ssl_handshake_timeoutÚ_servingÚ_serving_forever_fut)rfÚloopÚsocketsÚprotocol_factoryZ ssl_contextÚbacklogÚssl_handshake_timeoutrrrrhszServer.__init__cCsd|jj›d|j›d�S)Nú)Ú __class__r|rŠrqrrrÚ__repr__ szServer.__repr__cCs |jdk st‚|jd7_dSrZ)r€ÚAssertionErrorr�rqrrrÚ_attach#szServer._attachcCs<|jdkst‚|jd8_|jdkr8|jdkr8| ¡dS)Nrr)r�r’r€Ú_wakeuprqrrrÚ_detach'szServer._detachcCs,|j}d|_|D]}| ¡s| |¡qdSrB)r‚Údoners)rfÚwaitersÚwaiterrrrr”-s zServer._wakeupc CsJ|jr dSd|_|jD].}| |j¡|j |j||j||j|j¡qdS)NT) r‡r€Zlistenr„rcÚ_start_servingrƒr…r†)rfr*rrrr™4s  þzServer._start_servingcCs|jSrB)rcrqrrrÚget_loop>szServer.get_loopcCs|jSrB)r‡rqrrrÚ is_servingAszServer.is_servingcCs"|jdkrdStdd„|jDƒƒS)Nrcss|]}t |¡VqdSrB)r ZTransportSocket)rCÚsrrrrEHsz!Server.sockets..)r€ÚtuplerqrrrrŠDs zServer.socketscCsn|j}|dkrdSd|_|D]}|j |¡qd|_|jdk rX|j ¡sX|j ¡d|_|jdkrj| ¡dS)NFr) r€rcZ _stop_servingr‡rˆr–rzr�r”)rfrŠr*rrrÚcloseJs ÿ  z Server.closecÃs"| ¡tjd|jd�IdHdS)Nr©r‰)r™r ÚsleeprcrqrrrÚ start_serving]szServer.start_servingc Ãs¢|jdk rtd|›d�ƒ‚|jdkr4td|›d�ƒ‚| ¡|j ¡|_zLz|jIdHWn6tjk r�z| ¡|  ¡IdHW5‚XYnXW5d|_XdS)Nzserver z, is already being awaited on serve_forever()z is closed) rˆrmr€r™rcrdrZCancelledErrorržÚ wait_closedrqrrrÚ serve_forevercs   ÿ  zServer.serve_forevercÃs<|jdks|jdkrdS|j ¡}|j |¡|IdHdSrB)r€r‚rcrdr9)rfr˜rrrr¢xs   zServer.wait_closedN)r|r}r~rhr‘r“r•r”r™ršr›ÚpropertyrŠržr¡r£r¢rrrrrs   rc @sPeZdZdd„Zdd„Zdd„Zddœd d „Zd d „Zd d„Zd dddœdd„Z d¡dddddddœdd„Z d¢dd„Z d£dd„Z d¤dd„Z d¥dd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zejfd7d8„Zd9d:„Zd;d<„Zdd=œd>d?„Z dd=œd@dA„Z!dd=œdBdC„Z"dDdE„Z#dFdG„Z$dHdI„Z%dd=œdJdK„Z&dLdM„Z'dNdO„Z(dPdQ„Z)dRdRdRdRdSœdTdU„Z*d¦dVdW„Z+d§ddXœdYdZ„Z,d[d\„Z-d]d^„Z.d_d`„Z/d¨dadb„Z0d©ddRdRdRdddddddcœ ddde„Z1dªdfdg„Z2d«ddXœdhdi„Z3djdk„Z4dldm„Z5ddddnœdodp„Z6d¬dRdRdRe7ddddqœdrds„Z8dRe9j:dRdRdSœdtdu„Z;dvdw„Zddxddddddyœ dzd{„Z?ddd|œd}d~„Z@dd€„ZAd�d‚„ZBdƒd„„ZCeDjEeDjEeDjEdddRdddd…œ d†d‡„ZFeDjEeDjEeDjEdddRdddd…œ dˆd‰„ZGdŠd‹„ZHdŒd�„ZIdŽd�„ZJd�d‘„ZKd’d“„ZLd”d•„ZMd–d—„ZNd˜d™„ZOdšd›„ZPdœd�„ZQdždŸ„ZRdS)®rcCsˆd|_d|_d|_t ¡|_g|_d|_d|_d|_ t   d¡j |_ d|_| t ¡¡d|_d|_d|_d|_d|_t ¡|_d|_dS)NrFÚ monotonicgš™™™™™¹?)Ú_timer_cancelled_countÚ_closedÚ _stoppingrFÚdequeÚ_readyÚ _scheduledÚ_default_executorZ _internal_fdsÚ _thread_idÚtimeÚget_clock_infoZ resolutionÚ_clock_resolutionÚ_exception_handlerÚ set_debugrZ_is_debug_modeÚslow_callback_durationÚ_current_handleÚ _task_factoryÚ"_coroutine_origin_tracking_enabledÚ&_coroutine_origin_tracking_saved_depthÚweakrefZWeakSetÚ _asyncgensÚ_asyncgens_shutdown_calledrqrrrrh‚s$  zBaseEventLoop.__init__c Cs.d|jj›d| ¡›d| ¡›d| ¡›d� S)NrŽz running=z closed=z debug=r�)r�r|Ú is_runningÚ is_closedÚ get_debugrqrrrr‘žs,ÿzBaseEventLoop.__repr__cCs tj|d�S)z,Create a Future object attached to the loop.rŸ)rZFuturerqrrrrd¤szBaseEventLoop.create_futureN)ÚnamecCsN| ¡|jdkr2tj|||d�}|jrJ|jd=n| ||¡}t ||¡|S)zDSchedule a coroutine object. Return a task object. N)r‰r¾éÿÿÿÿ)Ú _check_closedrµr rÚ_source_tracebackZ_set_task_name)rfÚcoror¾ZtaskrrrÚ create_task¨s    zBaseEventLoop.create_taskcCs"|dk rt|ƒstdƒ‚||_dS)awSet a task factory that will be used by loop.create_task(). If factory is None the default task factory will be set. If factory is a callable, it should have a signature matching '(loop, coro)', where 'loop' will be a reference to the active event loop, 'coro' will be a coroutine object. The callable must return a Future. Nz'task factory must be a callable or None)Úcallabler5rµ)rfÚfactoryrrrÚset_task_factory¸s zBaseEventLoop.set_task_factorycCs|jS)zsz4BaseEventLoop.shutdown_asyncgens..)Zreturn_exceptionsr‰z;an error occurred during closing of asynchronous generator )ÚmessagerRZasyncgen) rºÚlenr¹rHÚclearr ÚgatherÚziprÚ ExceptionÚcall_exception_handler)rfZ closing_agensZresultsÚresultrèrrrÚshutdown_asyncgens s"    ý üz BaseEventLoop.shutdown_asyncgenscCs(| ¡rtdƒ‚t ¡dk r$tdƒ‚dS)Nz"This event loop is already runningz7Cannot run the event loop while another loop is running)r»rmrZ_get_running_looprqrrrÚ_check_running&s  ÿzBaseEventLoop._check_runningc Cs’| ¡| ¡| |j¡t ¡|_t ¡}tj |j |j d�z t  |¡| ¡|j rLq^qLW5d|_ d|_t  d¡| d¡tj |ŽXdS)zRun until stop() is called.)Ú firstiterÚ finalizerFN)rÀrûÚ_set_coroutine_origin_trackingÚ_debugÚ threadingÚ get_identr­ÚsysÚget_asyncgen_hooksÚset_asyncgen_hooksrðrér¨rZ_set_running_loopÚ _run_once)rfZold_agen_hooksrrrÚ run_forever-s$  ÿ   zBaseEventLoop.run_foreverc Cs | ¡| ¡t |¡ }tj||d�}|r4d|_| t¡z|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¿)rÀrÿrrÚ _call_soonrÁ©rfrr rÙrrrrrÅs  zBaseEventLoop.call_sooncCsDt |¡st |¡r$td|›d�ƒ‚t|ƒs@td|›d|›�ƒ‚dS)Nzcoroutines cannot be used with z()z"a callable object was expected by z(), got )rZ iscoroutineZiscoroutinefunctionr5rÄ)rfrÚmethodrrrrØs ÿ ÿÿzBaseEventLoop._check_callbackcCs.t ||||¡}|jr|jd=|j |¡|S)Nr¿)rÚHandlerÁrªr9)rfrrÙr rrrrrâs  zBaseEventLoop._call_sooncCs,|jdkrdSt ¡}||jkr(tdƒ‚dS)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)r­rrrm)rfZ thread_idrrrrés  ÿzBaseEventLoop._check_threadcGsB| ¡|jr| |d¡| |||¡}|jr6|jd=| ¡|S)z"Like call_soon(), but thread-safe.rår¿)rÀrÿrrrÁrárrrrråús z"BaseEventLoop.call_soon_threadsafecGsZ| ¡|jr| |d¡|dkr@|j}|dkr@tj ¡}||_tj|j|f|žŽ|d�S)NÚrun_in_executorrŸ) rÀrÿrr¬Ú concurrentrÚThreadPoolExecutorZ wrap_futureZsubmit)rfr ÚfuncrÙrrrrs  ÿzBaseEventLoop.run_in_executorcCs&t|tjjƒst dtd¡||_dS)Nz{Using the default executor that is not an instance of ThreadPoolExecutor is deprecated and will be prohibited in Python 3.9é)rrrrrìríÚDeprecationWarningr¬r rrrÚset_default_executorsüz"BaseEventLoop.set_default_executorc CsÞ|›d|›�g}|r$| d|›�¡|r8| d|›�¡|rL| d|›�¡|r`| d|›�¡d |¡}t d|¡| ¡}t ||||||¡} | ¡|} d|›d | d d ›d | ›�}| |jkrÐt |¡n t |¡| S) Nú:zfamily=ztype=zproto=zflags=ú, zGet address info %szGetting address info z took g@�@z.3fzms: ) r9Újoinrr r®r$Ú getaddrinfor³Úinfo) rfr;r<r=r>r?ÚflagsÚmsgÚt0ÚaddrinfoÚdtrrrÚ_getaddrinfo_debugs&      z BaseEventLoop._getaddrinfo_debugr©r=r>r?r)c Ãs2|jr|j}ntj}| d|||||||¡IdHSrB)rÿr.r$r'r)rfr;r<r=r>r?r)Z getaddr_funcrrrr'2sÿzBaseEventLoop.getaddrinfocÃs| dtj||¡IdHSrB)rr$Ú getnameinfo)rfZsockaddrr)rrrr0<s ÿzBaseEventLoop.getnameinfo)Úfallbackc Ãs„|jr| ¡dkrtdƒ‚| ||||¡z| ||||¡IdHWStjk rl}z |s\‚W5d}~XYnX| ||||¡IdHS)Nrzthe socket must be non-blocking)rÿZ gettimeoutr%Ú_check_sendfile_paramsÚ_sock_sendfile_nativerÚSendfileNotAvailableErrorÚ_sock_sendfile_fallback)rfr*ÚfileÚoffsetÚcountr1rWrrrÚ sock_sendfile@sÿ ÿzBaseEventLoop.sock_sendfilecÃst d|›d�¡‚dS)Nz-syscall sendfile is not available for socket z and file {file!r} combination©rr4©rfr*r6r7r8rrrr3Ns ÿz#BaseEventLoop._sock_sendfile_nativec ÃsÌ|r| |¡|rt|tjƒntj}t|ƒ}d}zt|rNt|||ƒ}|dkrNqžt|ƒd|…}| d|j|¡IdH} | szqž|  ||d| …¡IdH|| 7}q2|W¢S|dkrÆt|dƒrÆ| ||¡XdS)NrÚseek) r<ÚminrZ!SENDFILE_FALLBACK_READBUFFER_SIZEÚ bytearrayr#Ú memoryviewrÚreadintoZ sock_sendall) rfr*r6r7r8Ú blocksizeÚbufÚ total_sentÚviewÚreadrrrr5Us, ÿþ z%BaseEventLoop._sock_sendfile_fallbackcCs”dt|ddƒkrtdƒ‚|jtjks,tdƒ‚|dk rbt|tƒsLtd |¡ƒ‚|dkrbtd |¡ƒ‚t|tƒsztd |¡ƒ‚|dkr�td |¡ƒ‚dS)NÚbÚmodez$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$r1rr4r5Úformatr;rrrr2os2  ÿÿ ÿÿÿÿz$BaseEventLoop._check_sendfile_paramsc Ãs@g}| |¡|\}}}}} d} zºtj|||d�} |  d¡|dk rÄ|D]r\}}}}} z|  | ¡WqÄWqHtk r¸} z0d| ›d| j ¡›�} t| j| ƒ} | | ¡W5d} ~ XYqHXqH| ¡‚|  | | ¡IdH| WStk �r} z"| | ¡| dk �r |   ¡‚W5d} ~ XYn | dk �r4|   ¡‚YnXdS)z$Create, bind and connect one socket.N©r=r>r?Fz*error while attempting to bind on address ú: ) r9r$Ú setblockingÚbindr(ÚstrerrorÚlowerÚerrnoÚpopÚ sock_connectrž)rfrZ addr_infoZlocal_addr_infosZ my_exceptionsr=Ztype_r?Ú_rÓr*ZladdrrWr*rrrÚ _connect_sock„s:    ÿ    zBaseEventLoop._connect_sock) Ússlr=r?r)r*Ú local_addrrÏr�Úhappy_eyeballs_delayÚ interleavec  ƒsl| dk r|stdƒ‚| dkr0|r0|s,tdƒ‚|} | dk rD|sDtdƒ‚| dk rX| dkrXd} |dk sj|dk �rò|dk rztdƒ‚ˆj||f|tj||ˆd�IdH}|s¨tdƒ‚| dk r܈j| |tj||ˆd�IdH‰ˆsàtdƒ‚nd‰| rît|| ƒ}g‰| dk�rH|D]D}z ˆ ˆ|ˆ¡IdH}W�qvWntk �r@Y�qYnX�qn.tj‡‡‡fd d „|Dƒ| ˆd �IdH\}}}|dk�r d d „ˆDƒ‰t ˆƒdk�r¦ˆd‚nJt ˆdƒ‰t ‡fdd „ˆDƒƒ�rÒˆd‚td  d  dd „ˆDƒ¡¡ƒ‚n.|dk�rtdƒ‚|jtjk�r td|›�ƒ‚ˆj|||| | d�IdH\}}ˆj�rd| d¡}t d|||||¡||fS)aöConnect 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 hostú1ssl_handshake_timeout is only meaningful with sslrú8host/port and sock can not be specified at the same time©r=r>r?r)r‰ú!getaddrinfo() returned empty listc3s |]}t ˆjˆ|ˆ¡VqdSrB)Ú functoolsÚpartialrS)rCr,)rÚ laddr_infosrfrrrEùs þÿz2BaseEventLoop.create_connection..rŸcSsg|]}|D]}|‘q qSrr)rCÚsubrWrrrrñÿsz3BaseEventLoop.create_connection..rc3s|]}t|ƒˆkVqdSrB©r©rCrW)ÚmodelrrrEszMultiple exceptions: {}r%css|]}t|ƒVqdSrBr`rarrrrE sz5host and port was not specified and no sock specifiedú"A Stream Socket was expected, got )r�r$z%r connected to %s:%r: (%r, %r))r%Ú_ensure_resolvedr$r1r(rPrSr Zstaggered_racerórÚallrHr&r>Ú_create_connection_transportrÿÚget_extra_inforr )rfr‹r;r<rTr=r?r)r*rUrÏr�rVrWÚinfosr,rRrnrÌr)rr^rbrfrÚcreate_connection¨s¾   ÿÿþ ý    ÿ  þü   ÿ ÿÿþ ÿzBaseEventLoop.create_connectionc Ãs„| d¡|ƒ}| ¡}|rHt|tƒr*dn|} |j||| ||||d�} n| |||¡} z|IdHWn|  ¡‚YnX| |fS)NF©rÎrÏr�)rKrdrÚboolrÒrÍrž) rfr*r‹rTrÏrÎr�rÌr˜rÑrnrrrrf%s* ýz*BaseEventLoop._create_connection_transportc Ãs²| ¡rtdƒ‚t|dtjjƒ}|tjjkr:td|›�ƒ‚|tjjkrŠz| ||||¡IdHWStj k rˆ}z |sx‚W5d}~XYnX|sœtd|›�ƒ‚|  ||||¡IdHS)a„Send 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 ) rirmrrZ _SendfileModeZ UNSUPPORTEDZ TRY_NATIVEÚ_sendfile_nativerr4Ú_sendfile_fallback)rfrnr6r7r8r1rGrWrrrÚsendfile?s4ÿ ÿ ÿ ÿÿzBaseEventLoop.sendfilecÃst d¡‚dS)Nz!sendfile syscall is not supportedr:)rfrgr6r7r8rrrrlnsÿzBaseEventLoop._sendfile_nativec Ãsì|r| |¡|rt|dƒnd}t|ƒ}d}t|ƒ}z‚|rXt|||ƒ}|dkrX|W¢bSt|ƒd|…} | d|j| ¡IdH} | sŠ|W¢0S|  ¡IdH|  | d| …¡|| 7}q6W5|dkrØt|dƒrØ| ||¡| ¡IdHXdS)Ni@rr<) r<r=r>r\r#r{r?rr@rkÚwrite) rfrgr6r7r8rArBrCr?rDrErrrrmrs* z BaseEventLoop._sendfile_fallbackrjc ÃsØtdkrtdƒ‚t|tjƒs*td|›�ƒ‚t|ddƒsFtd|›d�ƒ‚| ¡}tj|||||||dd�}|  ¡|  |¡|  |j |¡} |  |j ¡} z|IdHWn.tk rÐ| ¡|  ¡|  ¡‚YnX|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())r�rÐ)rTrmrZ SSLContextr5rrdr Z SSLProtocolrarbrroryÚ BaseExceptionržrzZ_app_transport) rfrnrÌrÑrÎrÏr�r˜Z ssl_protocolZ conmade_cbZ resume_cbrrrÚ start_tls‹sB  ÿ  ÿü  zBaseEventLoop.start_tls)r=r?r)Ú reuse_addressÚ reuse_portÚallow_broadcastr*c ƒs| dk r�| jtjkr"td| ›�ƒ‚ˆs>ˆs>|s>|s>|s>|s>| r~tˆˆ|||||| d�} d dd„|  ¡Dƒ¡} td| ›d�ƒ‚|  d ¡d} �nˆsºˆsº|d kr¨td ƒ‚||fd ff}�n°ttd ƒ�rŒ|tj k�rŒˆˆfD]}|dk rÚt |t ƒsÚt dƒ‚qÚˆ�rxˆd dk�rxz"t  t  ˆ¡j¡�r.t ˆ¡WnFtk �rFYn2tk �rv}zt dˆ|¡W5d}~XYnX||fˆˆfff}nÞi}d ˆfdˆffD]¢\}}|dk �r t |tƒ�rÌt|ƒdk�sÔtdƒ‚|j||tj|||d�IdH}|�stdƒ‚|D]:\}}}}}||f}||k�r0ddg||<||||<�q�q ‡‡fdd„| ¡Dƒ}|�sjtdƒ‚g}|tk �r˜|�rˆtdƒ‚ntjdtdd�|D]ø\\}}\}}d} d} zxtj|tj|d�} |�rÖt| ƒ| �rî|  tj tj!d¡|  d ¡ˆ�r|  "|¡ˆ�r*| �s&| #| |¡IdH|} Wn^tk �rl}z | dk �rR|  $¡| %|¡W5d}~XYn&| dk �r„|  $¡‚YnX�qž�qœ|d ‚|ƒ}| &¡}| '| || |¡}|j(�rîˆ�rÞt )dˆˆ||¡nt *dˆ||¡z|IdHWn| $¡‚YnX||fS)zCreate datagram connection.NzA UDP Socket was expected, got )rUÚ remote_addrr=r?r)rrrsrtr%css$|]\}}|r|›d|›�VqdS)ú=Nr)rCÚkÚvrrrrEËsz9BaseEventLoop.create_datagram_endpoint..zKsocket modifier keyword arguments can not be used when sock is specified. (ú)Frzunexpected address family)NNÚAF_UNIXzstring is expected)rúz2Unable to check or remove stale UNIX socket %r: %rrr!z2-tuple is expectedrZr[cs8g|]0\}}ˆr|ddksˆr,|ddks||f‘qS)rNrr)rCÚkeyZ addr_pair©rUrurrrñþs   þz: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.)Ú stacklevelrIz@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))+r>r$r2r%Údictr&ÚitemsrKr#rzrrr5ÚstatÚS_ISSOCKÚosÚst_modeÚremoveÚFileNotFoundErrorr(rÚerrorr�rór’rdÚ_unsetrìrír"r+r&r'Z SO_BROADCASTrLrQržr9rdrÔrÿr(r ) rfr‹rUrur=r?r)rrrsrtr*ZoptsZproblemsZr_addrZaddr_pairs_inforOÚerrZ addr_infosÚidxrhZfamrRZprorÓr|rZ local_addressZremote_addressrWrÌr˜rnrr}rÚcreate_datagram_endpoint¹s* ÿÿÿÿþþý ÿ   þÿ ÿþ    ÿ  ýÿ ÿÿ     ÿþþz&BaseEventLoop.create_datagram_endpointc Ãs\|dd…\}}t|||||f|dd…žŽ} | dk r<| gS|j||||||d�IdHSdS)Nr!r/)rAr') rfrÓr=r>r?r)r‰r;r<r(rrrrdLs ÿzBaseEventLoop._ensure_resolvedcÃs8|j||f|tj||d�IdH}|s4td|›d�ƒ‚|S)N)r=r>r)r‰z getaddrinfo(z) returned empty list)rdr$r1r()rfr;r<r=r)rhrrrÚ_create_server_getaddrinfoXs þ z(BaseEventLoop._create_server_getaddrinfor) r=r)r*rŒrTrrrsr�r¡c  ƒs¸t|tƒrtdƒ‚| dk r*|dkr*tdƒ‚|dk s<ˆdk �r"|dk rLtdƒ‚| dkrhtjdkoftjdk} g} |dkr|dg}n$t|tƒs”t|t j j ƒsœ|g}n|}‡‡‡‡fdd „|Dƒ}t j |d ˆiŽIdH}ttj |¡ƒ}d }�z|D�]}|\}}}}}zt |||¡}Wn8tjk �rHˆj�r@tjd |||d d�YqêYnX|  |¡| �rl| tjtjd ¡| �rzt|ƒt�rª|tjk�rªttdƒ�rª| tj tj!d ¡z| "|¡Wqêt#k �rø}z t#|j$d||j% &¡fƒd‚W5d}~XYqêXqêd }W5|�s| D]}| ¡�qXn4|dk�r4tdƒ‚|j'tj(k�rPtd|›�ƒ‚|g} | D]}| )d ¡�qZt*ˆ| |||| ƒ}| �r | +¡t j,dˆd�IdHˆj�r´t -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 NoneNrXrYÚposixÚcygwinr.csg|]}ˆj|ˆˆˆd�‘qS))r=r))rŒ)rCr;©r=r)r<rfrrrñ’sþ ÿz/BaseEventLoop.create_server..r‰Fz:create_server() failed to create socket.socket(%r, %r, %r)T©Úexc_infoÚ IPPROTO_IPV6z0error while attempting to bind on address %r: %sz)Neither host/port nor sock were specifiedrcrrŸz %r is serving).rrkr5r%rƒr¾rÚplatformrrFÚabcÚIterabler rõÚsetrKrLrMržr$r‡rÿrÚwarningr9r&r'Z SO_REUSEADDRr+r8rr#r’Z IPV6_V6ONLYrLr(rOrMrNr>r1rKrr™r r()rfr‹r;r<r=r)r*rŒrTrrrsr�r¡rŠZhostsZfsrhZ completedÚresr@Zsocktyper?Z canonnameZsar‰rÉrr�rÚ create_server`s² ÿÿ  ÿþ þ  ÿÿþþ þþ ÿ zBaseEventLoop.create_server)rTr�cÃsv|jtjkrtd|›�ƒ‚|dk r.|s.tdƒ‚|j|||dd|d�IdH\}}|jrn| 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. rcNrXr.T)rÎr�r$z%r handled: (%r, %r)) r>r$r1r%rfrÿrgrr )rfr‹r*rTr�rnrÌrrrÚconnect_accepted_socketÕs$  ÿþ z%BaseEventLoop.connect_accepted_socketcÃsd|ƒ}| ¡}| |||¡}z|IdHWn| ¡‚YnX|jr\t d| ¡||¡||fS)Nz Read pipe %r connected: (%r, %r))rdr×ržrÿrr Úfileno©rfr‹rÖrÌr˜rnrrrÚconnect_read_pipeòsÿzBaseEventLoop.connect_read_pipecÃsd|ƒ}| ¡}| |||¡}z|IdHWn| ¡‚YnX|jr\t d| ¡||¡||fS)Nz!Write pipe %r connected: (%r, %r))rdrØržrÿrr r›rœrrrÚconnect_write_pipesÿz BaseEventLoop.connect_write_pipecCs–|g}|dk r"| dt|ƒ›�¡|dk rJ|tjkrJ| dt|ƒ›�¡n8|dk rf| dt|ƒ›�¡|dk r‚| dt|ƒ›�¡t d |¡¡dS)Nzstdin=zstdout=stderr=zstdout=zstderr=ú )r9r!rrrr r&)rfr*rÛrÜrÝr(rrrÚ_log_subprocessszBaseEventLoop._log_subprocess) rÛrÜrÝÚuniversal_newlinesrÚrÞÚencodingÚerrorsÚtextc ËsÖt|ttfƒstdƒ‚|r"tdƒ‚|s.tdƒ‚|dkr>tdƒ‚| rJtdƒ‚| dk rZtdƒ‚| dk rjtdƒ‚|ƒ} d}|jr’d |}| ||||¡|j| |d ||||f| ŽIdH}|jrÎ|dk rÎt d ||¡|| fS) Nzcmd must be a stringú universal_newlines must be Falsezshell must be Truerúbufsize must be 0útext must be Falseúencoding must be Noneúerrors must be Nonezrun shell command %rTú%s: %r) rr3rr%rÿr ràrr()rfr‹ÚcmdrÛrÜrÝr¡rÚrÞr¢r£r¤rßrÌÚ debug_logrnrrrÚsubprocess_shellsBÿÿ zBaseEventLoop.subprocess_shellc ÏsÌ|r tdƒ‚|rtdƒ‚|dkr(tdƒ‚| r4tdƒ‚| dk rDtdƒ‚| dk rTtdƒ‚|f| }|ƒ}d}|jrˆd|›�}| ||||¡|j||d ||||f| ŽIdH}|jrÄ|dk rÄt d ||¡||fS) Nr¥zshell must be Falserr¦r§r¨r©zexecute program Frª)r%rÿr ràrr()rfr‹ZprogramrÛrÜrÝr¡rÚrÞr¢r£r¤rÙrßZ popen_argsrÌr¬rnrrrÚsubprocess_execCs@  þþ zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use. )r±rqrrrÚget_exception_handleresz#BaseEventLoop.get_exception_handlercCs(|dk rt|ƒstd|›�ƒ‚||_dS)a³Set 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 )rÄr5r±)rfZhandlerrrrÚset_exception_handlerjs z#BaseEventLoop.set_exception_handlerc Cs| d¡}|sd}| d¡}|dk r6t|ƒ||jf}nd}d|kr`|jdk r`|jjr`|jj|d<|g}t|ƒD]†}|dkr|qn||}|dkr®d  t |¡¡}d }||  ¡7}n2|dkrØd  t |¡¡}d }||  ¡7}nt |ƒ}|  |›d |›�¡qnt j d  |¡|d�dS)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()`. ròz!Unhandled exception in event looprRNFZsource_tracebackZhandle_traceback>ròrRr.z+Object created at (most recent call last): z+Handle created at (most recent call last): rJÚ r�)Úgetr>Ú __traceback__r´rÁÚsortedr&Ú tracebackÚ format_listÚrstriprr9rr‡) rfr ròrRr‘Z log_linesr|ÚvalueÚtbrrrÚdefault_exception_handler{s<  ÿþÿ z'BaseEventLoop.default_exception_handlerc Csø|jdkrVz| |¡Wqôttfk r2‚Yqôtk rRtjddd�YqôXnžz| ||¡WnŒttfk r€‚Ynttk rò}zVz| d||dœ¡Wn:ttfk rÀ‚Yn"tk ràtjddd�YnXW5d}~XYnXdS)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 handlerTr�z$Unhandled error in exception handler)ròrRr zeException in default exception handler while handling an unexpected error in custom exception handler)r±rºrSrTrprr‡)rfr rWrrrrø­s4 ÿý ýz$BaseEventLoop.call_exception_handlercCs>t|tjƒstdƒ‚|jrdSt|tjƒr.t‚|j |¡dS)z3Add a Handle to _scheduled (TimerHandle) or _ready.zA Handle is required hereN)rrrr’Ú _cancelledrrªr9©rfrrrrÚ _add_callbackæs zBaseEventLoop._add_callbackcCs| |¡| ¡dS)z6Like _add_callback() but called from a signal handler.N)r½rár¼rrrÚ_add_callback_signalsafeîs z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)r«r¦r¼rrrÚ_timer_handle_cancelledósz%BaseEventLoop._timer_handle_cancelledc CsÒt|jƒ}|tkr`|j|tkr`g}|jD]}|jrsd                  ;   Do