Your IP : 3.21.46.129


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.pyo

�
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}zqyi|dk	r=d|_|j�}n|jrPd}dS|dkr`dS|jjj|jd�|_Wn�tk
r�}zF|js�|j	|d�n%|jj
�r�tjddd�nWYdd}~Xn�t
k
r}z|j|�WYdd}~Xnktk
rL}z|j	|d�WYdd}~Xn7tjk
ro|jsk�nYnX|jj|j�Wd|r�|jj|�nS|dk	r�|jj
�r�tj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)rOr�resultrr�	_proactor�recvr�ConnectionAbortedErrorrEr@r
rAr?rC�OSErrorr�CancelledError�add_done_callbackrPrZ
data_receivedZeof_receivedr5)r�fut�datarDZ	keep_openr#r#r$rP�sF			"	"	z(_ProactorReadPipeTransport._loop_reading)r(rKrLrMr
rRrSrPr#r#)r"r$rN�s	
rNc@sXeZdZdZdd�Zdddd�Zdd�Zd	d
�Zdd�ZdS)
�_ProactorBaseWritePipeTransportzTransport for write pipes.cCs�t|tttf�s0tdt|���n|jrHtd��n|sRdS|jr�|jt	j
kr}tjd�n|jd7_dS|j
dkr�|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
�warningr�
_loop_writingr�_maybe_pause_protocol�extend)rr]r#r#r$�write�s&			
z%_ProactorBaseWritePipeTransport.writeNcCszy
d|_d|_|r(|j�n|dkrI|j}d|_n|s�|jrq|jj|jd�n|jr�|j	j
tj�n|j
�no|jjj|j	|�|_|jj�s�t|�|_|jj|j�|j�n|jj|j�Wnftk
rA}z|j|�WYdd}~Xn5tk
ru}z|j|d�WYdd}~XnXdS)Nrz#Fatal write error on pipe transport)rrrUrrrrr3rrrFrH�SHUT_WRZ_maybe_resume_protocolrV�send�doner+r[rerfr?rCrYrE)r�fr]rDr#r#r$res0		
			

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(rKrLrMrhrermrnror#r#r#r$r^�s##r^cs.eZdZ�fdd�Zdd�Z�S)�_ProactorWritePipeTransportcsHt�j||�|jjj|jd�|_|jj|j�dS)N�)	rr
rrVrWrrr[�_pipe_closed)r�args�kw)r"r#r$r
3sz$_ProactorWritePipeTransport.__init__cCsV|j�rdS|jrdSd|_|jdk	rH|jt��n
|j�dS)N)Z	cancelledrrrrCr>r5)rr\r#r#r$rr8s		z(_ProactorWritePipeTransport._pipe_closed)r(rKrLr
rrr#r#)r"r$rp2srpc@s.eZdZdZdd�Zdd�ZdS)�_ProactorDuplexPipeTransportzTransport for duplex pipes.cCsdS)NFr#)rr#r#r$rmMsz*_ProactorDuplexPipeTransport.can_write_eofcCs
t�dS)N)�NotImplementedError)rr#r#r$rnPsz&_ProactorDuplexPipeTransport.write_eofN)r(rKrLrMrmrnr#r#r#r$ruHsruc@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
rdZgetpeername)rrr#r#r$rYs
		z#_ProactorSocketTransport._set_extracCsdS)NTr#)rr#r#r$rmisz&_ProactorSocketTransport.can_write_eofcCsH|js|jrdSd|_|jdkrD|jjtj�ndS)NT)rrrrrFrHri)rr#r#r$rnls
	z"_ProactorSocketTransport.write_eofN)r(rKrLrMrrmrnr#r#r#r$rwTsrwcsKeZdZ�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(rV�	_selector�_self_reading_future�_accept_futuresZset_loop�_make_self_pipe)rZproactor)r"r#r$r
vs
				
zBaseProactorEventLoop.__init__NcCst||||||�S)N)rw)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_availablervZSSLProtocolrwZ_app_transport)
rZrawsockr�
sslcontextrr�r�r r!Zssl_protocolr#r#r$�_make_ssl_transport�s
z)BaseProactorEventLoop._make_ssl_transportcCst|||||�S)N)ru)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)rp)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_piperVr5r{r)r)r"r#r$r5�s


		zBaseProactorEventLoop.closecCs|jj||�S)N)rVrW)rr�nr#r#r$�	sock_recv�szBaseProactorEventLoop.sock_recvcCs|jj||�S)N)rVrj)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_exceptionrVZconnect)rrZaddress�errr\r#r#r$�sock_connect�s
z"BaseProactorEventLoop.sock_connectcCs|jj|�S)N)rV�accept)rrr#r#r$�sock_accept�sz!BaseProactorEventLoop.sock_acceptcCs
t�dS)N)rv)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)rUrVrWr�rrZ�	ExceptionrBr|r[r�)rrlrDr#r#r$r��s
		z(BaseProactorEventLoop._loop_self_readingcCs|jjd�dS)Ns)r�rj)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 rxr!rzAccept failed on a socketr;r<rHzAccept failed on socket %rr:���)rUZ_debugr
rAr�rr�rVr�rYr*rBr5rrZr}r[)rlZconnZaddrrrD)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�rV�
_stop_servingr5)rrr#r#r$r�#s
z#BaseProactorEventLoop._stop_serving)r(rKrLr
rr�r�r�r�r5r�r�r�r�r�r�r~r�r�r�r�r�r�r#r#)r"r$rts4


()rM�__all__rHr6�rrrrrr	�logr
Z_FlowControlMixinZ
BaseTransportrZ
ReadTransportrNZWriteTransportr^rpZ	TransportrurwZ
BaseEventLooprr#r#r#r$�<module>s0	zMS


?>