Your IP : 18.188.130.151


Current Path : /opt/alt/python34/lib64/python3.4/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/asyncio/__pycache__/proactor_events.cpython-34.pyc

�
j f�N�@s_dZdgZddlZddlZddlmZddlmZddlmZddlmZdd	lm	Z	dd
lm
Z
ddlmZGdd
�d
e
j
e
j�ZGdd�dee
j�ZGdd�dee
j�ZGdd�de�ZGdd�deee
j�ZGdd�deee
j�ZGdd�dej�ZdS)z�Event loop using a proactor and related classes.

A proactor is a "notify-on-completion" multiplexer.  Currently a
proactor is only implemented on Windows with IOCP.
�BaseProactorEventLoop�N�)�base_events)�compat)�	constants)�futures)�sslproto)�
transports)�loggercs�eZdZdZddd�fdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
rud
d�Znddd�Zdd�Z
dd�Zdd�Z�S)�_ProactorBasePipeTransportz*Base class for pipe and socket transports.Ncs�t�j||�|j|�||_||_||_d|_d|_d|_d|_	d|_
d|_d|_|jdk	r�|jj
�n|jj|jj|�|dk	r�|jjtj|d�ndS)NrF)�super�__init__�
_set_extra�_sock�	_protocol�_server�_buffer�	_read_fut�
_write_fut�_pending_write�
_conn_lost�_closing�_eof_writtenZ_attach�_loop�	call_soonZconnection_maderZ_set_result_unless_cancelled)�self�loop�sock�protocol�waiter�extra�server)�	__class__��</opt/alt/python34/lib64/python3.4/asyncio/proactor_events.pyr
s$
										z#_ProactorBasePipeTransport.__init__cCs|jjg}|jdkr.|jd�n|jrG|jd�n|jdk	rs|jd|jj��n|jdk	r�|jd|j�n|jdk	r�|jd|j�n|jr�t	|j�}|jd|�n|j
r|jd�ndd	j|�S)
N�closed�closingzfd=%szread=%szwrite=%rzwrite_bufsize=%szEOF writtenz<%s>� )r"�__name__r�appendr�filenorrr�lenr�join)r�info�bufsizer#r#r$�__repr__/s"			z#_ProactorBasePipeTransport.__repr__cCs||jd<dS)N�pipe)�_extra)rrr#r#r$rBsz%_ProactorBasePipeTransport._set_extracCs|jS)N)r)rr#r#r$�
is_closingEsz%_ProactorBasePipeTransport.is_closingcCs�|jr
dSd|_|jd7_|jrW|jdkrW|jj|jd�n|jdk	r|jj�d|_ndS)NTr)	rrrrrr�_call_connection_lostr�cancel)rr#r#r$�closeHs		
z _ProactorBasePipeTransport.closecCs4|jdk	r0tjd|t�|j�ndS)Nzunclosed transport %r)r�warnings�warn�ResourceWarningr5)rr#r#r$�__del__Wsz"_ProactorBasePipeTransport.__del__zFatal error on pipe transportcCs�t|ttf�rC|jj�rrtjd||dd�qrn/|jji|d6|d6|d6|jd6�|j	|�dS)Nz%r: %s�exc_infoT�message�	exceptionZ	transportr)
�
isinstance�BrokenPipeError�ConnectionResetErrorr�	get_debugr
�debug�call_exception_handlerr�_force_close)r�excr;r#r#r$�_fatal_error\sz'_ProactorBasePipeTransport._fatal_errorcCs�|jr
dSd|_|jd7_|jrG|jj�d|_n|jri|jj�d|_nd|_d|_|jj|j	|�dS)NTrr)
rrrr4rrrrrr3)rrDr#r#r$rCis			
	
		z'_ProactorBasePipeTransport._force_closecCs�z|jj|�Wdt|jd�r?|jjtj�n|jj�d|_|j}|dk	r�|j	�d|_nXdS)N�shutdown)
rZconnection_lost�hasattrrrF�socketZ	SHUT_RDWRr5rZ_detach)rrDr!r#r#r$r3xs
		
z0_ProactorBasePipeTransport._call_connection_lostcCs2|j}|jdk	r.|t|j�7}n|S)N)rrr+)r�sizer#r#r$�get_write_buffer_size�s	z0_ProactorBasePipeTransport.get_write_buffer_size)r(�
__module__�__qualname__�__doc__r
r/rr2r5rZPY34r9rErCr3rJr#r#)r"r$rs	
rcsXeZdZdZddd�fdd�Zdd�Zdd�Zdd	d
�Z�S)�_ProactorReadPipeTransportzTransport for read pipes.Ncs?t�j||||||�d|_|jj|j�dS)NF)rr
�_pausedrr�
_loop_reading)rrrrrr r!)r"r#r$r
�s	z#_ProactorReadPipeTransport.__init__cCs_|jrtd��n|jr0td��nd|_|jj�r[tjd|�ndS)Nz#Cannot pause_reading() when closingzAlready pausedTz%r pauses reading)r�RuntimeErrorrOrr@r
rA)rr#r#r$�
pause_reading�s			z(_ProactorReadPipeTransport.pause_readingcCsm|jstd��nd|_|jr.dS|jj|j|j�|jj�ritj	d|�ndS)Nz
Not pausedFz%r resumes reading)
rOrQrrrrPrr@r
rA)rr#r#r$�resume_reading�s			z)_ProactorReadPipeTransport.resume_readingcCs%|jr
dSd}z�y�|dk	rj|j|ksR|jdkrL|jsRt�d|_|j�}n|jr}d}dS|dkr�dS|jjj|jd�|_Wn�t	k
r}zF|js�|j
|d�n%|jj�rtj
ddd�nWYdd}~Xn�tk
rE}z|j|�WYdd}~Xnktk
ry}z|j
|d�WYdd}~Xn7tjk
r�|js��nYnX|jj|j�Wd|r�|jj|�nS|dk	r |jj�r�tj
d|�n|jj�}|s |j�q nXdS)N�iz"Fatal read error on pipe transportz*Read error on pipe transport while closingr:Tz%r received EOF)rOrr�AssertionError�resultr�	_proactor�recvr�ConnectionAbortedErrorrEr@r
rAr?rC�OSErrorr�CancelledError�add_done_callbackrPrZ
data_receivedZeof_receivedr5)r�fut�datarDZ	keep_openr#r#r$rP�sJ			"	"	z(_ProactorReadPipeTransport._loop_reading)r(rKrLrMr
rRrSrPr#r#)r"r$rN�s	
rNc@sXeZdZdZdd�Zdddd�Zdd�Zd	d
�Zdd�ZdS)
�_ProactorBaseWritePipeTransportzTransport for write pipes.cCst|tttf�s0tdt|���n|jrHtd��n|sRdS|jr�|jt	j
kr}tjd�n|jd7_dS|j
dkr�|jdks�t�|jdt|��n?|js�t|�|_|j�n|jj|�|j�dS)Nz#data argument must be byte-ish (%r)zwrite_eof() already calledzsocket.send() raised exception.rr^)r=�bytes�	bytearray�
memoryview�	TypeError�typerrQrrZ!LOG_THRESHOLD_FOR_CONNLOST_WRITESr
�warningrrrU�
_loop_writing�_maybe_pause_protocol�extend)rr^r#r#r$�write�s(			
z%_ProactorBaseWritePipeTransport.writeNcCs�y7||jkst�d|_d|_|r=|j�n|dkr^|j}d|_n|s�|jr�|jj|jd�n|j	r�|j
jtj
�n|j�n�|jjj|j
|�|_|jj�s#|jdks�t�t|�|_|jj|j�|j�n|jj|j�Wnftk
rk}z|j|�WYdd}~Xn5tk
r�}z|j|d�WYdd}~XnXdS)Nrz#Fatal write error on pipe transport)rrUrrVrrrrr3rrrFrH�SHUT_WRZ_maybe_resume_protocolrW�send�doner+r\rfrgr?rCrZrE)r�fr^rDr#r#r$rfs4		
			

z-_ProactorBaseWritePipeTransport._loop_writingcCsdS)NTr#)rr#r#r$�
can_write_eof(sz-_ProactorBaseWritePipeTransport.can_write_eofcCs|j�dS)N)r5)rr#r#r$�	write_eof+sz)_ProactorBaseWritePipeTransport.write_eofcCs|jd�dS)N)rC)rr#r#r$�abort.sz%_ProactorBaseWritePipeTransport.abort)	r(rKrLrMrirfrnrorpr#r#r#r$r_�s##r_cs.eZdZ�fdd�Zdd�Z�S)�_ProactorWritePipeTransportcsHt�j||�|jjj|jd�|_|jj|j�dS)N�)	rr
rrWrXrrr\�_pipe_closed)r�args�kw)r"r#r$r
3sz$_ProactorWritePipeTransport.__init__cCs�|j�rdS|j�dks(t�|jrJ|jdksFt�dS||jksnt||jf��d|_|jdk	r�|jt��n
|j�dS)NrT)	Z	cancelledrVrUrrrrCr>r5)rr]r#r#r$rs8s	$	z(_ProactorWritePipeTransport._pipe_closed)r(rKrLr
rsr#r#)r"r$rq2srqc@s.eZdZdZdd�Zdd�ZdS)�_ProactorDuplexPipeTransportzTransport for duplex pipes.cCsdS)NFr#)rr#r#r$rnMsz*_ProactorDuplexPipeTransport.can_write_eofcCs
t�dS)N)�NotImplementedError)rr#r#r$roPsz&_ProactorDuplexPipeTransport.write_eofN)r(rKrLrMrnror#r#r#r$rvHsrvc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�_ProactorSocketTransportz Transport for connected sockets.cCs�||jd<y|j�|jd<WnCtjtfk
ri|jj�retjd|dd�nYnXd|jkr�y|j	�|jd<Wq�tjtfk
r�|jj�r�tjd|dd�nYq�XndS)NrHZsocknamezgetsockname() failed on %rr:T�peernamezgetpeername() failed on %r)
r1ZgetsocknamerH�error�AttributeErrorrr@r
reZgetpeername)rrr#r#r$rYs
		z#_ProactorSocketTransport._set_extracCsdS)NTr#)rr#r#r$rnisz&_ProactorSocketTransport.can_write_eofcCsH|js|jrdSd|_|jdkrD|jjtj�ndS)NT)rrrrrFrHrj)rr#r#r$rols
	z"_ProactorSocketTransport.write_eofN)r(rKrLrMrrnror#r#r#r$rxTsrxcsKeZdZ�fdd�Zddddd�Zdddddd	dd
ddd�Zddd
d�Zdddd�Zdddd�Z�fdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd �Zd!d"�Zdd#d$�Zd%d&�Zddd'd(�Zd)d*�Zd+d,�Zd-d.�Z�S)/rcsbt�j�tjd|jj�||_||_d|_i|_	|j
|�|j�dS)NzUsing proactor: %s)rr
r
rAr"r(rW�	_selector�_self_reading_future�_accept_futuresZset_loop�_make_self_pipe)rZproactor)r"r#r$r
vs
				
zBaseProactorEventLoop.__init__NcCst||||||�S)N)rx)rrrrr r!r#r#r$�_make_socket_transport�sz,BaseProactorEventLoop._make_socket_transport�server_sideF�server_hostnamer r!c
Cs\tj�std��ntj||||||�}	t|||	d|d|�|	jS)NzOProactor event loop requires Python 3.5 or newer (ssl.MemoryBIO) to support SSLr r!)rZ_is_sslproto_availablerwZSSLProtocolrxZ_app_transport)
rZrawsockr�
sslcontextrr�r�r r!Zssl_protocolr#r#r$�_make_ssl_transport�s
z)BaseProactorEventLoop._make_ssl_transportcCst|||||�S)N)rv)rrrrr r#r#r$�_make_duplex_pipe_transport�sz1BaseProactorEventLoop._make_duplex_pipe_transportcCst|||||�S)N)rN)rrrrr r#r#r$�_make_read_pipe_transport�sz/BaseProactorEventLoop._make_read_pipe_transportcCst|||||�S)N)rq)rrrrr r#r#r$�_make_write_pipe_transport�sz0BaseProactorEventLoop._make_write_pipe_transportcso|j�rtd��n|j�r+dS|j�|j�|jj�d|_d|_t�j�dS)Nz!Cannot close a running event loop)	Z
is_runningrQ�	is_closed�_stop_accept_futures�_close_self_piperWr5r|r)r)r"r#r$r5�s


		zBaseProactorEventLoop.closecCs|jj||�S)N)rWrX)rr�nr#r#r$�	sock_recv�szBaseProactorEventLoop.sock_recvcCs|jj||�S)N)rWrk)rrr^r#r#r$�sock_sendall�sz"BaseProactorEventLoop.sock_sendallcCsvytj||�WnHtk
r^}z(tjd|�}|j|�|SWYdd}~XnX|jj||�SdS)Nr)rZ_check_resolved_address�
ValueErrorrZFutureZ
set_exceptionrWZconnect)rrZaddress�errr]r#r#r$�sock_connect�s
z"BaseProactorEventLoop.sock_connectcCs|jj|�S)N)rW�accept)rrr#r#r$�sock_accept�sz!BaseProactorEventLoop.sock_acceptcCs
t�dS)N)rw)rr#r#r$�_socketpair�sz!BaseProactorEventLoop._socketpaircCsg|jdk	r(|jj�d|_n|jj�d|_|jj�d|_|jd8_dS)Nr)r}r4�_ssockr5�_csock�
_internal_fds)rr#r#r$r��s

	
	z&BaseProactorEventLoop._close_self_pipecCs[|j�\|_|_|jjd�|jjd�|jd7_|j|j�dS)NFr)r�r�r�Zsetblockingr�r�_loop_self_reading)rr#r#r$r�s
z%BaseProactorEventLoop._make_self_pipecCs�y5|dk	r|j�n|jj|jd�}Wn_tjk
rPdSYn`tk
r�}z'|jidd6|d6|d6�WYdd}~XnX||_|j	|j
�dS)Niz.Error on reading from the event loop self piper;r<r)rVrWrXr�rr[�	ExceptionrBr}r\r�)rrmrDr#r#r$r��s
		z(BaseProactorEventLoop._loop_self_readingcCs|jjd�dS)Ns)r�rk)rr#r#r$�_write_to_self�sz$BaseProactorEventLoop._write_to_selfcs5d������fdd���j��dS)Ncs�y�|dk	r�|j�\}}�jrCtjd�||�n��}�dk	r��j||�dddi|d6d��q��j||di|d6d��n�j�r�dS�jj��}Wn�t	k
rZ}zh�j
�dkr&�jidd	6|d
6�d6��j�n"�jrHtjd�d
d�nWYdd}~Xn?t
jk
rx�j�Yn!X|�j�j
�<|j��dS)Nz#%r got a new connection from %r: %rr�Tr ryr!rzAccept failed on a socketr;r<rHzAccept failed on socket %rr:���)rVZ_debugr
rAr�r�r�rWr�rZr*rBr5rr[r~r\)rmZconnZaddrrrD)r�protocol_factoryrr!rr�r#r$r�s>					
		"z2BaseProactorEventLoop._start_serving.<locals>.loop)r)rr�rr�r!r#)rr�rr!rr�r$�_start_serving�s$$z$BaseProactorEventLoop._start_servingcCsdS)Nr#)rZ
event_listr#r#r$�_process_eventssz%BaseProactorEventLoop._process_eventscCs5x!|jj�D]}|j�qW|jj�dS)N)r~�valuesr4�clear)rZfuturer#r#r$r�sz*BaseProactorEventLoop._stop_accept_futurescCs(|j�|jj|�|j�dS)N)r�rW�
_stop_servingr5)rrr#r#r$r�#s
z#BaseProactorEventLoop._stop_serving)r(rKrLr
r�r�r�r�r�r5r�r�r�r�r�r�rr�r�r�r�r�r�r#r#)r"r$rts4


()rM�__all__rHr6�rrrrrr	�logr
Z_FlowControlMixinZ
BaseTransportrZ
ReadTransportrNZWriteTransportr_rqZ	TransportrvrxZ
BaseEventLooprr#r#r#r$�<module>s0	zMS


?>