Your IP : 18.225.98.39


Current Path : /opt/alt/python35/lib64/python3.5/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/asyncio/__pycache__/streams.cpython-35.opt-2.pyc



���]�^�	@s�dddddddgZddlZeed	�rIejd
dg�dd
lmZddlmZddlmZddlmZddlm	Z	ddl
mZd"ZGdd�de
�ZGdd�de�Ze	dddddedd��Ze	dddddedd��Zeed	�rte	ddddedd
��Ze	ddddedd��ZGdd�dej�ZGdd�deej�ZGd d�d�ZGd!d�d�ZdS)#�StreamReader�StreamWriter�StreamReaderProtocol�open_connection�start_server�IncompleteReadError�LimitOverrunError�N�AF_UNIX�open_unix_connection�start_unix_server�)�
coroutines)�compat)�events)�	protocols)�	coroutine)�logger��cs"eZdZ�fdd�Z�S)rcs6t�jdt|�|f�||_||_dS)Nz-%d bytes read on a total of %r expected bytes)�super�__init__�len�partial�expected)�selfrr)�	__class__��,/opt/alt/python35/lib64/python3.5/streams.pyr s	zIncompleteReadError.__init__)�__name__�
__module__�__qualname__rrr)rrrscs"eZdZ�fdd�Z�S)rcst�j|�||_dS)N)rr�consumed)r�messager!)rrrr-szLimitOverrunError.__init__)rrr rrr)rrr's�loop�limitc	+s�|dkrtj�}td|d|�}t|d|��|j�fdd�|||�EdH\}}t|�||�}||fS)Nr$r#cs�S)Nrr)�protocolrr�<lambda>Ksz!open_connection.<locals>.<lambda>)r�get_event_looprr�create_connectionr)	�host�portr#r$�kwds�reader�	transport�_�writerr)r%rr2s)c+sK�dkrtj�����fdd�}�j||||�EdHS)Ncs.td�d��}t|�d��}|S)Nr$r#)rr)r,r%)�client_connected_cbr$r#rr�factoryks	zstart_server.<locals>.factory)rr'Z
create_server)r0r)r*r#r$r+r1r)r0r$r#rrPsc+s�|dkrtj�}td|d|�}t|d|��|j�fdd�||�EdH\}}t|�||�}||fS)Nr$r#cs�S)Nrr)r%rrr&�sz&open_unix_connection.<locals>.<lambda>)rr'rrZcreate_unix_connectionr)�pathr#r$r+r,r-r.r/r)r%rr
ws&c+sH�dkrtj�����fdd�}�j|||�EdHS)Ncs.td�d��}t|�d��}|S)Nr$r#)rr)r,r%)r0r$r#rrr1�s	z"start_unix_server.<locals>.factory)rr'Zcreate_unix_server)r0r2r#r$r+r1r)r0r$r#rr�sc@sUeZdZddd�Zdd�Zdd�Zdd	�Zed
d��ZdS)�FlowControlMixinNcCsF|dkrtj�|_n	||_d|_d|_d|_dS)NF)rr'�_loop�_paused�
_drain_waiter�_connection_lost)rr#rrrr�s			zFlowControlMixin.__init__cCs,d|_|jj�r(tjd|�dS)NTz%r pauses writing)r5r4�	get_debugr�debug)rrrr�
pause_writing�s	zFlowControlMixin.pause_writingcCscd|_|jj�r(tjd|�|j}|dk	r_d|_|j�s_|jd�dS)NFz%r resumes writing)r5r4r8rr9r6�done�
set_result)r�waiterrrr�resume_writing�s			zFlowControlMixin.resume_writingcCsud|_|jsdS|j}|dkr/dSd|_|j�rHdS|dkrd|jd�n
|j|�dS)NT)r7r5r6r;r<�
set_exception)r�excr=rrr�connection_lost�s				z FlowControlMixin.connection_lostccsP|jrtd��|js"dS|j}|jj�}||_|EdHdS)NzConnection lost)r7�ConnectionResetErrorr5r6r4�
create_future)rr=rrr�
_drain_helper�s				zFlowControlMixin._drain_helper)	rrr rr:r>rArrDrrrrr3�s

	r3cs^eZdZdd�fdd�Zdd�Z�fdd�Zdd	�Zd
d�Z�S)rNcs;t�jd|�||_d|_||_d|_dS)Nr#F)rr�_stream_reader�_stream_writer�_client_connected_cb�	_over_ssl)rZ
stream_readerr0r#)rrrr�s
			zStreamReaderProtocol.__init__cCs�|jj|�|jd�dk	|_|jdk	r�t|||j|j�|_|j|j|j�}tj	|�r�|jj
|�dS)NZ
sslcontext)rE�
set_transport�get_extra_inforHrGrr4rFr
ZiscoroutineZcreate_task)rr-�resrrr�connection_made�s	z$StreamReaderProtocol.connection_madecsa|jdk	r;|dkr+|jj�n|jj|�t�j|�d|_d|_dS)N)rE�feed_eofr?rrArF)rr@)rrrrA�s	z$StreamReaderProtocol.connection_lostcCs|jj|�dS)N)rE�	feed_data)r�datarrr�
data_received�sz"StreamReaderProtocol.data_receivedcCs|jj�|jrdSdS)NFT)rErMrH)rrrr�eof_received�s
	z!StreamReaderProtocol.eof_received)rrr rrLrArPrQrr)rrr�s
	
c@s�eZdZdd�Zdd�Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zddd�Ze
dd��ZdS)rcCs(||_||_||_||_dS)N)�
_transport�	_protocol�_readerr4)rr-r%r,r#rrrrs			zStreamWriter.__init__cCsM|jjd|jg}|jdk	r<|jd|j�ddj|�S)Nztransport=%rz	reader=%rz<%s>� )rrrRrT�append�join)r�inforrr�__repr__szStreamWriter.__repr__cCs|jS)N)rR)rrrrr-!szStreamWriter.transportcCs|jj|�dS)N)rR�write)rrOrrrrZ%szStreamWriter.writecCs|jj|�dS)N)rR�
writelines)rrOrrrr[(szStreamWriter.writelinescCs
|jj�S)N)rR�	write_eof)rrrrr\+szStreamWriter.write_eofcCs
|jj�S)N)rR�
can_write_eof)rrrrr].szStreamWriter.can_write_eofcCs
|jj�S)N)rR�close)rrrrr^1szStreamWriter.closeNcCs|jj||�S)N)rRrJ)r�name�defaultrrrrJ4szStreamWriter.get_extra_infoccsi|jdk	r0|jj�}|dk	r0|�|jdk	rS|jj�rSdV|jj�EdHdS)N)rT�	exceptionrRZ
is_closingrSrD)rr@rrr�drain7s	zStreamWriter.drain)rrr rrY�propertyr-rZr[r\r]r^rJrrbrrrrr	s
c@s0eZdZeddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
edd��Zedd��Zeddd��Zed'dd��Zed d!��Zejred"d#��Zed$d%��Zejr,d&d#�ZdS)(rNcCs�|dkrtd��||_|dkr?tj�|_n	||_t�|_d|_d|_d|_	d|_
d|_dS)NrzLimit cannot be <= 0F)�
ValueError�_limitrr'r4�	bytearray�_buffer�_eof�_waiter�
_exceptionrRr5)rr$r#rrrrRs						zStreamReader.__init__cCs�dg}|jr,|jdt|j��|jrB|jd�|jtkre|jd|j�|jr�|jd|j�|jr�|jd|j�|jr�|jd|j�|j	r�|jd�d	d
j
|�S)Nrz%d bytes�eofzl=%dzw=%rze=%rzt=%rZpausedz<%s>rU)rgrVrrhre�_DEFAULT_LIMITrirjrRr5rW)rrXrrrrYes 			
				
zStreamReader.__repr__cCs|jS)N)rj)rrrrrawszStreamReader.exceptioncCsD||_|j}|dk	r@d|_|j�s@|j|�dS)N)rjri�	cancelledr?)rr@r=rrrr?zs			zStreamReader.set_exceptioncCs;|j}|dk	r7d|_|j�s7|jd�dS)N)rirmr<)rr=rrr�_wakeup_waiter�s
		zStreamReader._wakeup_waitercCs
||_dS)N)rR)rr-rrrrI�szStreamReader.set_transportcCs;|jr7t|j�|jkr7d|_|jj�dS)NF)r5rrgrerR�resume_reading)rrrr�_maybe_resume_transport�s!	z$StreamReader._maybe_resume_transportcCsd|_|j�dS)NT)rhrn)rrrrrM�s	zStreamReader.feed_eofcCs|jo|jS)N)rhrg)rrrr�at_eof�szStreamReader.at_eofcCs�|s
dS|jj|�|j�|jdk	r�|jr�t|j�d|jkr�y|jj�Wntk
r�d|_Yn
Xd|_dS)NrT)	rg�extendrnrRr5rreZ
pause_reading�NotImplementedError)rrOrrrrN�s


zStreamReader.feed_dataccsq|jdk	rtd|��|jr>d|_|jj�|jj�|_z|jEdHWdd|_XdS)NzH%s() called while another coroutine is already waiting for incoming dataF)ri�RuntimeErrorr5rRror4rC)r�	func_namerrr�_wait_for_data�s

		
zStreamReader._wait_for_dataccs�d}t|�}y|j|�EdH}Wn�tk
rX}z|jSWYdd}~Xn�tk
r�}za|jj||j�r�|jd|j|�=n
|jj�|j	�t
|jd��WYdd}~XnX|S)Ns
r)r�	readuntilrrrrg�
startswithr!�clearrprd�args)r�sep�seplen�line�errr�readline�s

&zStreamReader.readlines
ccsYt|�}|dkr$td��|jdk	r<|j�d}x�t|j�}|||kr�|jj||�}|dkr�P|d|}||jkr�td|��|jr�t|j�}|jj	�t
|d��|jd�EdHqEW||jkrtd|��|jd||�}|jd||�=|j�t|�S)Nrz,Separator should be at least one-byte stringrz2Separator is not found, and chunk exceed the limitrwz2Separator is found, but chunk is longer than limit���)
rrdrjrg�findrerrh�bytesryrrvrp)rZ	separatorr|�offset�buflenZisep�chunkrrrrw�s:			

zStreamReader.readuntilrccs�|jdk	r|j�|dkr(dS|dkryg}x/|j|j�EdH}|s[P|j|�q=Wdj|�S|jr�|jr�|jd�EdHt|jd|��}|jd|�=|j	�|S)Nr��read)
rjr�rerVrWrgrhrvr�rp)r�nZblocks�blockrOrrrr�Js$	

zStreamReader.readccs
|dkrtd��|jdk	r0|j�|dkr@dSx_t|j�|kr�|jr�t|j�}|jj�t||��|jd�EdHqCWt|j�|kr�t|j�}|jj�n)t|jd|��}|jd|�=|j	�|S)Nrz*readexactly size can not be less than zeror��readexactly)
rdrjrrgrhr�ryrrvrp)rr�Z
incompleterOrrrr�}s&		

zStreamReader.readexactlycCs|S)Nr)rrrr�	__aiter__�szStreamReader.__aiter__ccs'|j�EdH}|dkr#t�|S)Nr�)r�StopAsyncIteration)r�valrrr�	__anext__�szStreamReader.__anext__cCs|S)Nr)rrrrr��sr�)rrr rlrrYrar?rnrIrprMrqrNrrvrrwr�r�rZPY35r�r�ZPY352rrrrrPs,	 [2*		i)�__all__�socket�hasattrrr�r
rrrr�logrrl�EOFErrorr�	Exceptionrrrr
rZProtocolr3rrrrrrr�<module>s@				"B3G

?>