B ú?ÂCúG;ã@s°dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZy ddlZWnek r dZYnXddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZd ZdZdZ e!e dƒZ"dZ#e$ƒZ%dd„Z&dd„Z'dd„Z(d&dd„Z)dd„Z*e!e dƒrndd„Z+ndd„Z+Gd d!„d!ej,ƒ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é)Ú constants)Ú coroutines)Úevents)Úfutures)Ú protocols)Ússlproto)Útasks)Ú transports)Ú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ú6/opt/alt/python37/lib/python3.7/asyncio/base_events.pyÚ_format_handleEs rcCs(|tjkrdS|tjkrdSt|ƒSdS)Nzz)Ú subprocessÚPIPEÚSTDOUTr)ÚfdrrrÚ _format_pipeNs   rcCsLttdƒstdƒ‚n4y| 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_reuseportWs   r'c CszttdƒsdS|dtjtjhks(|dkr,dS|tjkr>tj}n|tjkrPtj}ndS|dkrbd}nVt|tƒrz|dkrzd}n>t|tƒr’|dkr’d}n&y t |ƒ}Wnt t fk r¶dSX|tj krÜtj g}trâ| tj¡n|g}t|tƒrö| d¡}d|krdSxp|D]h}yJt ||¡trD|tjkrD|||d||||ffS|||d||ffSWntk rnYnXq WdS)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_infobsL           r=cCs:| ¡s(| ¡}t|tƒr(t|tƒs(dSt |¡ ¡dS)N)Ú cancelledÚ exceptionrÚ BaseExceptionÚ ExceptionrZ _get_loopÚstop)ÚfutÚexcrrrÚ_run_until_complete_cbs rEÚ TCP_NODELAYcCs@|jtjtjhkr<|jtjkr<|jtjkr<| tjtj d¡dS)Nr) r9r!r3rr:r-r;r,r#rF)r&rrrÚ _set_nodelay¨s  rGcCsdS)Nr)r&rrrrG®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_FlowControlMixinr1Ú _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)rIÚ is_closingÚConnectionErrorrQ)rRrCrrrÚdrainÁs  z_SendfileFallbackProtocol.draincCs tdƒ‚dS)Nz?Invalid state: connection should have been established already.)Ú RuntimeError)rRÚ transportrrrÚconnection_madeÉsz)_SendfileFallbackProtocol.connection_madecCs@|jdk r0|dkr$|j tdƒ¡n |j |¡|j |¡dS)NzConnection is closed by peer)rQZ set_exceptionrVrJÚconnection_lost)rRrDrrrr[Ís    z)_SendfileFallbackProtocol.connection_lostcCs |jdk rdS|jj ¡|_dS)N)rQrIrOrP)rRrrrÚ pause_writingØs z'_SendfileFallbackProtocol.pause_writingcCs$|jdkrdS|j d¡d|_dS)NF)rQÚ set_result)rRrrrÚresume_writingÝs  z(_SendfileFallbackProtocol.resume_writingcCs tdƒ‚dS)Nz'Invalid state: reading should be paused)rX)rRÚdatarrrÚ data_receivedãsz'_SendfileFallbackProtocol.data_receivedcCs tdƒ‚dS)Nz'Invalid state: reading should be paused)rX)rRrrrÚ eof_receivedæsz&_SendfileFallbackProtocol.eof_receivedcÃsF|j |j¡|jr|j ¡|jdk r2|j ¡|jrB|j ¡dS)N) rIrNrJrKÚresume_readingrQÚcancelrLr^)rRrrrÚrestoreés   z!_SendfileFallbackProtocol.restoreN) Ú__name__Ú __module__Ú __qualname__rTrWrZr[r\r^r`rardrrrrrH²s rHc@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) rOÚ_socketsÚ _active_countÚ_waitersÚ_protocol_factoryÚ_backlogÚ _ssl_contextÚ_ssl_handshake_timeoutÚ_servingÚ_serving_forever_fut)rRÚloopÚsocketsÚprotocol_factoryZ ssl_contextÚbacklogÚssl_handshake_timeoutrrrrTøszServer.__init__cCsd|jj›d|j›dS)Nú)Ú __class__rers)rRrrrÚ__repr__szServer.__repr__cCs|jd7_dS)Nr)rj)rRrrrÚ_attachszServer._attachcCs.|jd8_|jdkr*|jdkr*| ¡dS)Nrr)rjriÚ_wakeup)rRrrrÚ_detach szServer._detachcCs0|j}d|_x|D]}| ¡s| |¡qWdS)N)rkÚdoner])rRÚwaitersÚwaiterrrrr|s  zServer._wakeupc CsN|jr dSd|_x8|jD].}| |j¡|j |j||j||j|j¡qWdS)NT) rpriZlistenrmrOÚ_start_servingrlrnro)rRr&rrrrs   zServer._start_servingcCs|jS)N)rO)rRrrrÚget_loop#szServer.get_loopcCs|jS)N)rp)rRrrrÚ is_serving&szServer.is_servingcCs|jdkrgSt|jƒS)N)riÚlist)rRrrrrs)s zServer.socketscCsr|j}|dkrdSd|_x|D]}|j |¡qWd|_|jdk r\|j ¡s\|j ¡d|_|jdkrn| ¡dS)NFr) rirOZ _stop_servingrprqr~rcrjr|)rRrsr&rrrÚclose/s     z Server.closecÃs"| ¡tjd|jdIdHdS)Nr)rr)rr ÚsleeprO)rRrrrÚ start_servingBszServer.start_servingc Ãs¢|jdk rtd|›dƒ‚|jdkr4td|›dƒ‚| ¡|j ¡|_zLy|jIdHWn6tjk rz| ¡|  ¡IdHWd‚XYnXWdd|_XdS)Nzserver z, is already being awaited on serve_forever()z is closed) rqrXrirrOrPrZCancelledErrorr…Ú wait_closed)rRrrrÚ serve_foreverHs   zServer.serve_forevercÃs<|jdks|jdkrdS|j ¡}|j |¡|IdHdS)N)rirkrOrPr5)rRr€rrrrˆ]s   zServer.wait_closedN)rerfrgrTrzr{r}r|rr‚rƒÚpropertyrsr…r‡r‰rˆrrrrrhös   rhc @s*eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zdd d dœdd„Z dždd d d d ddœ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.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Zd d<œd=d>„Zd d<œd?d@„Zd d<œdAdB„Z dCdD„Z!dEdF„Z"dGdH„Z#d d<œdIdJ„Z$dKdL„Z%dMdN„Z&dOdP„Z'dQdQdQdQdRœdSdT„Z(d£dUdV„Z)d¤ddWœdXdY„Z*dZd[„Z+d\d]„Z,d^d_„Z-d¥d dQdQdQd d d d d`œdadb„Z.d¦dcdd„Z/d§ddWœdedf„Z0dgdh„Z1didj„Z2dd d dkœdldm„Z3d¨dQdQdQe4d d d dnœdodp„Z5dQe6j7dQdQdRœdqdr„Z8dsdt„Z9d©e6j:e6j;d dud d d d ddvœ dwdx„Zd~d„Z?d€d„Z@eAjBeAjBeAjBdddQd‚œdƒd„„ZCeAjBeAjBeAjBdddQd‚œd…d†„ZDd‡dˆ„ZEd‰dŠ„ZFd‹dŒ„ZGddŽ„ZHdd„ZId‘d’„ZJd“d”„ZKd•d–„ZLd—d˜„ZMd™dš„ZNd›dœ„ZOd S)ªr cCsˆ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Ú _stoppingÚ collectionsÚdequeÚ_readyÚ _scheduledÚ_default_executorZ _internal_fdsÚ _thread_idÚtimeZget_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_called)rRrrrrTgs$  zBaseEventLoop.__init__c Cs.d|jj›d| ¡›d| ¡›d| ¡›d S)Nrwz running=z closed=z debug=rx)ryreÚ is_runningÚ is_closedÚ get_debug)rRrrrrzƒszBaseEventLoop.__repr__cCs tj|dS)z,Create a Future object attached to the loop.)rr)rZFuture)rRrrrrP‰szBaseEventLoop.create_futurecCs@| ¡|jdkr0tj||d}|jr<|jd=n | ||¡}|S)zDSchedule a coroutine object. Return a task object. N)rréÿÿÿÿ)Ú _check_closedr›r rÚ_source_traceback)rRÚcoroZtaskrrrÚ create_tasks   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)Úcallabler1r›)rRÚfactoryrrrÚset_task_factory›s zBaseEventLoop.set_task_factorycCs|jS)züsz4BaseEventLoop.shutdown_asyncgens..)Zreturn_exceptionsrrz;an error occurred during closing of asynchronous generator )Úmessager?Zasyncgen) r ÚlenrŸr„Úclearr ÚgatherÚziprrAÚcall_exception_handler)rRZ 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¡rXrZ_get_running_loop)rRrrrÚ_check_runnung s  zBaseEventLoop._check_runnungc Cs–| ¡| ¡| |j¡t ¡|_t ¡}tj |j |j dz$t   |¡x| ¡|jrNPqNWWdd|_d|_t   d¡| d¡tj |ŽXdS)zRun until stop() is called.)Ú firstiterÚ finalizerNF)r¥rÜÚ_set_coroutine_origin_trackingÚ_debugÚ threadingÚ get_identr”ÚsysÚget_asyncgen_hooksÚset_asyncgen_hooksrÑrËrZ_set_running_loopÚ _run_oncerŽ)rRZold_agen_hooksrrrÚ run_forevers$       zBaseEventLoop.run_foreverc Cs | ¡| ¡t |¡ }tj||d}|r4d|_| t¡zr?Zremove_done_callbackrXrÚ)rRZfutureZnew_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)rŽ)rRrrrrBMszBaseEventLoop.stopcCsj| ¡rtdƒ‚|jrdS|jr,t d|¡d|_|j ¡|j ¡|j }|dk rfd|_ |j dddS)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¡rXrràr Údebugr‘rÖr’r“Zshutdown)rRÚexecutorrrrr…Us   zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)r)rRrrrr¢kszBaseEventLoop.is_closedcCs2| ¡s.tjd|›t|d| ¡s.| ¡dS)Nzunclosed event loop )rÌ)r¢rÍrÎrÏr¡r…)rRrrrÚ__del__os zBaseEventLoop.__del__cCs |jdk S)z*Returns True if the event loop is running.N)r”)rRrrrr¡vszBaseEventLoop.is_runningcCst ¡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. )r•r‹)rRrrrr•zszBaseEventLoop.time)ÚcontextcGs2|j| ¡||f|žd|iŽ}|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. rír¤)Úcall_atr•r¦)rRZdelayÚcallbackrír¼ÚtimerrrrÚ call_laterƒs zBaseEventLoop.call_latercGsZ| ¡|jr"| ¡| |d¡t |||||¡}|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îr¤T) r¥ràÚ _check_threadÚ_check_callbackrZ TimerHandler¦ÚheapqÚheappushr’)rRÚwhenrïrír¼rð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¤)r¥ràròróÚ _call_soonr¦)rRrïrí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 iscoroutineZiscoroutinefunctionr1r©)rRrïÚmethodrrrró¼s  zBaseEventLoop._check_callbackcCs.t ||||¡}|jr|jd=|j |¡|S)Nr¤)rZHandler¦r‘r5)rRrïr¼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”rárârX)rRZ thread_idrrrròÍs  zBaseEventLoop._check_threadcGsB| ¡|jr| |d¡| |||¡}|jr6|jd=| ¡|S)z"Like call_soon(), but thread-safe.rÈr¤)r¥ràrórør¦rÄ)rRrïrír¼rrrrrÈÞs z"BaseEventLoop.call_soon_threadsafecGsZ| ¡|jr| |d¡|dkr@|j}|dkr@tj ¡}||_tj|j|f|žŽ|dS)NÚrun_in_executor)rr) r¥ràrór“Ú concurrentrZThreadPoolExecutorZ wrap_futureZsubmit)rRrëÚfuncr¼rrrrúés  zBaseEventLoop.run_in_executorcCs ||_dS)N)r“)rRrërrrÚset_default_executorõsz"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=z, zGet address info %szGetting address info z took g@@z.3fzms: ) r5Újoinr rêr•r!Ú getaddrinfor™Úinfo) rRr7r8r9r:r;ÚflagsÚmsgÚt0ZaddrinfoÚdtrrrÚ_getaddrinfo_debugøs&      z BaseEventLoop._getaddrinfo_debugr)r9r:r;rc Ãs2|jr|j}ntj}| d|||||||¡IdHS)N)ràrr!rrú)rRr7r8r9r:r;rZ getaddr_funcrrrrs zBaseEventLoop.getaddrinfocÃs| dtj||¡IdHS)N)rúr!Ú getnameinfo)rRZsockaddrrrrrrszBaseEventLoop.getnameinfo)Úfallbackc Ãs‚|jr| ¡dkrtdƒ‚| ||||¡y| ||||¡IdHStjk rj}z |sZ‚Wdd}~XYnX| ||||¡IdHS)Nrzthe socket must be non-blocking)ràZ gettimeoutr"Ú_check_sendfile_paramsÚ_sock_sendfile_nativerÚSendfileNotAvailableErrorÚ_sock_sendfile_fallback)rRr&ÚfileÚoffsetÚcountrrDrrrÚ sock_sendfileszBaseEventLoop.sock_sendfilecÃst d|›d¡‚dS)Nz-syscall sendfile is not available for socket z and file {file!r} combination)rr )rRr&r rrrrrr ,sz#BaseEventLoop._sock_sendfile_nativec ÃsÌ|r| |¡|rt|tjƒntj}t|ƒ}d}ztxn|rPt|||ƒ}|dkrPPt|ƒd|…}| d|j|¡IdH} | s|P| ||d| …¡IdH|| 7}q4W|S|dkrÆt |dƒrÆ| ||¡XdS)NrÚseek) rÚminrZ!SENDFILE_FALLBACK_READBUFFER_SIZEÚ bytearrayÚ memoryviewrúÚreadintoZ sock_sendallr ) rRr&r rrÚ blocksizeÚbufÚ total_sentÚviewÚreadrrrr 3s(  z%BaseEventLoop._sock_sendfile_fallbackcCs”dt|ddƒkrtdƒ‚|jtjks,tdƒ‚|dk rbt|tƒsLtd |¡ƒ‚|dkrbtd |¡ƒ‚t|tƒsztd |¡ƒ‚|dkrtd |¡ƒ‚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!r-rr0r1Úformat)rRr&r rrrrrr Ms&     z$BaseEventLoop._check_sendfile_params)Ússlr9r;rr&Ú local_addrr³rvc ƒs| dk r|stdƒ‚| dkr0|r0|s,tdƒ‚|} | dk rD|sDtdƒ‚|dk sV|dk r†|dk rftdƒ‚|j||f|tj|||dIdH} | s”tdƒ‚| dk rÆ|j| |tj|||dIdH} | sÆtdƒ‚g}xæ| D]J\}}}}}yÚtj|||d}| d ¡| dk r’xˆ| D]r\}}}}}y| |¡PWnPtk r|}z0d |›d |j ¡›}t|j |ƒ}|  |¡Wdd}~XYnXqW|  ¡d}wÒ|j r¨t  d ||¡| ||¡IdHWn^tk rü}z |dk râ|  ¡|  |¡Wdd}~XYqÒ|dk r|  ¡‚YqÒXPqÒWt|ƒd kr:|d‚nJt|dƒ‰t‡fdd„|Dƒƒrf|d‚td d dd„|Dƒ¡¡ƒ‚n.|dkr˜tdƒ‚|jtjkr´td|›ƒ‚|j|||| | dIdH\}}|j rø| 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 hostz1ssl_handshake_timeout is only meaningful with sslz8host/port and sock can not be specified at the same time)r9r:r;rrrz!getaddrinfo() returned empty list)r9r:r;Fz*error while attempting to bind on address z: zconnect %r to %rrrc3s|]}t|ƒˆkVqdS)N)r)rÒrD)Úmodelrrú Æsz2BaseEventLoop.create_connection..zMultiple exceptions: {}z, css|]}t|ƒVqdS)N)r)rÒrDrrrr!Ësz5host and port was not specified and no sock specifiedz"A Stream Socket was expected, got )rvr!z%r connected to %s:%r: (%r, %r))r"Ú_ensure_resolvedr!r-r%Ú setblockingÚbindÚstrerrorÚlowerÚerrnor5r…ràr rêÚ sock_connectrÕrÚallrrÿr:Ú_create_connection_transportÚget_extra_info)rRrtr7r8rr9r;rr&rr³rvÚinfosZ laddr_infosÚ exceptionsr:Zcnamer·Ú_ZladdrrDrrYr°r)r rÚcreate_connectionbs–       "       zBaseEventLoop.create_connectionc Ãs„| d¡|ƒ}| ¡}|rHt|tƒr*dn|} |j||| ||||d} n| |||¡} y|IdHWn|  ¡‚YnX| |fS)NF)r²r³rv)r#rPrÚboolr¶r±r…) rRr&rtrr³r²rvr°r€rµrYrrrr*æs   z*BaseEventLoop._create_connection_transportc Ãs°| ¡rtdƒ‚t|dtjjƒ}|tjjkr:td|›ƒ‚|tjjkrˆy| ||||¡IdHStj k r†}z |sv‚Wdd}~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 ) rUrXrrZ _SendfileModeZ UNSUPPORTEDZ TRY_NATIVEÚ_sendfile_nativerr Ú_sendfile_fallback)rRrYr rrrrrDrrrÚsendfiles&     zBaseEventLoop.sendfilecÃst d¡‚dS)Nz!sendfile syscall is not supported)rr )rRrSr rrrrrr1/szBaseEventLoop._sendfile_nativec Ãsè|r| |¡|rt|dƒnd}t|ƒ}d}t|ƒ}z~xx|rVt|||ƒ}|dkrV|St|ƒd|…} | d|j| ¡IdH} | s„|S| ¡IdH| | d| …¡|| 7}q8WWd|dkrÔt |dƒrÔ| ||¡|  ¡IdHXdS)Ni@rr) rrrrHrrúrrWÚwriter rd) rRrSr rrrrrr;rrrrrr23s, z BaseEventLoop._sendfile_fallback)r²r³rvc ÃsØtdkrtdƒ‚t|tjƒs*td|›ƒ‚t|ddƒsFtd|›dƒ‚| ¡}tj|||||||dd}|  ¡|  |¡|  |j |¡} |  |j ¡} y|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())rvr´)rrXrZ SSLContextr1rrPrZ SSLProtocolrMrNr÷rZrbrAr…rcZ_app_transport) rRrYr°rµr²r³rvr€Z ssl_protocolZ conmade_cbZ resume_cbrrrÚ start_tlsLs4      zBaseEventLoop.start_tls)r9r;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 krx*ˆˆfD]}|dk rÜt |t ƒsÜt dƒ‚qÜW||fˆˆfff}nÈt  ¡}x˜d ˆfdˆffD]„\}}|dk r,|j||tj|||dIdH}|sjtdƒ‚xB|D]:\}}}}}||f}||krœddg||<||||<qpWq,W‡‡fdd„| ¡Dƒ}|sÚtdƒ‚g}|tk r|røtdƒ‚ntjdtddx|D]ô\\}}\}}d} d} yxtj|tj|d} |rJt| ƒ| rb|  tjtjd¡|  d ¡ˆr||  |¡ˆrž| sš| | |¡IdH|} Wn^tk rà}z | dk rÆ|  ¡| |¡Wdd}~XYn"| dk rø|  ¡‚YnXPqW|d ‚|ƒ}| ¡}| | || |¡}|jr`ˆrPt  !dˆˆ||¡nt  "dˆ||¡y|IdHWn| ¡‚YnX||fS)zCreate datagram connection.NzA UDP Socket was expected, got )rÚ remote_addrr9r;rr6r7r8z, css$|]\}}|r|›d|›VqdS)ú=Nr)rÒÚkÚvrrrr!Œsz9BaseEventLoop.create_datagram_endpoint..zKsocket modifier keyword arguments can not be used when sock is specified. (ú)Frzunexpected address family)NNÚAF_UNIXzstring is expectedr)r9r:r;rrrz!getaddrinfo() returned empty listcs8g|]0\}}ˆr|ddksˆr,|ddks||f‘qS)rNrr)rÒÚkeyZ addr_pair)rr9rrrÓ³sz:BaseEventLoop.create_datagram_endpoint..zcan not get address informationz~Passing `reuse_address=True` is no longer supported, as the usage of SO_REUSEPORT in UDP poses a significant security concern.zcThe *reuse_address* parameter has been deprecated as of 3.7.6 and is scheduled for removal in 3.11.é)Ú stacklevel)r9r:r;z@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))#r:r!r.r"ÚdictrÿÚitemsr#r r>rrr1rÚ OrderedDictr"r%Ú_unsetrÍrÎÚDeprecationWarningr'r#r$Z SO_BROADCASTr$r(r…r5rPr¸ràr rrê)rRrtrr9r9r;rr6r7r8r&ZoptsZproblemsZr_addrZaddr_pairs_infoZaddrZ addr_infosÚidxr,Zfamr.Zpror·r?r-Z local_addressZremote_addressrDr°r€rYr)rr9rÚcreate_datagram_endpointzs¼                z&BaseEventLoop.create_datagram_endpointc Ãs\|dd…\}}t|||||f|dd…žŽ} | dk r<| gS|j||||||dIdHSdS)Nr@)r9r:r;r)r=r) rRr·r9r:r;rrrr7r8rrrrr"s  zBaseEventLoop._ensure_resolvedcÃs8|j||f|tj||dIdH}|s4td|›dƒ‚|S)N)r9r:rrrz getaddrinfo(z) returned empty list)r"r!r-r%)rRr7r8r9rr,rrrÚ_create_server_getaddrinfo s  z(BaseEventLoop._create_server_getaddrinfor ) r9rr&rurr6r7rvr‡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"x|D] }|\}}}}}yt |||¡}Wn6tjk rJˆjrDtjd |||d dwîYnX|  |¡| rn| tjtjd ¡| r|t|ƒtr¬|tjkr¬ttdƒr¬| tjtj d ¡y| !|¡Wqît"k rú}z t"|j#d||j$ %¡fƒd‚Wdd}~XYqîXqîWd }Wd|s&x| D]}| &¡qWXn4|dkr.rrFz: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)rrz %r is serving).rr0r1r"ÚosÚnamerãÚplatformrrÚabcÚIterabler r×ÚsetÚ itertoolsÚchainÚ from_iterabler!Úerrorràr Úwarningr5r#r$Z SO_REUSEADDRr'r4rr rMZ IPV6_V6ONLYr$r%r'r%r&r…r:r-r#rhrr†r)rRrtr7r8r9rr&rurr6r7rvr‡rsZhostsZfsr,Z completedZresr<Zsocktyper;Z canonnameZsaÚerrr®r)r9rr8rRrÚ create_serversŠ     *     zBaseEventLoop.create_server)rrvcÃsv|jtjkrtd|›ƒ‚|dk r.|s.tdƒ‚|j|||dd|dIdH\}}|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. z"A Stream Socket was expected, got Nz1ssl_handshake_timeout is only meaningful with sslr*T)r²rvr!z%r handled: (%r, %r)) r:r!r-r"r*ràr+r rê)rRrtr&rrvrYr°rrrÚconnect_accepted_socket‰s    z%BaseEventLoop.connect_accepted_socketcÃsd|ƒ}| ¡}| |||¡}y|IdHWn| ¡‚YnX|jr\t d| ¡||¡||fS)Nz Read pipe %r connected: (%r, %r))rPrºr…ràr rêÚfileno)rRrtr¹r°r€rYrrrÚconnect_read_pipe¦szBaseEventLoop.connect_read_pipecÃsd|ƒ}| ¡}| |||¡}y|IdHWn| ¡‚YnX|jr\t d| ¡||¡||fS)Nz!Write pipe %r connected: (%r, %r))rPr»r…ràr rêr\)rRrtr¹r°r€rYrrrÚconnect_write_pipe¶sz 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=ú )r5rrrr rêrÿ)rRrr¾r¿rÀrrrrÚ_log_subprocessÆszBaseEventLoop._log_subprocess)r¾r¿rÀÚuniversal_newlinesr½rÁc Ësªt|ttfƒstdƒ‚|r"tdƒ‚|s.tdƒ‚|dkr>tdƒ‚|ƒ} d} |jrfd|} | | |||¡|j| |d||||f| ŽIdH} |jr¢| dk r¢t d| | ¡| | fS) Nzcmd must be a stringz universal_newlines must be Falsezshell must be Truerzbufsize must be 0zrun shell command %rTz%s: %r) rr/rr"ràr`rÃr r) rRrtÚcmdr¾r¿rÀrar½rÁrÂr°Ú debug_logrYrrrÚsubprocess_shellÓs$zBaseEventLoop.subprocess_shellcÏsÐ|r tdƒ‚|rtdƒ‚|dkr(tdƒ‚|f| } x.| D]&} t| ttfƒs8tdt| ƒj›ƒ‚q8W|ƒ} d}|jrŒd|›}| ||||¡|j | | d||||f| ŽIdH}|jrÈ|dk rÈt   d||¡|| fS) Nz universal_newlines must be Falsezshell must be Falserzbufsize must be 0z6program arguments must be a bytes or text string, not zexecute program Fz%s: %r) r"rrr/r1r:reràr`rÃr r)rRrtZprogramr¾r¿rÀrar½rÁr¼rÂZ popen_argsÚargr°rcrYrrrÚsubprocess_execïs,    zBaseEventLoop.subprocess_execcCs|jS)zKReturn an exception handler, or None if the default one is in use. )r—)rRrrrÚget_exception_handler sz#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©r1r—)rRZhandlerrrrÚset_exception_handlers z#BaseEventLoop.set_exception_handlerc Cs| d¡}|sd}| d¡}|dk r6t|ƒ||jf}nd}d|kr`|jdk r`|jjr`|jj|d<|g}x’t|ƒD]†}|dkr~qp||}|dkr°d  t |¡¡}d }||  ¡7}n2|dkrÚd  t |¡¡}d }||  ¡7}nt |ƒ}|  |›d |›¡qpWt 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()`. rÔz!Unhandled exception in event loopr?NFZsource_tracebackZhandle_traceback>rÔr?r*z+Object created at (most recent call last): z+Handle created at (most recent call last): z: Ú )rL)Úgetr:Ú __traceback__ršr¦ÚsortedrÿÚ tracebackÚ format_listÚrstriprr5r rW) rRrírÔr?rLZ log_linesr?ÚvalueÚtbrrrÚdefault_exception_handler#s6    z'BaseEventLoop.default_exception_handlerc Cs°|jdkr>y| |¡Wq¬tk r:tjdddYq¬Xnny| ||¡Wn\tk rª}z>y| d||dœ¡Wn"tk r˜tjdddYnXWdd}~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 handlerT)rLz$Unhandled error in exception handler)rÔr?rízeException in default exception handler while handling an unexpected error in custom exception handler)r—rrrAr rW)rRrírDrrrrÙUs" z$BaseEventLoop.call_exception_handlercCs|jr dS|j |¡dS)z3Add a Handle to _scheduled (TimerHandle) or _ready.N)Ú _cancelledr‘r5)rRrrrrÚ _add_callbackˆszBaseEventLoop._add_callbackcCs| |¡| ¡dS)z6Like _add_callback() but called from a signal handler.N)rtrÄ)rRrrrrÚ_add_callback_signalsafes z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_dS)z3Notification that a TimerHandle has been cancelled.rN)r’rŒ)rRrrrrÚ_timer_handle_cancelled•sz%BaseEventLoop._timer_handle_cancelledc Csšt|jƒ}|tkrd|j|tkrdg}x&|jD]}|jr>d|_q,| |¡q,Wt |¡||_d|_n8x6|jrš|jdjrš|jd8_t  |j¡}d|_qfWd}|j s¬|j r²d}n*|jrÜ|jdj }t td|| ¡ƒtƒ}|jr”|dkr”| ¡}|j |¡}| ¡|}|dkr tj} ntj} t|ƒ} |dkrNt | d|d| ¡nD| rpt | d|d|d| ¡n"|dkr t | d |d|d¡n |j |¡}| |¡| ¡|j} xD|jrü|jd}|j | krÚPt  |j¡}d|_|j  |¡qºWt|j ƒ} xˆt| ƒD]|} |j  ¡}|jr,q|jr„zD||_| ¡}| ¡| ¡|}||jkrvt  d t!|ƒ|¡Wdd|_Xn| ¡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Õr’Ú_MIN_SCHEDULED_TIMER_HANDLESrŒÚ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONrsr5rôÚheapifyÚheappopr‘rŽZ_whenrÚmaxr•ÚMAXIMUM_SELECT_TIMEOUTràZ _selectorZselectÚloggingÚINFOÚDEBUGr ÚlogrÆr–ÚrangeÚpopleftršZ_runr™rXr)rRZ sched_countZ new_scheduledrZtimeoutrörrÅrÚlevelZneventZend_timeZntodoÚirrrræšsˆ                       zBaseEventLoop._run_oncecCsHt|ƒt|jƒkrdS|r2t ¡|_t tj¡n t |j¡||_dS)N)r0rœrãÚ#get_coroutine_origin_tracking_depthrÚ#set_coroutine_origin_tracking_depthrZDEBUG_STACK_DEPTH)rRÚenabledrrrrßýs  z,BaseEventLoop._set_coroutine_origin_trackingcCs|jS)N)rà)rRrrrr£ szBaseEventLoop.get_debugcCs ||_| ¡r| |j|¡dS)N)ràr¡rÈrß)rRr‡rrrr˜szBaseEventLoop.set_debug)N)N)NNN)NN)NN)N)r)rN)NN)FN)rN)NN)NN)PrerfrgrTrzrPr¨r«r¬r±r¶r¸rºr»rÃrÄrÆr¥rËrÑrÛrÜrçrèrBr…r¢rìr¡r•rñrîr÷rórøròrÈrúrýrrrrr r r r/r*r3r1r2r5rErHr!r-r"rIr2Z AI_PASSIVErZr[r]r^r`rrrdrfrgrhrrrÙrtrurvrærßr£r˜rrrrr esØ      &       .,  l23cr )rr)2Ú__doc__rZcollections.abcZconcurrent.futuresrûrôrTr}rNr!rrár•rmrãrÍržrÚ ImportErrorr*rrrrrrr r r€r Ú__all__rwrxr r4r|ÚobjectrErrr'r=rErGZProtocolrHZAbstractServerrhZAbstractEventLoopr rrrrÚsZ               ;  Do