grthtrhthjhtyjytjytkergtrhtrjytjerhrfh3 \àã@sŠdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZd gZd Zd ZeeefZ e!e dƒZ"d)Z#dd„Z$dd„Z%dd„Z&dd„Z'dd„Z(dd„Z)de j*dddœdd„Z+e!e d ƒ�rRd!d"„Z,nd#d"„Z,d$d%„Z-Gd&d'„d'ej.ƒZ/Gd(d „d ej0ƒZ1dS)*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é)Úcompat)Ú coroutines)Úevents)Úfutures)Útasks)Ú coroutine)ÚloggerÚ BaseEventLoopédgà?ÚAF_INET6éicCs0|j}tt|ddƒtjƒr$t|jƒSt|ƒSdS)NÚ__self__)Z _callbackÚ isinstanceÚgetattrrÚTaskÚreprrÚstr)ÚhandleÚcb©rú+/usr/lib64/python3.6/asyncio/base_events.pyÚ_format_handle?s rcCs(|tjkrdS|tjkrdSt|ƒSdS)Nzz)Ú subprocessÚPIPEÚSTDOUTr)ÚfdrrrÚ _format_pipeHs   rc CsLttdƒstdƒ‚n4y|jtjtjdƒ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_reuseportQs   r&cCs&ttdƒr|d@tjkS|tjkSdS)NÚ SOCK_NONBLOCKé)rr Ú SOCK_STREAM)Ú sock_typerrrÚ_is_stream_socket\s r+cCs&ttdƒr|d@tjkS|tjkSdS)Nr'r()rr Ú SOCK_DGRAM)r*rrrÚ_is_dgram_sockeths r-cCsvttdƒsdS|dtjtjhks(|dkr,dSt|ƒrt|tƒrŽ|dkrŽd}n&y t |ƒ}Wnt t fk r²dSX|tj krØtj g}trÞ|jtjƒn|g}t|tƒrò|jdƒ}d|k�rdSxp|D]h}yJtj||ƒt�r@|tjk�r@|||d||ddffS|||d||ffSWntk �rjYnX�qWdS)NÚ inet_ptonróÚZidnaú%)rr Ú IPPROTO_TCPZ IPPROTO_UDPr+r-rÚbytesrÚintÚ TypeErrorr!Ú AF_UNSPECÚAF_INETÚ _HAS_IPv6Úappendr Údecoder.r$)ÚhostÚportÚfamilyÚtypeÚprotoZafsÚafrrrÚ _ipaddr_infopsL         rA)r=r>r?Úflagsc CsZ|dd…\}}t|||||ƒ}|dk r@|jƒ} | j|gƒ| S|j||||||d�SdS)Né)r=r>r?rB)rAÚ create_futureÚ set_resultÚ getaddrinfo) Úaddressr=r>r?rBÚloopr;r<ÚinfoÚfutrrrÚ_ensure_resolved«s  rKÚ TCP_NODELAYcCs>|jtjtjhkr:t|jƒr:|jtjkr:|jtjtj dƒdS)Nr) r=r r7r r+r>r?r2r"rL)r%rrrÚ _set_nodelayºs  rMcCsdS)Nr)r%rrrrMÀscCs.|j}t|tƒr t|tƒ r dS|jjƒdS)N)Z _exceptionrÚ BaseExceptionÚ ExceptionÚ_loopÚstop)rJÚexcrrrÚ_run_until_complete_cbÄs   rSc@sHeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Ze d d„ƒZ dS)ÚServercCs||_||_d|_g|_dS)Nr)rPÚsocketsÚ _active_countÚ_waiters)ÚselfrHrUrrrÚ__init__ÐszServer.__init__cCsd|jj|jfS)Nz<%s sockets=%r>)Ú __class__Ú__name__rU)rXrrrÚ__repr__ÖszServer.__repr__cCs |jdk st‚|jd7_dS)Nr)rUÚAssertionErrorrV)rXrrrÚ_attachÙszServer._attachcCs<|jdkst‚|jd8_|jdkr8|jdkr8|jƒdS)Nrr)rVr]rUÚ_wakeup)rXrrrÚ_detachÝszServer._detachcCsH|j}|dkrdSd|_x|D]}|jj|ƒqW|jdkrD|jƒdS)Nr)rUrPZ _stop_servingrVr_)rXrUr%rrrÚcloseãs  z Server.closecCs0|j}d|_x|D]}|jƒs|j|ƒqWdS)N)rWÚdonerE)rXÚwaitersÚwaiterrrrr_ís  zServer._wakeupccs<|jdks|jdkrdS|jjƒ}|jj|ƒ|EdHdS)N)rUrWrPrDr9)rXrdrrrÚ wait_closedôs   zServer.wait_closedN) r[Ú __module__Ú __qualname__rYr\r^r`rar_rrerrrrrTÎs rTc @sÆeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd†d d dœdd„Z d‡dd d d dœdd„Z dˆdd„Z d‰dd„Z dŠdd„Z ed‹dd„ƒZdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zed'd(„ƒZd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zej�rød3d4„Zd5d6„Zd7d8„Zd9d:„Z d;d<„Z!d=d>„Z"d?d@„Z#dAdB„Z$dCdD„Z%dEdF„Z&dGdH„Z'dIdJ„Z(dKdL„Z)dMdMdMdMdNœdOdP„Z*dŒdQdR„Z+ed�d dMdMdMd d d dSœdTdU„ƒZ,edŽdVdW„ƒZ-ed�dMdMdMd d d d dXœdYdZ„ƒZ.ed[d\„ƒZ/ed�e0j1e0j2d d]d d d d^œd_d`„ƒZ3ed daœdbdc„ƒZ4eddde„ƒZ5edfdg„ƒZ6dhdi„Z7ee8j9e8j9e8j9ddjdMdkœdldm„ƒZ:ee8j9e8j9e8j9dddMdkœdndo„ƒZ;dpdq„Zdvdw„Z?dxdy„Z@dzd{„ZAd|d}„ZBd~d„ZCd€d�„ZDd‚dƒ„ZEd„d…„ZFd S)‘r cCs¦d|_d|_d|_tjƒ|_g|_d|_d|_d|_ t j dƒj |_ d|_|jtjj odttjjdƒƒƒd|_d|_d|_d|_ttdƒr–tjƒ|_nd|_d|_dS)NrFÚ monotonicZPYTHONASYNCIODEBUGgš™™™™™¹?Úget_asyncgen_hooks) Ú_timer_cancelled_countÚ_closedÚ _stoppingÚ collectionsÚdequeÚ_readyÚ _scheduledÚ_default_executorZ _internal_fdsÚ _thread_idÚtimeZget_clock_infoZ resolutionÚ_clock_resolutionÚ_exception_handlerÚ set_debugÚsysrBÚignore_environmentÚboolÚosÚenvironÚgetÚslow_callback_durationÚ_current_handleÚ _task_factoryÚ_coroutine_wrapper_setrÚweakrefÚWeakSetÚ _asyncgensÚ_asyncgens_shutdown_called)rXrrrrYÿs(   zBaseEventLoop.__init__cCs d|jj|jƒ|jƒ|jƒfS)Nz"<%s running=%s closed=%s debug=%s>)rZr[Ú is_runningÚ is_closedÚ get_debug)rXrrrr\ s zBaseEventLoop.__repr__cCs tj|d�S)z,Create a Future object attached to the loop.)rH)rZFuture)rXrrrrD%szBaseEventLoop.create_futurecCs@|jƒ|jdkr0tj||d�}|jr<|jd=n |j||ƒ}|S)zDSchedule a coroutine object. Return a task object. N)rHréÿÿÿÿ)Ú _check_closedrrrÚ_source_traceback)rXÚcoroZtaskrrrÚ create_task)s   zBaseEventLoop.create_taskcCs$|dk rt|ƒ rtdƒ‚||_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)rXÚfactoryrrrÚset_task_factory7s zBaseEventLoop.set_task_factorycCs|jS)z—sz4BaseEventLoop.shutdown_asyncgens..)Zreturn_exceptionsrHz?an error occurred during closing of asynchronous generator {!r})ÚmessageÚ exceptionZasyncgen) r„rƒÚlenÚlistÚclearrÚgatherÚziprrOÚcall_exception_handlerr²)rXZ closing_agensZ shutdown_coroZresultsÚresultr­rrrÚshutdown_asyncgens‰s"      z BaseEventLoop.shutdown_asyncgensc CsÆ|jƒ|jƒrtdƒ‚tjƒdk r,tdƒ‚|j|jƒtjƒ|_ |j dk rft j ƒ}t j |j|jd�z$tj|ƒx|jƒ|jrtPqtWWdd|_d|_ tjdƒ|jdƒ|j dk rÀt j |ŽXdS)zRun until stop() is called.z"This event loop is already runningNz7Cannot run the event loop while another loop is running)Ú firstiterÚ finalizerF)r‰r…r©rZ_get_running_loopÚ_set_coroutine_wrapperÚ_debugÚ threadingÚ get_identrrrƒrwriÚset_asyncgen_hooksrµr®Z_set_running_loopÚ _run_oncerl)rXZold_agen_hooksrrrÚ run_forever¥s0          zBaseEventLoop.run_forevercCsš|jƒtj|ƒ }tj||d�}|r,d|_|jtƒz>y |jƒWn,|rj|j ƒrj|j ƒ rj|j ƒ‚YnXWd|j tƒX|j ƒs’t dƒ‚|jƒ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. )rHFNz+Event loop stopped before Future completed.)r‰rZisfuturerZ ensure_futureZ_log_destroy_pendingZadd_done_callbackrSrÊrbZ cancelledr¹Zremove_done_callbackr©rÀ)rXZfutureZnew_taskrrrÚrun_until_completeÁs      z BaseEventLoop.run_until_completecCs d|_dS)z´Stop running the event loop. Every callback already scheduled will still run. This simply informs run_forever to stop looping after a complete iteration. TN)rl)rXrrrrQæszBaseEventLoop.stopcCsj|jƒrtdƒ‚|jrdS|jr,tjd|ƒd|_|jjƒ|jjƒ|j }|dk rfd|_ |j dd�dS)z¾Close 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 %rTF)Úwait) r…r©rkrÅr Údebugror¼rprqZshutdown)rXÚexecutorrrrraîs   zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)rk)rXrrrr†szBaseEventLoop.is_closedcCs0|jƒs,tjd|t|d�|jƒs,|jƒdS)Nzunclosed event loop %r)r¯)r†r°r±r³r…ra)rXrrrÚ__del__ s  zBaseEventLoop.__del__cCs |jdk S)z*Returns True if the event loop is running.N)rr)rXrrrr…szBaseEventLoop.is_runningcCstjƒS)zçReturn 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. )rsrh)rXrrrrsszBaseEventLoop.timecGs,|j|jƒ||f|žŽ}|jr(|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_atrsrŠ)rXZdelayÚcallbackržÚtimerrrrÚ call_later szBaseEventLoop.call_latercGsX|jƒ|jr"|jƒ|j|dƒtj||||ƒ}|jr@|jd=tj|j |ƒd|_ |S)z|Like call_later(), but uses an absolute time. Absolute time corresponds to the event loop's time() method. rÐrTrˆ) r‰rÅÚ _check_threadÚ_check_callbackrÚ TimerHandlerŠÚheapqÚheappushrp)rXÚwhenrÑržrÒrrrrÐ5s zBaseEventLoop.call_atcGs@|jƒ|jr"|jƒ|j|dƒ|j||ƒ}|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_soonrrˆ)r‰rÅrÔrÕÚ _call_soonrŠ)rXrÑržrrrrrÚEs   zBaseEventLoop.call_sooncCs>tj|ƒstj|ƒr"tdj|ƒƒ‚t|ƒs:tdj||ƒƒ‚dS)Nz#coroutines cannot be used with {}()z0a callable object was expected by {}(), got {!r})rZ iscoroutineZiscoroutinefunctionr5r²r�)rXrÑÚmethodrrrrÕXs   zBaseEventLoop._check_callbackcCs,tj|||ƒ}|jr|jd=|jj|ƒ|S)Nrrˆ)rÚHandlerŠror9)rXrÑržrrrrrÛcs  zBaseEventLoop._call_sooncCs,|jdkrdStjƒ}||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)rrrÆrÇr©)rXZ thread_idrrrrÔjs  zBaseEventLoop._check_threadcGs@|jƒ|jr|j|dƒ|j||ƒ}|jr4|jd=|jƒ|S)z"Like call_soon(), but thread-safe.r«rrˆ)r‰rÅrÕrÛrŠr¦)rXrÑržrrrrr«{s  z"BaseEventLoop.call_soon_threadsafecGsZ|jƒ|jr|j|dƒ|dkr@|j}|dkr@tjjƒ}||_tj|j|f|žŽ|d�S)NÚrun_in_executor)rH) r‰rÅrÕrqÚ concurrentrZThreadPoolExecutorZ wrap_futureZsubmit)rXrÎÚfuncržrrrrÞ†s  zBaseEventLoop.run_in_executorcCs ||_dS)N)rq)rXrÎrrrÚset_default_executor‘sz"BaseEventLoop.set_default_executorc CsÊd||fg}|r |jd|ƒ|r2|jd|ƒ|rD|jd|ƒ|rV|jd|ƒdj|ƒ}tjd|ƒ|jƒ}tj||||||ƒ} |jƒ|} d|| d | f}| |jkr¼tj|ƒn tj|ƒ| S) Nz%s:%rz family=%rztype=%rzproto=%rzflags=%rz, zGet address info %sz(Getting address info %s took %.3f ms: %rg@�@) r9Újoinr rÍrsr rFr}rI) rXr;r<r=r>r?rBÚmsgÚt0ZaddrinfoÚdtrrrÚ_getaddrinfo_debug”s(      z BaseEventLoop._getaddrinfo_debugr)r=r>r?rBc Cs>|jr |jd|j||||||ƒS|jdtj||||||ƒSdS)N)rÅrÞrær rF)rXr;r<r=r>r?rBrrrrF­s   zBaseEventLoop.getaddrinfocCs|jdtj||ƒS)N)rÞr Ú getnameinfo)rXZsockaddrrBrrrrç¶szBaseEventLoop.getnameinfo)Ússlr=r?rBr%Ú local_addrr—c#s| dk r| rtdƒ‚| dkr2|r2|s.tdƒ‚|} |dk sD|dk �rž|dk rTtdƒ‚t||f|tj|||d�} | g} | dk ržt| |tj|||d�} | j| ƒnd} tj| |d�EdH| jƒ}|sÊtdƒ‚| dk ræ| jƒ}|sætdƒ‚g}�xÜ|D�]B\}}}}}yÒtj|||d�}|j d ƒ| dk �rªx€|D]j\}}}}}y|j |ƒPWnHtk �r”}z*t|j d j ||j jƒƒƒ}|j|ƒWYdd}~XnX�q.W|jƒd}wò|j�rÀtjd ||ƒ|j||ƒEdHWn^tk �r}z"|dk �rú|jƒ|j|ƒWYdd}~Xqò|dk �r,|jƒ‚YqòXPqòWt|ƒd k�rR|d ‚nJt|d ƒ‰t‡fdd„|Dƒƒ�r~|d ‚tdj djdd„|Dƒƒƒƒ‚n,|dk�r°tdƒ‚t|jƒ�sÊtdj |ƒƒ‚|j|||| ƒEdH\}}|j�r |jdƒ}tjd|||||ƒ||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 hostz8host/port and sock can not be specified at the same time)r=r>r?rBrH)rHz!getaddrinfo() returned empty list)r=r>r?Fz2error while attempting to bind on address {!r}: {}zconnect %r to %rrrc3s|]}t|ƒˆkVqdS)N)r)r¶rR)Úmodelrrú sz2BaseEventLoop.create_connection..zMultiple exceptions: {}z, css|]}t|ƒVqdS)N)r)r¶rRrrrrë#sz5host and port was not specified and no sock specifiedz&A Stream Socket was expected, got {!r}r z%r connected to %s:%r: (%r, %r))r!rKr r)r9rrÌrÀr$Ú setblockingÚbindÚerrnor²ÚstrerrorÚlowerrarÅr rÍÚ sock_connectrºrÚallrâr+r>Ú_create_connection_transportÚget_extra_info)rXÚprotocol_factoryr;r<rèr=r?rBr%rér—Úf1ÚfsÚf2ÚinfosZ laddr_infosÚ exceptionsr>ZcnamerGÚ_ZladdrrRÚ transportr”r)rêrÚcreate_connection¹sœ        "        zBaseEventLoop.create_connectionc cs‚|jdƒ|ƒ}|jƒ}|rFt|tƒr*dn|}|j||||||d�} n|j|||ƒ} y|EdHWn| jƒ‚YnX| |fS)NF)r–r—)rìrDrryr™r•ra) rXr%rõrèr—r–r”rdr˜rürrrró=s  z*BaseEventLoop._create_connection_transport)r=r?rBÚ reuse_addressÚ reuse_portÚallow_broadcastr%c#sZ| dk r�t| jƒs tdj| ƒƒ‚ˆs@ˆs@|s@|s@|s@|s@|s@| r~tˆˆ|||||| d�} djdd„| jƒDƒƒ} tdj| ƒƒ‚| jdƒd} �nLˆp–ˆs¸|d kr¨td ƒ‚||fdff}nätj ƒ}x´d ˆfd ˆffD] \}}|dk rÒt |t ƒ�rüt |ƒd k�st d ƒ‚t||tj|||d�EdH}|�s.tdƒ‚xB|D]:\}}}}}||f}||k�r`ddg||<||||<�q4WqÒW‡‡fdd„|jƒDƒ}|�sœtdƒ‚g}|dk�rÀtjdk�o¾tjdk}�x|D�]\\}}\}}d} d} yŠtj|tj|d�} |�r| jtjtjd ƒ|�rt| ƒ| �r4| jtjtjd ƒ| jdƒˆ�rN| j|ƒˆ�rj|j| |ƒEdH|} Wn^tk �r¬}z"| dk �r’| jƒ|j|ƒWYdd}~Xn"| dk �rÄ| jƒ‚YnXP�qÈW|d ‚|ƒ}|jƒ}|j | || |ƒ}|j!�r,ˆ�rt"j#dˆˆ||ƒnt"j$dˆ||ƒy|EdHWn|jƒ‚YnX||fS)zCreate datagram connection.Nz#A UDP Socket was expected, got {!r})réÚ remote_addrr=r?rBrþrÿrz, css"|]\}}|rdj||ƒVqdS)z{}={}N)r²)r¶ÚkÚvrrrrëisz9BaseEventLoop.create_datagram_endpoint..zNsocket modifier keyword arguments can not be used when sock is specified. ({})Frzunexpected address familyrrCz2-tuple is expected)r=r>r?rBrHz!getaddrinfo() returned empty listcs8g|]0\}}ˆr|ddkp*ˆo*|ddks||f‘qS)rNrr)r¶ÚkeyZ addr_pair)rérrrr·Šsz:BaseEventLoop.create_datagram_endpoint..zcan not get address informationÚposixÚcygwin)r=r>r?z@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))NN)%r-r>r!r²ÚdictrâÚitemsrìrmÚ OrderedDictrÚtuplerºr]rKr r,r$rzÚnamerwÚplatformr"r#Ú SO_REUSEADDRr&Z SO_BROADCASTrírñrar9rDršrÅr rIrÍ)rXrõrérr=r?rBrþrÿrr%ZoptsZproblemsZr_addrZaddr_pairs_infoZ addr_infosÚidxZaddrrùZfamrûZprorGrrúZ local_addressZremote_addressrRr”rdrür)rérrÚcreate_datagram_endpointUs´              z&BaseEventLoop.create_datagram_endpointccs4t||f|tj||d�EdH}|s0tdj|ƒƒ‚|S)N)r=r>rBrHz%getaddrinfo({!r}) returned empty list)rKr r)r$r²)rXr;r<r=rBrùrrrÚ_create_server_getaddrinfoÏs  z(BaseEventLoop._create_server_getaddrinfor )r=rBr%Úbacklogrèrþrÿc #sšt|tƒrtdƒ‚|dk s$ˆdk �r|dk r4tdƒ‚| dkrPtjdkoNtjdk} g} |dkrddg} n$t|tƒs|t|t j ƒ r„|g} n|} ‡‡‡‡fdd„| Dƒ} t j | d ˆiŽEdH}t tjj|ƒƒ}d }�z �x|D�] }|\}}}}}ytj|||ƒ}Wn6tjk �r2ˆj�r,tjd |||d d �wÖYnX| j|ƒ| �rV|jtjtjd ƒ| �rdt|ƒt�r”|tjk�r”ttdƒ�r”|jtjtjd ƒy|j |ƒWqÖt!k �rà}z t!|j"d||j#j$ƒfƒ‚WYdd}~XqÖXqÖWd }Wd|�s x| D]}|j%ƒ�qúWXn2|dk�r"tdƒ‚t&|j'ƒ�s.rHFz: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 specifiedz&A Stream Socket was expected, got {!r}z %r is serving).rryr5r!rzr rwr rrmÚIterablerr½ÚsetÚ itertoolsÚchainÚ from_iterabler ÚerrorrÅr Úwarningr9r"r#r r&r8r rrZ IPV6_V6ONLYrír$rîrïrðrar+r>r²rTZlistenrìZ_start_servingrI)rXrõr;r<r=rBr%rrèrþrÿrUZhostsr÷rùZ completedÚresr@Zsocktyper?Z canonnameZsaÚerrr’r)r=rBr<rXrÚ create_serverØs‚     (         zBaseEventLoop.create_server)rèccs^t|jƒstdj|ƒƒ‚|j|||ddd�EdH\}}|jrV|jdƒ}tjd|||ƒ||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. z&A Stream Socket was expected, got {!r}r0T)r–Nr z%r handled: (%r, %r)) r+r>r!r²rórÅrôr rÍ)rXrõr%rèrür”rrrÚconnect_accepted_socketAs   z%BaseEventLoop.connect_accepted_socketc csd|ƒ}|jƒ}|j|||ƒ}y|EdHWn|jƒ‚YnX|jr\tjd|jƒ||ƒ||fS)Nz Read pipe %r connected: (%r, %r))rDrœrarÅr rÍÚfileno)rXrõr›r”rdrürrrÚconnect_read_pipeXszBaseEventLoop.connect_read_pipec csd|ƒ}|jƒ}|j|||ƒ}y|EdHWn|jƒ‚YnX|jr\tjd|jƒ||ƒ||fS)Nz!Write pipe %r connected: (%r, %r))rDr�rarÅr rÍr)rXrõr›r”rdrürrrÚconnect_write_pipeisz BaseEventLoop.connect_write_pipecCsŽ|g}|dk r |jdt|ƒƒ|dk rF|tjkrF|jdt|ƒƒn4|dk r`|jdt|ƒƒ|dk rz|jdt|ƒƒtjdj|ƒƒdS)Nzstdin=%szstdout=stderr=%sz stdout=%sz stderr=%sú )r9rrrr rÍrâ)rXrãr r¡r¢rIrrrÚ_log_subprocesszszBaseEventLoop._log_subprocessT)r r¡r¢Úuniversal_newlinesrŸr£c ksªt|ttfƒstdƒ‚|r"tdƒ‚|s.tdƒ‚|dkr>tdƒ‚|ƒ} d} |jrfd|} |j| |||ƒ|j| |d||||f| ŽEdH} |jr¢| dk r¢tjd| | ƒ| | fS) Nzcmd must be a stringz universal_newlines must be Falsezshell must be Truerzbufsize must be 0zrun shell command %rTz%s: %r) rr3rr!rÅr#r¥r rI) rXrõÚcmdr r¡r¢r$rŸr£r¤r”Ú debug_logrürrrÚsubprocess_shell‡s$zBaseEventLoop.subprocess_shellcosÌ|r tdƒ‚|rtdƒ‚|dkr(tdƒ‚|f| } x,| D]$} t| ttfƒs8tdt| ƒjƒ‚q8W|ƒ} d}|jrˆd|}|j||||ƒ|j | | d||||f| ŽEdH}|jrÄ|dk rÄt j d||ƒ|| fS) Nz universal_newlines must be Falsezshell must be Falserzbufsize must be 0z8program arguments must be a bytes or text string, not %szexecute program %rFz%s: %r) r!rrr3r5r>r[rÅr#r¥r rI)rXrõZprogramr r¡r¢r$rŸr£ržr¤Z popen_argsÚargr”r&rürrrÚsubprocess_exec¡s,   zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use. )ru)rXrrrÚget_exception_handlerÀsz#BaseEventLoop.get_exception_handlercCs*|dk r t|ƒ r tdj|ƒƒ‚||_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})r�r5r²ru)rXZhandlerrrrÚset_exception_handlerÅs z#BaseEventLoop.set_exception_handlerc Cs|jdƒ}|sd}|jdƒ}|dk r6t|ƒ||jf}nd}d|kr`|jdk r`|jjr`|jj|d<|g}x�t|ƒD]„}|dkr~qp||}|dkr°djtj|ƒƒ}d }||j ƒ7}n2|dkrÚdjtj|ƒƒ}d }||j ƒ7}nt |ƒ}|j d j ||ƒƒqpWt jd j|ƒ|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 loopr¹NFZsource_tracebackZhandle_tracebackr0z+Object created at (most recent call last): z+Handle created at (most recent call last): z{}: {}Ú )r>r¸r¹)r|r>Ú __traceback__r~rŠÚsortedrâÚ tracebackÚ format_listÚrstriprr9r²r r) rXÚcontextr¸r¹rZ log_linesrÚvalueÚtbrrrÚdefault_exception_handlerÖs6    z'BaseEventLoop.default_exception_handlercCs°|jdkr>y|j|ƒWq¬tk r:tjddd�Yq¬Xnny|j||ƒWn\tk rª}z@y|jd||dœƒWn"tk r˜tjddd�YnXWYdd}~XnXdS)aCall 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; - '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 handlerT)rz$Unhandled error in exception handler)r¸r¹r2zeException in default exception handler while handling an unexpected error in custom exception handler)rur5rOr r)rXr2rRrrrr¿s" z$BaseEventLoop.call_exception_handlercCs@t|tjƒstdƒ‚|jrdSt|tjƒ s0t‚|jj|ƒdS)z3Add a Handle to _scheduled (TimerHandle) or _ready.zA Handle is required hereN)rrrÝr]Ú _cancelledrÖror9)rXrrrrÚ _add_callback9s zBaseEventLoop._add_callbackcCs|j|ƒ|jƒdS)z6Like _add_callback() but called from a signal handler.N)r7r¦)rXrrrrÚ_add_callback_signalsafeAs z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)rprj)rXrrrrÚ_timer_handle_cancelledFsz%BaseEventLoop._timer_handle_cancelledc Cs˜t|jƒ}|tkrd|j|tkrdg}x&|jD]}|jr>d|_q,|j|ƒq,Wtj|ƒ||_d|_n8x6|jrš|jdjrš|jd8_tj |jƒ}d|_qfWd}|j s¬|j r²d}n*|jrÜ|jdj }t td||jƒƒtƒ}|joè|dk�r’|jƒ}|jj|ƒ}|jƒ|}|dk�rtj} ntj} t|ƒ} |dk�rLtj| d|d| ƒnD| �rntj| d|d|d| ƒn"|dk�ržtj| d |d|dƒn |jj|ƒ}|j|ƒ|jƒ|j} xD|j�rú|jd}|j | k�rØPtj |jƒ}d|_|j j|ƒ�q¸Wt|j ƒ} xˆt| ƒD]|} |j jƒ}|j�r*�q|j�r‚zD||_|jƒ}|jƒ|jƒ|}||jk�rttj d t!|ƒ|ƒWdd|_Xn|jƒ�qWd}dS) zÕRun one full iteration of the event loop. This calls all currently ready callbacks, polls for I/O, schedules the resulting callbacks, and finally schedules 'call_later' callbacks. FrrNgð?zpoll took %.3f ms: %s eventsg@�@z$poll %.3f ms took %.3f ms: %s eventsz"poll %.3f ms took %.3f ms: timeoutzExecuting %s took %.3f seconds)"rºrpÚ_MIN_SCHEDULED_TIMER_HANDLESrjÚ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr6r9r×ÚheapifyÚheappoprorlZ_whenÚminÚmaxrsÚMAXIMUM_SELECT_TIMEOUTrÅZ _selectorZselectÚloggingÚINFOÚDEBUGr Úlogr¨rtÚrangeÚpopleftr~Z_runr}rr)rXZ sched_countZ new_scheduledrZtimeoutrÙrär§råÚlevelZneventZend_timeZntodoÚirrrrÉKsˆ                       zBaseEventLoop._run_oncec Csªytj}tj}Wntk r$dSXt|ƒ}|j|krsV            ;   /