File "base_events.cpython-34.pyc"

Full Path: /home/attunedd/public_html/byp/izo/con7ext_sym404/rintoar.txt/opt/alt/python34/lib64/python3.4/asyncio/__pycache__/base_events.cpython-34.pyc
File size: 37.27 KB
MIME-type: text/x-bytecode.python
Charset: 8 bit


j f@sdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZdgZdZd
ZdZddZddZ dZ!e"edre!ej#OZ!ne"edre!ej$OZ!nej%ddddZ&ddZ'ddZ(Gdddej)Z*Gdddej+Z,dS) aBase 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
BaseEventLoopdg?cCsH|j}tj|r:t|jtjr:t|jSt|SdS)N)		_callbackinspectZismethod
isinstance__self__rTaskreprstr)handlecbr8/opt/alt/python34/lib64/python3.4/asyncio/base_events.py_format_handle9s	$
rcCs4|tjkrdS|tjkr&dSt|SdS)Nz<pipe>z<stdout>)
subprocessPIPESTDOUTr)fdrrr_format_pipeBs
r
SOCK_NONBLOCKSOCK_CLOEXECmaxsizeicCs|dtjtjhks'|dkr+dS|tM}|tjkrQtj}n|tjkrltj}ndSttdr2|tjkrtjtj	g}n	|g}x|D]w}y\|tj	krtj
||jddntj
|||||d||ffSWqtk
r)YqXqWdSyt
j|}WnKtk
ry t
j|jdd}Wntk
rdSYnXYnX|jdkrtjntj	}|tj|fkrdS|||d||ffS)Nr	inet_pton%)socketZIPPROTO_TCPZIPPROTO_UDP_SOCKET_TYPE_MASKSOCK_STREAM
SOCK_DGRAMhasattr	AF_UNSPECZAF_INETAF_INET6r!	partitionOSError	ipaddressZIPv4Address
ValueErrorZIPv6Addressversion)hostportfamilytypeprotoZafsafaddrrrr_ipaddr_infoSs@'	
 
	
 
!r8cCsyttdr%|jtjkr%dS|dd\}}t|||j|j|jdkrutd|ndS)NAF_UNIXz2address must be resolved (IP address), got host %r)r)r%r3r9r8r4r5r/)sockaddressr1r2rrr_check_resolved_addresss!'r=cCs=|j}t|tr,t|tr,dS|jjdS)N)Z
_exceptionr
BaseException	Exception_loopstop)futexcrrr_run_until_complete_cbs
	rDc@sjeZdZddZddZddZddZd	d
ZddZe	d
dZ
dS)ServercCs(||_||_d|_g|_dS)Nr)r@sockets
_active_count_waiters)selflooprFrrr__init__s			zServer.__init__cCsd|jj|jfS)Nz<%s sockets=%r>)	__class____name__rF)rIrrr__repr__szServer.__repr__cCs(|jdk	st|jd7_dS)Nr)rFAssertionErrorrG)rIrrr_attachszServer._attachcCsS|jdkst|jd8_|jdkrO|jdkrO|jndS)Nrr)rGrOrF_wakeup)rIrrr_detachszServer._detachcCsc|j}|dkrdSd|_x|D]}|jj|q)W|jdkr_|jndS)Nr)rFr@Z
_stop_servingrGrQ)rIrFr;rrrcloses		
zServer.closecCsC|j}d|_x*|D]"}|js|j|qqWdS)N)rHdone
set_result)rIwaiterswaiterrrrrQs
		
zServer._wakeupccsT|jdks|jdkr"dStjd|j}|jj||DdHdS)NrJ)rFrHrFuturer@append)rIrWrrrwait_closeds
zServer.wait_closedN)rM
__module____qualname__rKrNrPrRrSrQrrZrrrrrEs
rEc@s!eZdZddZddZddZddZd	d
Zdddd
dddZdddddddd
dddZ	dddddZ
ddddZddddZe
dddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,ZejrPd-d.Znd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFdGdFdHdFdIdFdJdKZ%dFdLdMZ&e
dddNddEdFdHdFdIdFdOddPddddQdRZ'e
dSdTZ(e
dddEdFdHdFdIdFdUddVddWddOddXdYZ)e
dZd[Z*e
dddEe+j,dIe+j-dOdd\d]dNddUddVdd^d_Z.e
d`daZ/e
dbdcZ0dddeZ1e
dfe2j3dge2j3dhe2j3diddjdkdldFdmdnZ4e
dfe2j3dge2j3dhe2j3diddjddldFdodpZ5dqdrZ6dsdtZ7dudvZ8dwdxZ9dydzZ:d{d|Z;d}d~Z<ddZ=ddZ>ddZ?dS)r
cCsd|_d|_d|_tj|_g|_d|_d|_d|_	t
jdj|_
d|_|jtjjottjjdd|_d|_d|_d|_dS)NrF	monotonicZPYTHONASYNCIODEBUGg?)_timer_cancelled_count_closed	_stoppingcollectionsdeque_ready
_scheduled_default_executorZ
_internal_fds
_thread_idtimeZget_clock_infoZ
resolution_clock_resolution_exception_handler	set_debugsysflagsignore_environmentboolosenvirongetslow_callback_duration_current_handle
_task_factory_coroutine_wrapper_set)rIrrrrKs 											zBaseEventLoop.__init__cCs,d|jj|j|j|jfS)Nz"<%s running=%s closed=%s debug=%s>)rLrM
is_running	is_closed	get_debug)rIrrrrNszBaseEventLoop.__repr__cCs]|j|jdkrGtj|d|}|jrY|jd=qYn|j||}|S)zDSchedule a coroutine object.

        Return a task object.
        NrJr)
_check_closedrtrr_source_traceback)rIZcoroZtaskrrrcreate_tasks
	zBaseEventLoop.create_taskcCs5|dk	r(t|r(tdn||_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)callable	TypeErrorrt)rIZfactoryrrrset_task_factorys
zBaseEventLoop.set_task_factorycCs|jS)z<Return a task factory, or None if the default one is in use.)rt)rIrrrget_task_factoryszBaseEventLoop.get_task_factoryNextraservercCs
tdS)zCreate socket transport.N)NotImplementedError)rIr;protocolrWrrrrr_make_socket_transportsz$BaseEventLoop._make_socket_transportserver_sideFserver_hostnamec	Cs
tdS)zCreate SSL transport.N)r)	rIZrawsockr
sslcontextrWrrrrrrr_make_ssl_transportsz!BaseEventLoop._make_ssl_transportcCs
tdS)zCreate datagram transport.N)r)rIr;rr<rWrrrr_make_datagram_transportsz&BaseEventLoop._make_datagram_transportcCs
tdS)zCreate read pipe transport.N)r)rIpiperrWrrrr_make_read_pipe_transport sz'BaseEventLoop._make_read_pipe_transportcCs
tdS)zCreate write pipe transport.N)r)rIrrrWrrrr_make_write_pipe_transport%sz(BaseEventLoop._make_write_pipe_transportc	
Ks
tdS)zCreate subprocess transport.N)r)
rIrargsshellstdinstdoutstderrbufsizerkwargsrrr_make_subprocess_transport*sz(BaseEventLoop._make_subprocess_transportcCs
tdS)zWrite a byte to self-pipe, to wake up the event loop.

        This may be called from a different thread.

        The subclass is responsible for implementing the self-pipe.
        N)r)rIrrr_write_to_self1szBaseEventLoop._write_to_selfcCs
tdS)zProcess selector events.N)r)rI
event_listrrr_process_events:szBaseEventLoop._process_eventscCs|jrtdndS)NzEvent loop is closed)r_RuntimeError)rIrrrrz>s	zBaseEventLoop._check_closedcCs|j|jr%tdn|j|jtj|_z"x|j|j	rJPqJqJWWdd|_	d|_|jdXdS)zRun until stop() is called.zEvent loop is running.NF)
rzrvr_set_coroutine_wrapper_debug	threading	get_identrf	_run_oncer`)rIrrrrun_foreverBs

			zBaseEventLoop.run_foreverc	Cs|jt|tj}tj|d|}|rDd|_n|jty|j	Wn7|r|j
r|jr|jnYnX|j
t|j
stdn|jS)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.
        rJFz+Event loop stopped before Future completed.)rzrrrXrZ
ensure_futureZ_log_destroy_pendingZadd_done_callbackrDrrTZ	cancelled	exceptionZremove_done_callbackrresult)rIZfutureZnew_taskrrrrun_until_completeSs 



z BaseEventLoop.run_until_completecCs
d|_dS)zStop 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`)rIrrrrAwszBaseEventLoop.stopcCs|jrtdn|jr(dS|jrDtjd|nd|_|jj|jj|j	}|dk	rd|_	|j
ddndS)zClose 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 %rTwaitF)rvrr_rr	debugrcclearrdreZshutdown)rIexecutorrrrrSs			

		zBaseEventLoop.closecCs|jS)z*Returns True if the event loop was closed.)r_)rIrrrrwszBaseEventLoop.is_closedcCs@|js<tjd|t|js<|jq<ndS)Nzunclosed event loop %r)rwwarningswarnResourceWarningrvrS)rIrrr__del__szBaseEventLoop.__del__cCs
|jdk	S)z*Returns True if the event loop is running.N)rf)rIrrrrvszBaseEventLoop.is_runningcCs
tjS)zReturn 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.
        )rgr])rIrrrrgszBaseEventLoop.timecGs9|j|j|||}|jr5|jd=n|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.
        rry)call_atrgr{)rIZdelaycallbackrtimerrrr
call_laters	
zBaseEventLoop.call_latercGstj|stj|r-tdn|j|jrM|jntj||||}|j	r{|j	d=nt
j|j|d|_|S)z|Like call_later(), but uses an absolute time.

        Absolute time corresponds to the event loop's time() method.
        z(coroutines cannot be used with call_at()rTry)
riscoroutineiscoroutinefunctionr~rzr
_check_threadrTimerHandler{heapqheappushrd)rIwhenrrrrrrrs
	
	
	zBaseEventLoop.call_atcGsB|jr|jn|j||}|jr>|jd=n|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.
        rry)rr
_call_soonr{)rIrrrrrr	call_soons
	
	
zBaseEventLoop.call_sooncCsvtj|stj|r-tdn|jtj|||}|jrb|jd=n|jj	||S)Nz*coroutines cannot be used with call_soon()rry)
rrrr~rzrHandler{rcrY)rIrrrrrrrs
	
zBaseEventLoop._call_sooncCsA|jdkrdStj}||jkr=tdndS)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)rfrrr)rIZ	thread_idrrrrs	zBaseEventLoop._check_threadcGs6|j||}|jr(|jd=n|j|S)z"Like call_soon(), but thread-safe.rry)rr{r)rIrrrrrrcall_soon_threadsafes
	

z"BaseEventLoop.call_soon_threadsafecGstj|stj|r-tdn|jt|tjr|sVtt|tj	sot|j
rtjd|}|j
d|S|j|j}}n|dkr|j}|dkrtjjt}||_qntj|j||d|S)Nz0coroutines cannot be used with run_in_executor()rJ)rrrr~rzrrrrOr
_cancelledrrXrUr
_argsre
concurrentZThreadPoolExecutor_MAX_WORKERSZwrap_futureZsubmit)rIrfuncrfrrrrun_in_executors$

	
	zBaseEventLoop.run_in_executorcCs
||_dS)N)re)rIrrrrset_default_executor sz"BaseEventLoop.set_default_executorcCsd||fg}|r-|jd|n|rG|jd|n|ra|jd|n|r{|jd|ndj|}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@@)	rYjoinr	rrgr%getaddrinforrinfo)rIr1r2r3r4r5rlmsgt0Zaddrinfodtrrr_getaddrinfo_debug#s(
z BaseEventLoop._getaddrinfo_debugr3rr4r5rlc		Cst|||||}|dk	rJtjd|}|j|g|S|jrx|jd|j||||||S|jdtj||||||SdS)NrJ)	r8rrXrUrrrr%r)	rIr1r2r3r4r5rlrrBrrrr<s	zBaseEventLoop.getaddrinfocCs|jdtj||S)N)rr%getnameinfo)rIZsockaddrrlrrrrJszBaseEventLoop.getnameinfosslr;
local_addrc#s0|
dk	r"|r"tdn|
dkrR|rR|sItdn|}
n|dk	sj|dk	r|dk	rtdn|j||d|dtjd|d|}|g}|	dk	r|jd|dtjd|d||	}
|j|
nd}
tj|d	|DdH|j}|s@td
n|
dk	rp|
j}|sptd
qpng}xF|D]\}}}}}ytjd|d|d|}|j	d|
dk	rpx|D]\}}}}}y|j
|PWqtk
rU}z9t|jdj||j
j}|j|WYdd}~XqXqW|jd}w}n|jrtjd
||n|j||DdHWnntk
r}z+|dk	r|jn|j|WYdd}~Xq}|dk	r|jnYq}XPq}Wt|dkr:|dqt|dtfdd|Drv|dntdjdjdd|Dn|dkrtdn|j	d|j||||
DdH\}}|jr&|jd}tjd|||||n||fS)aConnect 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 timer3r4r5rlrJz!getaddrinfo() returned empty listFz2error while attempting to bind on address {!r}: {}zconnect %r to %rrrc3s!|]}t|kVqdS)N)r).0rC)modelrr	<genexpr>sz2BaseEventLoop.create_connection.<locals>.<genexpr>zMultiple exceptions: {}z, css|]}t|VqdS)N)r)rrCrrrrsz5host and port was not specified and no sock specifiedr%z%r connected to %s:%r: (%r, %r))r/rr%r'rYrrrr-setblockingbinderrnoformatstrerrorlowerrSrr	rsock_connectlenrallr_create_connection_transportZget_extra_info)rIprotocol_factoryr1r2rr3r5rlr;rrf1fsf2infosZladdr_infos
exceptionsr4Zcnamer<_ZladdrrC	transportrr)rrcreate_connectionMs			

$
	



	%
		zBaseEventLoop.create_connectionc		cs|}tjd|}|rct|tr6dn|}|j||||ddd|}n|j|||}y
|DdHWn|jYnX||fS)NrJrFr)rrXrrnrrrS)	rIr;rrrrrWrrrrrrs	

z*BaseEventLoop._create_connection_transport
reuse_address
reuse_portallow_broadcastc#s|
dk	rs<s<|s<|s<|s<|s<|s<|	rtddd|d|d|d|d|d	|	}d
jdd|jD}td
j|n|
jdd}
nRps|dkrtdn||fd ff}nEtj}xdfdffD]\}}|dk	r)t|t	rbt
|dksntd|jd|dt
jd|d||DdH}|stdnxY|D]N\}}}}}||f}||krddg||<n||||<qWq)q)Wfdd|jD}|sItdng}|dkr|tjdkovtjdk}nx|D]\\}}\}}d}
d}
yt
j
d|dt
jd|}
|r|
jt
jt
jdn|r-tt
dstdq-|
jt
jt
jdn|	rO|
jt
jt
jdn|
jdrr|
j|nr|j|
|DdH|}
nWnntk
r}z+|
dk	r|
jn|j|WYdd}~Xq|
dk	r|
jnYqXPqW|d|}tjd|}|j |
||
|}|j!rrut"j#d||qt"j$d||ny
|DdHWn|jYnX||fS)!zCreate datagram connection.Nrremote_addrr3r5rlrrrz, css-|]#\}}|rdj||VqdS)z{}={}N)r)rkvrrrrsz9BaseEventLoop.create_datagram_endpoint.<locals>.<genexpr>zNsocket modifier keyword arguments can not be used when sock is specified. ({})Frzunexpected address familyrr:z2-tuple is expectedr4z!getaddrinfo() returned empty listcsNg|]D\}}r(|ddkp;o;|ddks||fqS)rNrr)rkeyZ	addr_pair)rrrr
<listcomp>s		z:BaseEventLoop.create_datagram_endpoint.<locals>.<listcomp>zcan not get address informationposixcygwinSO_REUSEPORTz)reuse_port not supported by socket modulerJz@Datagram endpoint local_addr=%r remote_addr=%r created: (%r, %r)z2Datagram endpoint remote_addr=%r created: (%r, %r))NN)%dictritemsr/rrraOrderedDictrtuplerrOrr%r(r-ronamerkplatform
setsockopt
SOL_SOCKETSO_REUSEADDRr)rZSO_BROADCASTrrrSrYrrXrrr	rr)rIrrrr3r5rlrrrr;ZoptsZproblemsZr_addrZaddr_pairs_infoZ
addr_infosidxr7rZfamrZpror<rrZ
local_addressZremote_addressrCrrWrr)rrrcreate_datagram_endpoints	
	%$		"!	




				

z&BaseEventLoop.create_datagram_endpointc	csN|j||d|dtjd|DdH}|sJtdj|n|S)Nr3r4rlz%getaddrinfo({!r}) returned empty list)rr%r'r-r)rIr1r2r3rlrrrr_create_server_getaddrinfoZs	z(BaseEventLoop._create_server_getaddrinfobacklogrc #st|trtdn|dk	s6dk	r|dk	rQtdnttdd}|	dkrtjdkotj	dk}	ng}|dkrdg}
n4t|t
st|tjr|g}
n|}
fd	d
|
D}t
jd|DdH}tjj|}d}zx|D]{}|\}}}}}ytj|||}Wn@tjk
rjrtjd
|||ddnw@YnX|j||	r|jtjtjdn|
r&ttds
tdq&|jtjtjdn||kr]ttdr]|jtjtjdny|j|Wq@tk
r}z*t|j d||j!j"fWYdd}~Xq@Xq@Wd}Wd|sx|D]}|j#qWnXn$|dkrtdn|g}t$|}x>|D]6}|j%||j&dj'||||q+Wjrtj(d|n|S)aCreate 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.

        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+rrrr#c	s.g|]$}j|ddqS)r3rl)r)rr1)r3rlr2rIrrrs	z/BaseEventLoop.create_server.<locals>.<listcomp>rJFz:create_server() failed to create socket.socket(%r, %r, %r)exc_infoTrz)reuse_port not supported by socket moduleIPPROTO_IPV6z0error while attempting to bind on address %r: %sz)Neither host/port nor sock were specifiedz
%r is serving))rrnr~r/getattrr%rorrkrrraIterablerZgather	itertoolschain
from_iterableerrorrr	warningrYrrrr)rrZIPV6_V6ONLYrr-rrrrSrEZlistenrZ_start_servingr)rIrr1r2r3rlr;rrrrr+rFZhostsrrZ	completedresr6Zsocktyper5Z	canonnameZsaerrrr)r3rlr2rIr
create_servercs!

		

0

	


	zBaseEventLoop.create_serverccs|}tjd|}|j|||}y
|DdHWn|jYnX|jr}tjd|j||n||fS)NrJz Read pipe %r connected: (%r, %r))rrXrrSrr	rfileno)rIrrrrWrrrrconnect_read_pipes	

		zBaseEventLoop.connect_read_pipeccs|}tjd|}|j|||}y
|DdHWn|jYnX|jr}tjd|j||n||fS)NrJz!Write pipe %r connected: (%r, %r))rrXrrSrr	rr)rIrrrrWrrrrconnect_write_pipes	

		z BaseEventLoop.connect_write_pipecCs|g}|dk	r/|jdt|n|dk	rd|tjkrd|jdt|nL|dk	r|jdt|n|dk	r|jdt|ntjdj|dS)Nzstdin=%szstdout=stderr=%sz	stdout=%sz	stderr=%s )rYrrrr	rr)rIrrrrrrrr_log_subprocesss	zBaseEventLoop._log_subprocessrrruniversal_newlinesrTrc
	kst|ttfs$tdn|r9tdn|sNtdn|dkritdn|}
|jrd|}|j||||n|j|
|d|||||	DdH}|jrtjd||fn||
fS)	Nzcmd must be a stringz universal_newlines must be Falsezshell must be Truerzbufsize must be 0zrun shell command %rTz%s: %r)	rbytesrr/rr
rr	r)
rIrcmdrrrrrrrr	debug_logrrrrsubprocess_shells"		
#	zBaseEventLoop.subprocess_shellc	os|rtdn|r*tdn|dkrEtdn|f|	}x?|D]7}t|ttfsYtdt|jqYqYW|}
|jrd|}|j||||n|j	|
|d|||||
DdH}|jrt
jd||fn||
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/rrrr~r4rMrr
rr	r)rIrZprogramrrrrrrrrZ
popen_argsargrrrrrrsubprocess_execs*

		
	zBaseEventLoop.subprocess_execcCs>|dk	r1t|r1tdj|n||_dS)aSet 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}r~rri)rIZhandlerrrrset_exception_handler0s	z#BaseEventLoop.set_exception_handlerc	Cs|jd}|sd}n|jd}|dk	rTt|||jf}nd}d|kr|jdk	r|jjr|jj|d<n|g}xt|D]}|dkrqn||}|dkr	djtj|}d	}||j	7}nI|dkrFdjtj|}d
}||j	7}nt
|}|jdj||qWt
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()`.
        messagez!Unhandled exception in event looprNFZsource_tracebackZhandle_tracebackr#z+Object created at (most recent call last):
z+Handle created at (most recent call last):
z{}: {}
r>	exceptionmessage)rqr4
__traceback__rsr{sortedr	tracebackformat_listrstriprrYrr	r)	rIcontextrrrZ	log_linesrvaluetbrrrdefault_exception_handlerAs6
		
z'BaseEventLoop.default_exception_handlercCs|jdkrKy|j|Wqtk
rGtjdddYqXny|j||Wnstk
r}zSy&|jidd6|d6|d6Wn%tk
rtjd	ddYnXWYdd}~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.

        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 handlerrTz$Unhandled error in exception handlerrrrzeException in default exception handler while handling an unexpected error in custom exception handler)rirr?r	r)rIrrCrrrcall_exception_handlerms"
	
z$BaseEventLoop.call_exception_handlercCsXt|tjstd|jr+dSt|tjsDt|jj|dS)z3Add a Handle to _scheduled (TimerHandle) or _ready.zA Handle is required hereN)rrrrOrrrcrY)rIrrrr
_add_callbacks
	zBaseEventLoop._add_callbackcCs|j||jdS)z6Like _add_callback() but called from a signal handler.N)r!r)rIrrrr_add_callback_signalsafes
z&BaseEventLoop._add_callback_signalsafecCs|jr|jd7_ndS)z3Notification that a TimerHandle has been cancelled.rN)rdr^)rIrrrr_timer_handle_cancelleds	z%BaseEventLoop._timer_handle_cancelledcCs{t|j}|tkr|j|tkrg}x3|jD](}|jrYd|_q>|j|q>Wtj|||_d|_nJxG|jr|jdjr|jd8_tj	|j}d|_qWd}|j
s|jrd}n5|jr,|jdj}t
d||j}n|jr|dkr|j}|jj|}|j|}|dkrtj}	n	tj}	t|}
|dkrtj|	d|d|
q1|
rtj|	d|d|d|
q1|dkr1tj|	d	|d|dq1n|jj|}|j||j|j}xX|jr|jd}|j|kr}Pntj	|j}d|_|j
j|qTWt|j
}xt|D]}
|j
j}|jrqn|jrcz^||_|j}|j|j|}||jkrRtjd
t||nWdd|_Xq|jqWd}dS)zRun 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) rrd_MIN_SCHEDULED_TIMER_HANDLESr^%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONrrYrheapifyheappoprcr`Z_whenmaxrgrZ	_selectorZselectloggingINFODEBUGr	logrrhrangepopleftrsZ_runrrrr)rIZsched_countZ
new_scheduledrZtimeoutrrrrlevelZneventZend_timeZntodoirrrrs
		
	
					

				
	
zBaseEventLoop._run_oncecCsytj}tj}Wntk
r.dSYnXt|}|j|krNdStj}|}|r|d|fkrtj	d|t
q||d|_n<|d|fkrtj	d|t
n|dd|_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)rkZset_coroutine_wrapperZget_coroutine_wrapperAttributeErrorrnrurZ
debug_wrapperrrRuntimeWarning)rIenabledZset_wrapperZget_wrapperwrapperZcurrent_wrapperrrrrs.	

			

z$BaseEventLoop._set_coroutine_wrappercCs|jS)N)r)rIrrrrx3szBaseEventLoop.get_debugcCs)||_|jr%|j|ndS)N)rrvr)rIr3rrrrj6s	zBaseEventLoop.set_debug)@rMr[r\rKrNr|rrrrrrrrrrrrzrrrArSrwrZPY34rrvrgrrrrrrrrrrrrrrrr%r*Z
AI_PASSIVErrrr
rrrrrrr r!r"r#rrrxrjrrrrr
s	$		!
	y	w				^
	,0c!)-__doc__raZconcurrent.futuresr	functoolsrrr.rr)ror%rrrgrrkrr#rrrrrrr,r	__all__rr$r%rrr&r)rr	lru_cacher8r=rDZAbstractServerrEZAbstractEventLoopr
rrrr<module>sN		
:

/