î j fySã @sÁdZddddddddd d d d g Zd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl Z d dl m Z dd„Z dd„Z ddd„Zdd„ZGdd„dƒZGdd„deƒZGdd„dƒZGdd„dƒZGdd„dƒZGdd„deƒZdaejƒZd d!„Zd"d„Zd#d„Zd$d„Zd%d „Zd&d „Zd'd „Zd(d „Z dS))z!Event loop and event loop policy.ÚAbstractEventLoopPolicyÚAbstractEventLoopÚAbstractServerÚHandleÚ TimerHandleÚget_event_loop_policyÚset_event_loop_policyÚget_event_loopÚset_event_loopÚnew_event_loopÚget_child_watcherÚset_child_watcheréN)ÚcompatcCs©tjrtj|ƒ}nt|dƒr6|j}ntj|ƒr^|j}|j|j fSt |t j ƒr}t |jƒStjr¥t |t jƒr¥t |jƒSdS)NÚ __wrapped__)rZPY34ÚinspectZunwrapÚhasattrrZ isfunctionÚ__code__Ú co_filenameÚco_firstlinenoÚ isinstanceÚ functoolsÚpartialÚ_get_function_sourceÚfuncÚ partialmethod)rÚcode©rú3/opt/alt/python34/lib64/python3.4/asyncio/events.pyrs     rcCsKtj|ƒ}t|ƒdkrG|jdƒrG|dd…d}n|S)zoFormat function arguments. Special case for a single parameter: ('hello',) is formatted as ('hello'). éz,)Néú)éþÿÿÿ)ÚreprlibÚreprÚlenÚendswith)ÚargsZ args_reprrrrÚ _format_args&s!r'ÚcCsËt|tjƒrG|dk r1t|ƒ|}nt|j|j|ƒSt|dƒrht|dƒ}n-t|dƒr‰t|dƒ}n t |ƒ}|dk r´|t|ƒ7}n|rÇ||7}n|S)NÚ __qualname__Ú__name__) rrrr'Ú_format_callbackrr&rÚgetattrr#)rr&ÚsuffixÚ func_reprrrrr+2s    r+cCs6t||ƒ}t|ƒ}|r2|d|7}n|S)Nz at %s:%s)r+r)rr&r.ÚsourcerrrÚ_format_callback_sourceEs  r0c@sXeZdZdZdZd d „Zd d „Zd d„Zdd„Zdd„Z dS)rz1Object returned by callback registration methods.Ú _callbackÚ_argsÚ _cancelledÚ_loopÚ_source_tracebackÚ_reprÚ __weakref__cCsƒt|tƒ stdƒ‚||_||_||_d|_d|_|jjƒrvt j t j dƒƒ|_ n d|_ dS)NzA Handle is not a callbackFr)rrÚAssertionErrorr4r1r2r3r6Ú get_debugÚ tracebackÚ extract_stackÚsysÚ _getframer5)ÚselfÚcallbackr&ÚlooprrrÚ__init__Ss     zHandle.__init__cCs’|jjg}|jr(|jdƒn|jdk rV|jt|j|jƒƒn|jrŽ|jd}|jd|d|dfƒn|S)NZ cancelledrzcreated at %s:%sr éÿÿÿÿ)Ú __class__r*r3Úappendr1r0r2r5)r>ÚinfoZframerrrÚ _repr_info_s   "zHandle._repr_infocCs3|jdk r|jS|jƒ}ddj|ƒS)Nz<%s>ú )r6rFÚjoin)r>rErrrÚ__repr__js zHandle.__repr__cCsL|jsHd|_|jjƒr3t|ƒ|_nd|_d|_ndS)NT)r3r4r9r#r6r1r2)r>rrrÚcancelps    z Handle.cancelcCs®y|j|jŒWn�tk r£}zmt|j|jƒ}dj|ƒ}i|d6|d6|d6}|jr�|j|dÚexcÚcbÚmsgÚcontextrrrÚ_run{s  #z Handle._runN)z _callbackz_argsz _cancelledz_loopz_source_tracebackz_reprz __weakref__) r*Ú __module__r)Ú__doc__Ú __slots__rArFrIrJrTrrrrrMs   cs¬eZdZdZddgZ‡fdd†Z‡fdd†Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z ‡fdd†Z‡S)rz7Object returned by timed callback registration methods.Ú _scheduledÚ_whencsT|dk st‚tƒj|||ƒ|jr>|jd=n||_d|_dS)NrFrB)r8ÚsuperrAr5rYrX)r>Úwhenr?r&r@)rCrrrA‘s    zTimerHandle.__init__cs?tƒjƒ}|jrdnd}|j|d|jƒ|S)Nrrzwhen=%s)rZrFr3ÚinsertrY)r>rEÚpos)rCrrrF™szTimerHandle._repr_infocCs t|jƒS)N)ÚhashrY)r>rrrÚ__hash__ŸszTimerHandle.__hash__cCs|j|jkS)N)rY)r>ÚotherrrrÚ__lt__¢szTimerHandle.__lt__cCs#|j|jkrdS|j|ƒS)NT)rYÚ__eq__)r>r`rrrÚ__le__¥szTimerHandle.__le__cCs|j|jkS)N)rY)r>r`rrrÚ__gt__ªszTimerHandle.__gt__cCs#|j|jkrdS|j|ƒS)NT)rYrb)r>r`rrrÚ__ge__­szTimerHandle.__ge__cCsYt|tƒrU|j|jkoT|j|jkoT|j|jkoT|j|jkStS)N)rrrYr1r2r3ÚNotImplemented)r>r`rrrrb²s zTimerHandle.__eq__cCs$|j|ƒ}|tkrtS| S)N)rbrf)r>r`ZequalrrrÚ__ne__ºszTimerHandle.__ne__cs-|js|jj|ƒntƒjƒdS)N)r3r4Ú_timer_handle_cancelledrZrJ)r>)rCrrrJ¾s zTimerHandle.cancel)r*rUr)rVrWrArFr_rarcrdrerbrgrJrr)rCrrŒs         c@s.eZdZdZdd„Zdd„ZdS)rz,Abstract server returned by create_server().cCstS)z5Stop serving. This leaves existing connections open.)rf)r>rrrÚcloseÇszAbstractServer.closecCstS)z*Coroutine to wait until service is closed.)rf)r>rrrÚ wait_closedËszAbstractServer.wait_closedN)r*rUr)rVrirjrrrrrÄs  c@s%eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!d"d!d#d!d$d!d%d&„Zd!d'd(„Zd)d)d*d)d d!d#d!d$d!d+d)d,d)d-d)d.d/„Zd)d)d ejd$ejd+d)d0d1d*d)d2d)d3d)d4d5„Zd*d)d+d)d-d)d6d7„Zd+d)d0d1d*d)d8d9„Zd)d)d d!d#d!d$d!d2d)d3d)d:d)d+d)d;d<„Zd=d>„Zd?d@„ZdAej dBej dCej dDdE„Z!dAej dBej dCej dFdG„Z"dHdI„Z#dJdK„Z$dLdM„Z%dNdO„Z&dPdQ„Z'dRdS„Z(dTdU„Z)dVdW„Z*dXdY„Z+dZd[„Z,d\d]„Z-d^d_„Z.d`da„Z/dbdc„Z0ddde„Z1dfdg„Z2dhdi„Z3d)S)jrzAbstract event loop.cCs t‚dS)z*Run the event loop until stop() is called.N)ÚNotImplementedError)r>rrrÚ run_foreverÕszAbstractEventLoop.run_forevercCs t‚dS)zpRun the event loop until a Future is done. Return the Future's result, or raise its exception. N)rk)r>ZfuturerrrÚrun_until_completeÙsz$AbstractEventLoop.run_until_completecCs t‚dS)z®Stop the event loop as soon as reasonable. Exactly how soon that is may depend on the implementation, but no more I/O callbacks should be scheduled. N)rk)r>rrrÚstopàszAbstractEventLoop.stopcCs t‚dS)z3Return whether the event loop is currently running.N)rk)r>rrrÚ is_runningèszAbstractEventLoop.is_runningcCs t‚dS)z*Returns True if the event loop was closed.N)rk)r>rrrÚ is_closedìszAbstractEventLoop.is_closedcCs t‚dS)zªClose the loop. The loop should not be running. This is idempotent and irreversible. No other methods should be called after this one. N)rk)r>rrrriðs zAbstractEventLoop.closecCs t‚dS)z3Notification that a TimerHandle has been cancelled.N)rk)r>rLrrrrhýsz)AbstractEventLoop._timer_handle_cancelledcGs|jd||ŒS)Nr )Ú call_later)r>r?r&rrrÚ call_soonszAbstractEventLoop.call_sooncGs t‚dS)N)rk)r>Zdelayr?r&rrrrqszAbstractEventLoop.call_latercGs t‚dS)N)rk)r>r[r?r&rrrÚcall_atszAbstractEventLoop.call_atcCs t‚dS)N)rk)r>rrrÚtime szAbstractEventLoop.timecCs t‚dS)N)rk)r>ZcororrrÚ create_taskszAbstractEventLoop.create_taskcGs t‚dS)N)rk)r>r?r&rrrÚcall_soon_threadsafesz&AbstractEventLoop.call_soon_threadsafecGs t‚dS)N)rk)r>Úexecutorrr&rrrÚrun_in_executorsz!AbstractEventLoop.run_in_executorcCs t‚dS)N)rk)r>rwrrrÚset_default_executorsz&AbstractEventLoop.set_default_executorÚfamilyr ÚtypeÚprotoÚflagscCs t‚dS)N)rk)r>ÚhostÚportrzr{r|r}rrrÚ getaddrinfoszAbstractEventLoop.getaddrinfocCs t‚dS)N)rk)r>Zsockaddrr}rrrÚ getnameinfo"szAbstractEventLoop.getnameinfoNÚsslÚsockÚ local_addrÚserver_hostnamec Cs t‚dS)N)rk) r>Úprotocol_factoryr~rr‚rzr|r}rƒr„r…rrrÚcreate_connection%sz#AbstractEventLoop.create_connectionÚbacklogédÚ reuse_addressÚ reuse_portc Cs t‚dS)a”A coroutine which creates a TCP server bound to host and port. The return value is a Server object which can be used to stop the service. If host is an empty string or None all interfaces are assumed and a list of multiple sockets will be returned (most likely one for IPv4 and another one for IPv6). The host parameter can also be a sequence (e.g. list) of hosts to bind to. family can be set to either AF_INET or AF_INET6 to force the socket to use IPv4 or IPv6. If not set it will be determined from host (defaults to AF_UNSPEC). flags is a bitmask for getaddrinfo(). sock can optionally be specified in order to use a preexisting socket object. backlog is the maximum number of queued connections passed to listen() (defaults to 100). ssl can be set to an SSLContext to enable SSL over the accepted connections. reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified will automatically be set to True on UNIX. reuse_port tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are bound to, so long as they all set this flag when being created. This option is not supported on Windows. N)rk) r>r†r~rrzr}rƒrˆr‚rŠr‹rrrÚ create_server*s'zAbstractEventLoop.create_servercCs t‚dS)N)rk)r>r†Úpathr‚rƒr…rrrÚcreate_unix_connectionSsz(AbstractEventLoop.create_unix_connectioncCs t‚dS)a#A coroutine which creates a UNIX Domain Socket server. The return value is a Server object, which can be used to stop the service. path is a str, representing a file systsem path to bind the server socket to. sock can optionally be specified in order to use a preexisting socket object. backlog is the maximum number of queued connections passed to listen() (defaults to 100). ssl can be set to an SSLContext to enable SSL over the accepted connections. N)rk)r>r†r�rƒrˆr‚rrrÚcreate_unix_serverXsz$AbstractEventLoop.create_unix_serverÚallow_broadcastc Cs t‚dS)aÈA coroutine which creates a datagram endpoint. This method will try to establish the endpoint in the background. When successful, the coroutine returns a (transport, protocol) pair. protocol_factory must be a callable returning a protocol instance. socket family AF_INET or socket.AF_INET6 depending on host (or family if specified), socket type SOCK_DGRAM. reuse_address tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. If not specified it will automatically be set to True on UNIX. reuse_port tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are bound to, so long as they all set this flag when being created. This option is not supported on Windows and some UNIX's. If the :py:data:`~socket.SO_REUSEPORT` constant is not defined then this capability is unsupported. allow_broadcast tells the kernel to allow this endpoint to send messages to the broadcast address. sock can optionally be specified in order to use a preexisting socket object. N)rk) r>r†r„Z remote_addrrzr|r}rŠr‹r�rƒrrrÚcreate_datagram_endpointms!z*AbstractEventLoop.create_datagram_endpointcCs t‚dS)aRegister read pipe in event loop. Set the pipe to non-blocking mode. protocol_factory should instantiate object with Protocol interface. pipe is a file-like object. Return pair (transport, protocol), where transport supports the ReadTransport interface.N)rk)r>r†ÚpiperrrÚconnect_read_pipe’s z#AbstractEventLoop.connect_read_pipecCs t‚dS)aRegister write pipe in event loop. protocol_factory should instantiate object with BaseProtocol interface. Pipe is file-like object already switched to nonblocking. Return pair (transport, protocol), where transport support WriteTransport interface.N)rk)r>r†r’rrrÚconnect_write_pipeŸs z$AbstractEventLoop.connect_write_pipeÚstdinÚstdoutÚstderrcKs t‚dS)N)rk)r>r†Úcmdr•r–r—ÚkwargsrrrÚsubprocess_shell¬sz"AbstractEventLoop.subprocess_shellcOs t‚dS)N)rk)r>r†r•r–r—r&r™rrrÚsubprocess_exec±sz!AbstractEventLoop.subprocess_execcGs t‚dS)N)rk)r>Úfdr?r&rrrÚ add_reader»szAbstractEventLoop.add_readercCs t‚dS)N)rk)r>rœrrrÚ remove_reader¾szAbstractEventLoop.remove_readercGs t‚dS)N)rk)r>rœr?r&rrrÚ add_writerÁszAbstractEventLoop.add_writercCs t‚dS)N)rk)r>rœrrrÚ remove_writerÄszAbstractEventLoop.remove_writercCs t‚dS)N)rk)r>rƒÚnbytesrrrÚ sock_recvÉszAbstractEventLoop.sock_recvcCs t‚dS)N)rk)r>rƒÚdatarrrÚ sock_sendallÌszAbstractEventLoop.sock_sendallcCs t‚dS)N)rk)r>rƒZaddressrrrÚ sock_connectÏszAbstractEventLoop.sock_connectcCs t‚dS)N)rk)r>rƒrrrÚ sock_acceptÒszAbstractEventLoop.sock_acceptcGs t‚dS)N)rk)r>Úsigr?r&rrrÚadd_signal_handler×sz$AbstractEventLoop.add_signal_handlercCs t‚dS)N)rk)r>r§rrrÚremove_signal_handlerÚsz'AbstractEventLoop.remove_signal_handlercCs t‚dS)N)rk)r>ZfactoryrrrÚset_task_factoryßsz"AbstractEventLoop.set_task_factorycCs t‚dS)N)rk)r>rrrÚget_task_factoryâsz"AbstractEventLoop.get_task_factorycCs t‚dS)N)rk)r>ZhandlerrrrÚset_exception_handlerçsz'AbstractEventLoop.set_exception_handlercCs t‚dS)N)rk)r>rSrrrÚdefault_exception_handlerêsz+AbstractEventLoop.default_exception_handlercCs t‚dS)N)rk)r>rSrrrrOísz(AbstractEventLoop.call_exception_handlercCs t‚dS)N)rk)r>rrrr9òszAbstractEventLoop.get_debugcCs t‚dS)N)rk)r>ZenabledrrrÚ set_debugõszAbstractEventLoop.set_debug)4r*rUr)rVrlrmrnrorprirhrrrqrsrtrurvrxryr€r�r‡ÚsocketZ AF_UNSPECZ AI_PASSIVErŒrŽr�r‘r“r”Ú subprocessÚPIPEršr›r�ržrŸr r¢r¤r¥r¦r¨r©rªr«r¬r­rOr9r®rrrrrÐsr               $  &   !                  c@sReZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) rz-Abstract policy for accessing the event loop.cCs t‚dS)a:Get the event loop for the current context. Returns an event loop object implementing the BaseEventLoop interface, or raises an exception in case no event loop has been set for the current context and the current policy does not specify to create one. It should never return None.N)rk)r>rrrrüsz&AbstractEventLoopPolicy.get_event_loopcCs t‚dS)z3Set the event loop for the current context to loop.N)rk)r>r@rrrr sz&AbstractEventLoopPolicy.set_event_loopcCs t‚dS)zÑCreate and return a new event loop object according to this policy's rules. If there's need to set this loop as the event loop for the current context, set_event_loop must be called explicitly.N)rk)r>rrrr sz&AbstractEventLoopPolicy.new_event_loopcCs t‚dS)z$Get the watcher for child processes.N)rk)r>rrrr sz)AbstractEventLoopPolicy.get_child_watchercCs t‚dS)z$Set the watcher for child processes.N)rk)r>Úwatcherrrrr sz)AbstractEventLoopPolicy.set_child_watcherN) r*rUr)rVrr r r r rrrrrùs    c@seeZdZdZdZGdd„dejƒZdd„Zdd„Z d d „Z d d „Z dS) ÚBaseDefaultEventLoopPolicyaßDefault policy implementation for accessing the event loop. In this policy, each thread has its own event loop. However, we only automatically create an event loop by default for the main thread; other threads by default have no event loop. Other policies may have different rules (e.g. a single global event loop, or automatically creating an event loop per thread, or using some other notion of context to which an event loop is associated). Nc@seZdZdZdZdS)z!BaseDefaultEventLoopPolicy._LocalNF)r*rUr)r4Ú _set_calledrrrrÚ_Local*s rµcCs|jƒ|_dS)N)rµÚ_local)r>rrrrA.sz#BaseDefaultEventLoopPolicy.__init__cCs…|jjdkrM|jj rMttjƒtjƒrM|j|jƒƒn|jjdkr{t dtjƒj ƒ‚n|jjS)zSGet the event loop. This may be None or an instance of EventLoop. Nz,There is no current event loop in thread %r.) r¶r4r´rÚ threadingZcurrent_threadZ _MainThreadr r Ú RuntimeErrorÚname)r>rrrr1s z)BaseDefaultEventLoopPolicy.get_event_loopcCs=d|j_|dks-t|tƒs-t‚||j_dS)zSet the event loop.TN)r¶r´rrr8r4)r>r@rrrr ?s !z)BaseDefaultEventLoopPolicy.set_event_loopcCs |jƒS)zvCreate a new event loop. You must call set_event_loop() to make this the current event loop. )Ú _loop_factory)r>rrrr Esz)BaseDefaultEventLoopPolicy.new_event_loop) r*rUr)rVrºr·ZlocalrµrArr r rrrrr³s    r³c Cs9t�-tdkr/ddlm}|ƒanWdQXdS)Nr)ÚDefaultEventLoopPolicy)Ú_lockÚ_event_loop_policyr(r»)r»rrrÚ_init_event_loop_policyXs r¾cCstdkrtƒntS)z"Get the current event loop policy.N)r½r¾rrrrr`s  cCs+|dks!t|tƒs!t‚|adS)zZSet the current event loop policy. If policy is None, the default policy is restored.N)rrr8r½)Zpolicyrrrrgs!cCs tƒjƒS)z?Equivalent to calling get_event_loop_policy().get_event_loop().)rrrrrrrpscCstƒj|ƒdS)zCEquivalent to calling get_event_loop_policy().set_event_loop(loop).N)rr )r@rrrr uscCs tƒjƒS)z?Equivalent to calling get_event_loop_policy().new_event_loop().)rr rrrrr zscCs tƒjƒS)zBEquivalent to calling get_event_loop_policy().get_child_watcher().)rr rrrrr scCstƒj|ƒS)zMEquivalent to calling get_event_loop_policy().set_child_watcher(watcher).)rr )r²rrrr „s)!rVÚ__all__rrr"r¯r°r<r·r:Zasynciorrr'r+r0rrrrrr³r½ZLockr¼r¾rrrr r r r rrrrÚsH             ?8 ÿ*"7