ñÕYf‡Üã @sÿdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZd gZd Zd ZeeefZ dd„Z!dd„Z"dd„Z#dd„Z$dd„Z%dd„Z&ddde j'dddddd„Z(d d!„Z)Gd"d#„d#ej*ƒZ+Gd$d „d ej,ƒZ-dS)%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à?cCsH|j}tj|ƒr:t|jtjƒr:t|jƒSt|ƒSdS)N) Z _callbackÚinspectZismethodÚ isinstanceÚ__self__rÚTaskÚreprÚstr)ÚhandleÚcb©rú8/opt/alt/python35/lib64/python3.5/asyncio/base_events.pyÚ_format_handle:s $ rcCs4|tjkrdS|tjkr&dSt|ƒSdS)Nzz)Ú subprocessÚPIPEÚSTDOUTr)ÚfdrrrÚ _format_pipeCs rc Cs`ttdƒstdƒ‚n>y|jtjtjdƒWntk r[tdƒ‚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_reuseportLs  r$cCs|jtj@tjkS)N)ÚtyperÚ SOCK_STREAM)r#rrrÚ_is_stream_socketWsr'cCs|jtj@tjkS)N)r%rÚ SOCK_DGRAM)r#rrrÚ_is_dgram_socket^sr)cCsÏttdƒsdS|dtjtjhks:|dkr>dS|tjkrYtj}n|tjkrttj}ndS|dkr�d}nwt|tƒr±|dkr±d}nSt|tƒrÕ|dkrÕd}n/yt |ƒ}Wnt t fk rdSYnX|tj krAtj g}ttdƒrJ|jtjƒn |g}t|tƒrh|jdƒ}d|krxdSxP|D]H}y-tj||ƒ|||d||ffSWqtk rÆYqXqWdS)NÚ inet_ptonróÚÚAF_INET6Zidnaú%)rrZ IPPROTO_TCPZ IPPROTO_UDPr&r(r ÚbytesrÚintÚ TypeErrorrÚ AF_UNSPECZAF_INETÚappendr-Údecoder*r")ÚhostÚportÚfamilyr%ÚprotoZafsÚafrrrÚ _ipaddr_infoesH              r:r7r%r8Úflagsc Cs†|dd…\}}t|||||ƒ}|dk rZ|jƒ} | j|gƒ| S|j||d|d|d|d|ƒSdS)Nér7r%r8r;)r:Ú create_futureÚ set_resultÚ getaddrinfo) Úaddressr7r%r8r;Úloopr5r6ÚinfoÚfutrrrÚ_ensure_resolved¢s  rDcCs=|j}t|tƒr,t|tƒ r,dS|jjƒdS)N)Z _exceptionr Ú BaseExceptionÚ ExceptionÚ_loopÚstop)rCÚexcrrrÚ_run_until_complete_cb°s  rJc@sjeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Ze d d„ƒZ dS)ÚServercCs(||_||_d|_g|_dS)Nr)rGÚsocketsÚ _active_countÚ_waiters)ÚselfrArLrrrÚ__init__¼s   zServer.__init__cCsd|jj|jfS)Nz<%s sockets=%r>)Ú __class__Ú__name__rL)rOrrrÚ__repr__ÂszServer.__repr__cCs(|jdk st‚|jd7_dS)Nr)rLÚAssertionErrorrM)rOrrrÚ_attachÅszServer._attachcCsP|jdkst‚|jd8_|jdkrL|jdkrL|jƒdS)Nrr)rMrTrLÚ_wakeup)rOrrrÚ_detachÉszServer._detachcCs`|j}|dkrdSd|_x|D]}|jj|ƒq)W|jdkr\|jƒdS)Nr)rLrGZ _stop_servingrMrV)rOrLr#rrrÚcloseÏs    z Server.closecCs@|j}d|_x'|D]}|jƒs|j|ƒqWdS)N)rNÚdoner>)rOÚwaitersÚwaiterrrrrVÙs     zServer._wakeupccsN|jdks|jdkr"dS|jjƒ}|jj|ƒ|EdHdS)N)rLrNrGr=r3)rOr[rrrÚ wait_closedàs zServer.wait_closedN) rRÚ __module__Ú __qualname__rPrSrUrWrXrVrr\rrrrrKºs      rKc@s‡eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd dd dd dd„Z d dddd dd dd dd„Z d d d dd„Z d d dd„Z d d dd„Z ed dd„ƒZdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zed)d*„ƒZd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zejrƒd5d6„Zd7d8„Zd9d:„Zd;d<„Z d=d>„Z!d?d@„Z"dAdB„Z#dCdD„Z$dEdF„Z%dGdH„Z&dIdJ„Z'dKdL„Z(dMdN„Z)dOdPdQdPdRdPdSdPdTdU„Z*dPdVdW„Z+ed d dXd dOdPdRdPdSdPdYd dZd dd d[d\„ƒZ,edd]d^„ƒZ-ed d dOdPdRdPdSdPd_d d`d dad dYd dbdc„ƒZ.eddde„ƒZ/ed d dOe0j1dSe0j2dYd dfdgdXd d_d d`d dhdi„ƒZ3edXd djdk„ƒZ4edldm„ƒZ5edndo„ƒZ6dpdq„Z7edre8j9dse8j9dte8j9duddvdwdxdPdydz„ƒZ:edre8j9dse8j9dte8j9duddvddxdPd{d|„ƒZ;d}d~„Z<dd€„Z=d�d‚„Z>dƒd„„Z?d…d†„Z@d‡dˆ„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 o”ttjjdƒƒƒd|_d|_d|_d|_ttdƒrÝtjƒ|_n d|_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Úsysr;Úignore_environmentÚboolÚosÚenvironÚgetÚslow_callback_durationÚ_current_handleÚ _task_factoryÚ_coroutine_wrapper_setrÚweakrefÚWeakSetÚ _asyncgensÚ_asyncgens_shutdown_called)rOrrrrPës(             zBaseEventLoop.__init__cCs,d|jj|jƒ|jƒ|jƒfS)Nz"<%s running=%s closed=%s debug=%s>)rQrRÚ is_runningÚ is_closedÚ get_debug)rOrrrrS szBaseEventLoop.__repr__cCstjd|ƒS)z,Create a Future object attached to the loop.rA)rZFuture)rOrrrr=szBaseEventLoop.create_futurecCsZ|jƒ|jdkrDtj|d|ƒ}|jrV|jd=n|j||ƒ}|S)zDSchedule a coroutine object. Return a task object. NrAréÿÿÿÿ)Ú _check_closedrvrrÚ_source_traceback)rOÚcoroZtaskrrrÚ create_tasks   zBaseEventLoop.create_taskcCs2|dk r%t|ƒ r%tdƒ‚||_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)Úcallabler1rv)rOÚfactoryrrrÚset_task_factory#s  zBaseEventLoop.set_task_factorycCs|jS)z†s z4BaseEventLoop.shutdown_asyncgens..Zreturn_exceptionsrAÚmessagez?an error occurred during closing of asynchronous generator {!r}Ú exceptionZasyncgen) r{rzÚlenÚlistÚclearrÚgatherÚzipr rFÚcall_exception_handlerr¨)rOZ closing_agensZ shutdown_coroZresultsÚresultr£rrrÚshutdown_asyncgensxs"     z BaseEventLoop.shutdown_asyncgensc Cs|jƒ|jƒr"tdƒ‚tjƒdk r@tdƒ‚|j|jƒtjƒ|_ |j dk r–t j ƒ}t j d|jd|jƒz,tj|ƒx|jƒ|jr©Pq©WWdd|_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 runningZ firstiterZ finalizerF)r€r|r rZ_get_running_loopÚ_set_coroutine_wrapperÚ_debugÚ threadingÚ get_identrirzrnr`Zset_asyncgen_hooksr«r¤Z_set_running_loopÚ _run_oncerc)rOZold_agen_hooksrrrÚ run_forever”s0              zBaseEventLoop.run_forevercCsÇ|jƒtj|ƒ }tj|d|ƒ}|r>d|_|jtƒzIy|jƒWn4|r‹|j ƒr‹|j ƒ r‹|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. rAFNz+Event loop stopped before Future completed.)r€rZisfuturerZ ensure_futureZ_log_destroy_pendingZadd_done_callbackrJr½rYZ cancelledr¯Zremove_done_callbackr r¶)rOZfutureZnew_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)rc)rOrrrrHÕszBaseEventLoop.stopcCs“|jƒrtdƒ‚|jr%dS|jr>tjd|ƒd|_|jjƒ|jjƒ|j }|dk r�d|_ |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 %rTÚwaitF) r|r rbr¹r Údebugrfr²rgrhZshutdown)rOÚexecutorrrrrXÝs          zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)rb)rOrrrr}ószBaseEventLoop.is_closedcCs:|jƒs6tjd|tƒ|jƒs6|jƒdS)Nzunclosed event loop %r)r}r¦r§r©r|rX)rOrrrÚ__del__ûs  zBaseEventLoop.__del__cCs |jdk S)z*Returns True if the event loop is running.N)ri)rOrrrr|szBaseEventLoop.is_runningcCs tjƒ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. )rjr_)rOrrrrjszBaseEventLoop.timecGs6|j|jƒ|||Œ}|jr2|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_atrjr�)rOZdelayÚcallbackr•ÚtimerrrrÚ call_laters  zBaseEventLoop.call_latercGsx|jƒ|jr-|jƒ|j|dƒtj||||ƒ}|jrX|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Úheappushrg)rOÚwhenrÄr•rÅrrrrÃ#s      zBaseEventLoop.call_atcGsV|jƒ|jr-|jƒ|j|dƒ|j||ƒ}|jrR|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�)rOrÄr•rrrrrÍ3s     zBaseEventLoop.call_sooncCs[tj|ƒstj|ƒr3tdj|ƒƒ‚t|ƒsWtdj||ƒƒ‚dS)Nz#coroutines cannot be used with {}()z0a callable object was expected by {}(), got {!r})rZ iscoroutineZiscoroutinefunctionr1r¨r„)rOrÄÚmethodrrrrÈFs zBaseEventLoop._check_callbackcCs<tj|||ƒ}|jr(|jd=|jj|ƒ|S)Nrr)rÚHandler�rfr3)rOrÄr•rrrrrÎQs   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)rirºr»r )rOZ thread_idrrrrÇXs  zBaseEventLoop._check_threadcGsV|jƒ|jr#|j|dƒ|j||ƒ}|jrH|jd=|jƒ|S)z"Like call_soon(), but thread-safe.Úcall_soon_threadsaferr)r€r¹rÈrÎr�r�)rOrÄr•rrrrrÑis     z"BaseEventLoop.call_soon_threadsafecGs{|jƒ|jr#|j|dƒ|dkr\|j}|dkr\tjjƒ}||_tj|j||Œd|ƒS)NÚrun_in_executorrA) r€r¹rÈrhÚ concurrentrZThreadPoolExecutorZ wrap_futureZsubmit)rOrÁÚfuncr•rrrrÒts      zBaseEventLoop.run_in_executorcCs ||_dS)N)rh)rOrÁrrrÚset_default_executorsz"BaseEventLoop.set_default_executorc Csd||fg}|r*|jd|ƒ|rA|jd|ƒ|rX|jd|ƒ|ro|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@�@) r3Újoinr rÀrjrr?rtrB) rOr5r6r7r%r8r;ÚmsgÚt0ZaddrinfoÚdtrrrÚ_getaddrinfo_debug‚s(  z BaseEventLoop._getaddrinfo_debugr7rr%r8r;c CsW|jr.|jd|j||||||ƒS|jdtj||||||ƒSdS)N)r¹rÒrÚrr?)rOr5r6r7r%r8r;rrrr?›s  zBaseEventLoop.getaddrinfocCs|jdtj||ƒS)N)rÒrÚ getnameinfo)rOZsockaddrr;rrrrÛ¤szBaseEventLoop.getnameinfoÚsslr#Ú local_addrc#s#| dk r| rtdƒ‚| dkrI|rI|sCtdƒ‚|} |dk sa|dk r‰|dk rytdƒ‚t||fd|dtjd|d|d |ƒ} | g} | dk rþt| d|dtjd|d|d |ƒ} | j| ƒnd} tj| d |ƒEdH| jƒ}|s:td ƒ‚| dk rd| jƒ}|sdtd ƒ‚g}xU|D]Ž\}}}}}y tjd|d|d|ƒ}|j d ƒ| dk raxž|D]ƒ\}}}}}y|j |ƒPWqÇtk rI}z9t|j d j ||j jƒƒƒ}|j|ƒWYdd}~XqÇXqÇW|jƒd}wq|jr}tjd ||ƒ|j||ƒEdHWnhtk rÝ}z(|dk r¾|jƒ|j|ƒWYdd}~Xqq|dk rö|jƒ‚YqqXPqqWt|ƒdkr"|d‚qÂt|dƒ‰t‡fdd†|Dƒƒr[|d‚tdj djdd„|Dƒƒƒƒ‚n9|dkr¡tdƒ‚t|ƒsÂtdj |ƒƒ‚|j|||| ƒEdH\}}|jr|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 timer7r%r8r;rAz!getaddrinfo() returned empty listFz2error while attempting to bind on address {!r}: {}zconnect %r to %rrrc3s!|]}t|ƒˆkVqdS)N)r)r¬rI)Úmodelrrú sz2BaseEventLoop.create_connection..zMultiple exceptions: {}z, css|]}t|ƒVqdS)N)r)r¬rIrrrrßsz5host and port was not specified and no sock specifiedz&A Stream Socket was expected, got {!r}rz%r connected to %s:%r: (%r, %r))rrDrr&r3rr¿r¶r"Ú setblockingÚbindÚerrnor¨ÚstrerrorÚlowerrXr¹r rÀÚ sock_connectr°rÚallrÖr'Ú_create_connection_transportÚget_extra_info)rOÚprotocol_factoryr5r6rÜr7r8r;r#rÝrŽÚf1ÚfsÚf2ÚinfosZ laddr_infosÚ exceptionsr%Zcnamer@Ú_ZladdrrIÚ transportr‹r)rÞrÚcreate_connection§sœ                $         %     zBaseEventLoop.create_connectionc cs®|jdƒ|ƒ}|jƒ}|rjt|tƒr=dn|}|j||||d|d|ƒ} n|j|||ƒ} y |EdHWn| jƒ‚YnX| |fS)NFr�rŽ)ràr=r rpr�rŒrX) rOr#rérÜrŽr�r‹r[r�rðrrrrç+s     z*BaseEventLoop._create_connection_transportÚ reuse_addressÚ reuse_portÚallow_broadcastc#s�| dk rãt| ƒs-tdj| ƒƒ‚ˆs]ˆs]|s]|s]|s]|s]|s]| rÍtdˆdˆd|d|d|d|d |d | ƒ} d jd d „| jƒDƒƒ} tdj| ƒƒ‚| jdƒd} nˆpìˆs|dkrtdƒ‚||fdff}n<tjƒ}xùdˆfdˆffD]ß\}}|dk rDt |t ƒr}t |ƒdks‰t dƒ‚t |d|dtjd|d|d|ƒEdH}|sÍtdƒ‚xS|D]K\}}}}}||f}||krddg||<||||.zNsocket modifier keyword arguments can not be used when sock is specified. ({})Frzunexpected address familyrr<z2-tuple is expectedr%rAz!getaddrinfo() returned empty listcsNg|]D\}}ˆr(|ddkp;ˆo;|ddks||f‘qS)rNrr)r¬ÚkeyZ addr_pair)rÝrõrrr­xs z:BaseEventLoop.create_datagram_endpoint..zcan not get address informationÚposixÚcygwinz@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))NN)$r)rr¨ÚdictrÖÚitemsràrdÚ OrderedDictr Útupler°rTrDrr(r"rqÚnamernÚplatformr r!Ú SO_REUSEADDRr$Z SO_BROADCASTrárårXr3r=r‘r¹r rBrÀ)rOrérÝrõr7r8r;ròrórôr#ZoptsZproblemsZr_addrZaddr_pairs_infoZ addr_infosÚidxZaddrríZfamrïZpror@rørîZ local_addressZremote_addressrIr‹r[rðr)rÝrõrÚcreate_datagram_endpointCs´            % $    "                    z&BaseEventLoop.create_datagram_endpointc csQt||fd|dtjd|d|ƒEdH}|sMtdj|ƒƒ‚|S)Nr7r%r;rAz%getaddrinfo({!r}) returned empty list)rDrr&r"r¨)rOr5r6r7r;rírrrÚ_create_server_getaddrinfo½s  z(BaseEventLoop._create_server_getaddrinfoÚbacklogr c #sdt|tƒrtdƒ‚|dk s3ˆdk r²|dk rKtdƒ‚ttddƒ} | dkr‡tjdko„tj dk} g} |dkr¥dg} n4t|t ƒsÇt|t j ƒ rÓ|g} n|} ‡‡‡‡fd d †| Dƒ}t j|d ˆŒEdH}ttjj|ƒƒ}d }zWxJ|D]B}|\}}}}}ytj|||ƒ}Wn=tjk r°ˆjr©tjd |||ddƒw=YnX| j|ƒ| rÝ|jtjtjdƒ| rít|ƒ|| kr!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šWXnB|dkrÊtdƒ‚t%|ƒsëtdj&|ƒƒ‚|g} t'ˆ| ƒ}xA| D]9}|j(|ƒ|j)d ƒˆj*|||||ƒq Wˆjr`tj+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 NoneNz8host/port and sock can not be specified at the same timer-rrùrúr,c s.g|]$}ˆj|ˆdˆdˆƒ‘qS)r7r;)r)r¬r5)r7r;r6rOrrr­òs z/BaseEventLoop.create_server..rAFz:create_server() failed to create socket.socket(%r, %r, %r)Úexc_infoTÚ 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),r rpr1rÚgetattrrrqrÿrnrrrdÚIterablerr³ÚsetÚ itertoolsÚchainÚ from_iterableÚerrorr¹r Úwarningr3r r!rr$rrZ IPV6_V6ONLYrár"rârãrärXr'r¨rKZlistenràZ_start_servingrB)rOrér5r6r7r;r#rrÜròrór-rLZhostsrëríZ completedÚresr9Zsocktyper8Z canonnameZsaÚerrr‰r)r7r;r6rOrÚ create_serverÆs€               0          zBaseEventLoop.create_serverccs‚t|ƒs!tdj|ƒƒ‚|j|||dddƒEdH\}}|jrx|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}r,r�TNrz%r handled: (%r, %r))r'rr¨rçr¹rèr rÀ)rOrér#rÜrðr‹rrrÚconnect_accepted_socket.s # z%BaseEventLoop.connect_accepted_socketc cs~|ƒ}|jƒ}|j|||ƒ}y |EdHWn|jƒ‚YnX|jrttjd|jƒ||ƒ||fS)Nz Read pipe %r connected: (%r, %r))r=r“rXr¹r rÀÚfileno)rOrér’r‹r[rðrrrÚconnect_read_pipeEs      zBaseEventLoop.connect_read_pipec cs~|ƒ}|jƒ}|j|||ƒ}y |EdHWn|jƒ‚YnX|jrttjd|jƒ||ƒ||fS)Nz!Write pipe %r connected: (%r, %r))r=r”rXr¹r rÀr)rOrér’r‹r[rðrrrÚconnect_write_pipeVs      z BaseEventLoop.connect_write_pipecCsÁ|g}|dk r,|jdt|ƒƒ|dk ra|tjkra|jdt|ƒƒnF|dk r„|jdt|ƒƒ|dk r§|jdt|ƒƒtjdj|ƒƒdS)Nzstdin=%szstdout=stderr=%sz stdout=%sz stderr=%sú )r3rrrr rÀrÖ)rOr×r—r˜r™rBrrrÚ_log_subprocessgs    zBaseEventLoop._log_subprocessr—r˜r™Úuniversal_newlinesr–Tršc ksÞt|ttfƒs!tdƒ‚|r3tdƒ‚|sEtdƒ‚|dkr]tdƒ‚|ƒ} |jr�d|} |j| |||ƒ|j| |d||||| �EdH} |jrÔtjd| | ƒ| | fS) Nzcmd must be a stringz universal_newlines must be Falsezshell must be Truerzbufsize must be 0zrun shell command %rTz%s: %r) r r/rrr¹rrœr rB) rOréÚcmdr—r˜r™rr–ršr›r‹Ú debug_logrðrrrÚsubprocess_shellts"        # zBaseEventLoop.subprocess_shellc os |rtdƒ‚|r$tdƒ‚|dkr<tdƒ‚|f| } x<| D]4} t| ttfƒsPtdt| ƒjƒ‚qPW|ƒ} |jrºd|}|j||||ƒ|j | | d||||| �EdH}|jrÿ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) rr rr/r1r%rRr¹rrœr rB)rOréZprogramr—r˜r™rr–ršr•r›Z popen_argsÚargr‹rrðrrrÚsubprocess_exec�s*          zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use. )rl)rOrrrÚ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„r1r¨rl)rOZhandlerrrrÚset_exception_handler°s   z#BaseEventLoop.set_exception_handlerc Cs†|jdƒ}|sd}|jdƒ}|dk rQt|ƒ||jf}nd}d|krŽ|jdk rŽ|jjrŽ|jj|d<|g}xÌt|ƒD]¾}|dkr¹q¤||}|dkrdjtj|ƒƒ}d }||j ƒ7}nI|dkr=djtj|ƒƒ}d }||j ƒ7}n t |ƒ}|j d j ||ƒƒq¤Wt jd j|ƒd |ƒdS)a@Default 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. The context parameter has the same meaning as in `call_exception_handler()`. r®z!Unhandled exception in event loopr¯NFZsource_tracebackZhandle_tracebackr,z+Object created at (most recent call last): z+Handle created at (most recent call last): z{}: {}Ú r>r®r¯)rsr%Ú __traceback__rur�ÚsortedrÖÚ tracebackÚ format_listÚrstriprr3r¨r r) rOÚcontextr®r¯rZ log_linesrøÚvalueÚtbrrrÚdefault_exception_handlerÁs6          z'BaseEventLoop.default_exception_handlercCsÖ|jdkrKy|j|ƒWqÒtk rGtjdddƒYqÒXn‡y|j||ƒWnptk rÑ}zPy#|jddd|d|iƒWn%tk r¾tjd ddƒ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 handlerrTr®z$Unhandled error in exception handlerr¯r'zeException in default exception handler while handling an unexpected error in custom exception handler)rlr*rFr r)rOr'rIrrrrµís"    z$BaseEventLoop.call_exception_handlercCsXt|tjƒstdƒ‚|jr+dSt|tjƒ sDt‚|jj|ƒdS)z3Add a Handle to _scheduled (TimerHandle) or _ready.zA Handle is required hereN)r rrÐrTÚ _cancelledrÉrfr3)rOrrrrÚ _add_callbacks  zBaseEventLoop._add_callbackcCs|j|ƒ|jƒdS)z6Like _add_callback() but called from a signal handler.N)r,r�)rOrrrrÚ_add_callback_signalsafe's z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)rgra)rOrrrrÚ_timer_handle_cancelled,s z%BaseEventLoop._timer_handle_cancelledc Cslt|jƒ}|tkrŒ|j|tkrŒg}x3|jD](}|jrYd|_q>|j|ƒq>Wtj|ƒ||_d|_nJxG|jrÕ|jdjrÕ|jd8_tj |jƒ}d|_q�Wd}|j sî|j r÷d}n2|jr)|jdj }t d||jƒƒ}|jr|dkr|jƒ}|jj|ƒ}|jƒ|}|dkr„tj} n tj} t|ƒ} |dkrÂtj| d|d| ƒq+| rìtj| d|d|d| ƒq+|dkr+tj| d |d|dƒn|jj|ƒ}|j|ƒ|jƒ|j} xU|jr¢|jd}|j | krtPtj |jƒ}d|_|j j|ƒqNWt|j ƒ} x­t| ƒD]Ÿ} |j jƒ}|jràq¿|jrTz[||_|jƒ}|jƒ|jƒ|}||jkrCtjd t|ƒ|ƒWdd|_Xq¿|jƒq¿Wd}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°rgÚ_MIN_SCHEDULED_TIMER_HANDLESraÚ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr+r3rÊÚheapifyÚheappoprfrcZ_whenÚmaxrjr¹Z _selectorZselectÚloggingÚINFOÚDEBUGr ÚlogrŸrkÚrangeÚpopleftruZ_runrtrr)rOZ sched_countZ new_scheduledrZtimeoutrÌrØržrÙÚlevelZneventZend_timeZntodoÚirrrr¼1sˆ                                zBaseEventLoop._run_oncec Csåytj}tj}Wntk r.dSYnXt|ƒ}|j|krNdStj}|ƒ}|r¥|d|fkr�tj d|t ƒqá||ƒd|_n<|d|fkrÎtj d|t ƒn|dƒd|_dS)Nz[loop.set_debug(True): cannot set debug coroutine wrapper; another wrapper is already set %rTzWloop.set_debug(False): cannot unset debug coroutine wrapper; another wrapper was set %rF) rnÚset_coroutine_wrapperÚget_coroutine_wrapperÚAttributeErrorrprwrZ debug_wrapperr¦r§ÚRuntimeWarning)rOÚenabledZ set_wrapperZ get_wrapperÚwrapperZcurrent_wrapperrrrr¸”s.          z$BaseEventLoop._set_coroutine_wrappercCs|jS)N)r¹)rOrrrr~µszBaseEventLoop.get_debugcCs&||_|jƒr"|j|ƒdS)N)r¹r|r¸)rOr@rrrrm¸s  zBaseEventLoop.set_debug)GrRr]r^rPrSr=rƒr†r‡rŒr�r‘r“r”rrœr�rŸr€r¤r«r·r½r¾rHrXr}rZPY34rÂr|rjrÆrÃrÍrÈrÎrÇrÑrÒrÕrÚr?rÛrñrçrrrr2Z AI_PASSIVErrrrrrrrrrr r*rµr,r-r.r¼r¸r~rmrrrrr és¶  !            %             ! �  u    _     , 2    c ! ).Ú__doc__rdZconcurrent.futuresrÓrÊr r r4rqrrrºrjr$rnr¦rxr,rrrrrrr7r Ú__all__r/r0ÚBrokenPipeErrorÚConnectionResetErrorÚConnectionAbortedErrorZ_FATAL_ERROR_IGNORErrr$r'r)r:r&rDrJZAbstractServerrKZAbstractEventLoopr rrrrÚsL                    = /