Your IP : 52.15.42.61


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

�
j f]�	@s�dZdddddddgZdd	lZeed
�rRejddg�nd
dlmZd
dlmZd
dlmZd
dlm	Z	d
dlm
Z
d
dlmZd
dlm
Z
d$ZGdd�de�ZGdd�de�Zed	d	dd	dedd��Zed	d	dd	dedd��Zeed
�r�ed	dd	dedd��Zed	dd	dedd��ZnGdd �d e
j�ZGd!d�dee
j�ZGd"d�d�ZGd#d�d�Zd	S)%zStream-related things.�StreamReader�StreamWriter�StreamReaderProtocol�open_connection�start_server�IncompleteReadError�LimitOverrunError�NZAF_UNIX�open_unix_connection�start_unix_server�)�
coroutines)�compat)�events)�futures)�	protocols)�	coroutine)�logger��cs(eZdZdZ�fdd�Z�S)rz�
    Incomplete read error. Attributes:

    - partial: read bytes string before the end of stream was reached
    - expected: total number of expected bytes (or None if unknown)
    cs6t�jdt|�|f�||_||_dS)Nz-%d bytes read on a total of %r expected bytes)�super�__init__�len�partial�expected)�selfrr)�	__class__��4/opt/alt/python34/lib64/python3.4/asyncio/streams.pyr!s	zIncompleteReadError.__init__)�__name__�
__module__�__qualname__�__doc__rrr)rrrscs(eZdZdZ�fdd�Z�S)rz�Reached buffer limit while looking for the separator.

    Attributes:
    - message: error message
    - consumed: total number of bytes that should be consumed
    cs&t�j|�||_||_dS)N)rr�message�consumed)rr"r#)rrrr/s	zLimitOverrunError.__init__)rrr r!rrr)rrr(s�loop�limitc	+s�|dkrtj�}ntd|d|�}t|d|��|j�fdd�|||�DdH\}}t|�||�}||fS)a�A wrapper for create_connection() returning a (reader, writer) pair.

    The reader returned is a StreamReader instance; the writer is a
    StreamWriter instance.

    The arguments are all the usual arguments to create_connection()
    except protocol_factory; most common are positional host and port,
    with various optional keyword arguments following.

    Additional optional keyword arguments are loop (to set the event loop
    instance to use) and limit (to set the buffer limit passed to the
    StreamReader).

    (If you want to customize the StreamReader and/or
    StreamReaderProtocol classes, just copy the code -- there's
    really nothing special here except some convenience.)
    Nr%r$cs�S)Nrr)�protocolrr�<lambda>Nsz!open_connection.<locals>.<lambda>)r�get_event_looprrZcreate_connectionr)	�host�portr$r%�kwds�reader�	transport�_�writerr)r&rr5s)c+sN�dkrtj��n���fdd�}�j||||�DdHS)a�Start a socket server, call back for each client connected.

    The first parameter, `client_connected_cb`, takes two parameters:
    client_reader, client_writer.  client_reader is a StreamReader
    object, while client_writer is a StreamWriter object.  This
    parameter can either be a plain callback function or a coroutine;
    if it is a coroutine, it will be automatically converted into a
    Task.

    The rest of the arguments are all the usual arguments to
    loop.create_server() except protocol_factory; most common are
    positional host and port, with various optional keyword arguments
    following.  The return value is the same as loop.create_server().

    Additional optional keyword arguments are loop (to set the event loop
    instance to use) and limit (to set the buffer limit passed to the
    StreamReader).

    The return value is the same as loop.create_server(), i.e. a
    Server object which can be used to stop the service.
    Ncs.td�d��}t|�d��}|S)Nr%r$)rr)r,r&)�client_connected_cbr%r$rr�factoryns	zstart_server.<locals>.factory)rr(Z
create_server)r0r)r*r$r%r+r1r)r0r%r$rrSsc+s�|dkrtj�}ntd|d|�}t|d|��|j�fdd�||�DdH\}}t|�||�}||fS)z@Similar to `open_connection` but works with UNIX Domain Sockets.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	zs&c+sK�dkrtj��n���fdd�}�j|||�DdHS)z=Similar to `start_server` but works with UNIX Domain Sockets.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@s[eZdZdZddd�Zdd�Zdd�Zd	d
�Zedd��Z	dS)
�FlowControlMixina)Reusable flow control logic for StreamWriter.drain().

    This implements the protocol methods pause_writing(),
    resume_reading() and connection_lost().  If the subclass overrides
    these it must call the super methods.

    StreamWriter.drain() must wait for _drain_helper() coroutine.
    NcCsF|dkrtj�|_n	||_d|_d|_d|_dS)NF)rr(�_loop�_paused�
_drain_waiter�_connection_lost)rr$rrrr�s			zFlowControlMixin.__init__cCs/d|_|jj�r+tjd|�ndS)NTz%r pauses writing)r5r4�	get_debugr�debug)rrrr�
pause_writing�s	zFlowControlMixin.pause_writingcCsld|_|jj�r+tjd|�n|j}|dk	rhd|_|j�sh|jd�qhndS)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_lostccsY|jrtd��n|js%dS|j}tjd|j�}||_|DdHdS)NzConnection lostr$)r7�ConnectionResetErrorr5r6r�Futurer4)rr=rrr�
_drain_helper�s				zFlowControlMixin._drain_helper)
rrr r!rr:r>rArrDrrrrr3�s	r3csdeZdZdZdd�fdd�Zdd�Z�fdd�Zd	d
�Zdd�Z�S)
ra=Helper class to adapt between Protocol and StreamReader.

    (This is a helper class instead of making StreamReader itself a
    Protocol subclass, because the StreamReader has other potential
    uses, and to prevent the user of the StreamReader to accidentally
    call inappropriate methods of the protocol.)
    Ncs2t�jd|�||_d|_||_dS)Nr$)rr�_stream_reader�_stream_writer�_client_connected_cb)rZ
stream_readerr0r$)rrrr�s		zStreamReaderProtocol.__init__cCs~|jj|�|jdk	rzt|||j|j�|_|j|j|j�}tj|�rz|jj|�qzndS)N)	rE�
set_transportrGrr4rFrZiscoroutineZcreate_task)rr-�resrrr�connection_made�s	z$StreamReaderProtocol.connection_madecs@|dkr|jj�n|jj|�t�j|�dS)N)rE�feed_eofr?rrA)rr@)rrrrA�sz$StreamReaderProtocol.connection_lostcCs|jj|�dS)N)rE�	feed_data)r�datarrr�
data_received�sz"StreamReaderProtocol.data_receivedcCs|jj�dS)NT)rErK)rrrr�eof_received�s
z!StreamReaderProtocol.eof_received)	rrr r!rrJrArNrOrr)rrr�sc@s�eZdZdZdd�Zdd�Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zddd�Z
edd��ZdS)ra'Wraps a Transport.

    This exposes write(), writelines(), [can_]write_eof(),
    get_extra_info() and close().  It adds drain() which returns an
    optional Future on which you can wait for flow control.  It also
    adds a transport property which references the Transport
    directly.
    cCs(||_||_||_||_dS)N)�
_transport�	_protocol�_readerr4)rr-r&r,r$rrrr
s			zStreamWriter.__init__cCsP|jjd|jg}|jdk	r?|jd|j�nddj|�S)Nztransport=%rz	reader=%rz<%s>� )rrrPrR�append�join)r�inforrr�__repr__szStreamWriter.__repr__cCs|jS)N)rP)rrrrr-szStreamWriter.transportcCs|jj|�dS)N)rP�write)rrMrrrrXszStreamWriter.writecCs|jj|�dS)N)rP�
writelines)rrMrrrrY"szStreamWriter.writelinescCs
|jj�S)N)rP�	write_eof)rrrrrZ%szStreamWriter.write_eofcCs
|jj�S)N)rP�
can_write_eof)rrrrr[(szStreamWriter.can_write_eofcCs
|jj�S)N)rP�close)rrrrr\+szStreamWriter.closeNcCs|jj||�S)N)rP�get_extra_info)r�name�defaultrrrr].szStreamWriter.get_extra_infoccsu|jdk	r6|jj�}|dk	r6|�q6n|jdk	r_|jj�r_dVq_n|jj�DdHdS)z~Flush the write buffer.

        The intended use is to write

          w.write(data)
          yield from w.drain()
        N)rR�	exceptionrPZ
is_closingrQrD)rr@rrr�drain1s	zStreamWriter.drain)rrr r!rrW�propertyr-rXrYrZr[r\r]rrarrrrrsc@seZdZeddd�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%��ZndS)'rNcCs�|dkrtd��n||_|dkrBtj�|_n	||_t�|_d|_d|_d|_	d|_
d|_dS)NrzLimit cannot be <= 0F)�
ValueError�_limitrr(r4�	bytearray�_buffer�_eof�_waiter�
_exceptionrPr5)rr%r$rrrrLs						zStreamReader.__init__cCs�dg}|jr/|jdt|j��n|jrH|jd�n|jtkrn|jd|j�n|jr�|jd|j�n|jr�|jd|j�n|jr�|jd|j�n|j	r�|jd�nd	d
j
|�S)Nrz%d bytes�eofzl=%dzw=%rze=%rzt=%rZpausedz<%s>rS)rfrTrrgrd�_DEFAULT_LIMITrhrirPr5rU)rrVrrrrW_s 							zStreamReader.__repr__cCs|jS)N)ri)rrrrr`qszStreamReader.exceptioncCsJ||_|j}|dk	rFd|_|j�sF|j|�qFndS)N)rirh�	cancelledr?)rr@r=rrrr?ts			zStreamReader.set_exceptioncCsA|j}|dk	r=d|_|j�s=|jd�q=ndS)z1Wakeup read*() functions waiting for data or EOF.N)rhrlr<)rr=rrr�_wakeup_waiter}s
		zStreamReader._wakeup_waitercCs
||_dS)N)rP)rr-rrrrH�szStreamReader.set_transportcCs>|jr:t|j�|jkr:d|_|jj�ndS)NF)r5rrfrdrP�resume_reading)rrrr�_maybe_resume_transport�s!	z$StreamReader._maybe_resume_transportcCsd|_|j�dS)NT)rgrm)rrrrrK�s	zStreamReader.feed_eofcCs|jo|jS)z=Return True if the buffer is empty and 'feed_eof' was called.)rgrf)rrrr�at_eof�szStreamReader.at_eofcCs�|s
dS|jj|�|j�|jdk	r�|jr�t|j�d|jkr�y|jj�Wntk
r�d|_Yq�Xd|_ndS)NrT)	rf�extendrmrPr5rrdZ
pause_reading�NotImplementedError)rrMrrrrL�s


zStreamReader.feed_dataccs}|jdk	r"td|��n|jrDd|_|jj�ntjd|j�|_z|jDdHWdd|_XdS)zpWait until feed_data() or feed_eof() is called.

        If stream was paused, automatically resume it.
        NzH%s() called while another coroutine is already waiting for incoming dataFr$)rh�RuntimeErrorr5rPrnrrCr4)rZ	func_namerrr�_wait_for_data�s

		zStreamReader._wait_for_dataccs�d}t|�}y|j|�DdH}Wn�tk
rX}z|jSWYdd}~Xn�tk
r�}za|jj||j�r�|jd|j|�=n
|jj�|j	�t
|jd��WYdd}~XnX|S)a�Read chunk of data from the stream until newline (b'
') is found.

        On success, return chunk that ends with newline. If only partial
        line can be read due to EOF, return incomplete line without
        terminating newline. When EOF was reached while no bytes read, empty
        bytes object is returned.

        If limit is reached, ValueError will be raised. In that case, if
        newline was found, complete line including newline will be removed
        from internal buffer. Else, internal buffer will be cleared. Limit is
        compared against part of the line without newline.

        If stream was paused, this function will automatically resume it if
        needed.
        s
Nr)r�	readuntilrrrrf�
startswithr#�clearrorc�args)r�sep�seplen�line�errr�readline�s

&zStreamReader.readlines
ccsnt|�}|dkr'td��n|jdk	rB|j�nd}x�t|j�}|||kr�|jj||�}|dkr�Pn|d|}||jkr�td|��q�n|jr�t|j�}|jj	�t
|d��n|jd�DdHqKW||jkr/td|��n|jd||�}|jd||�=|j�t|�S)	auRead chunk of data from the stream until `separator` is found.

        On success, chunk and its separator will be removed from internal buffer
        (i.e. consumed). Returned chunk will include separator at the end.

        Configured stream limit is used to check result. Limit means maximal
        length of chunk that can be returned, not counting the separator.

        If EOF occurs and complete separator still not found,
        IncompleteReadError(<partial data>, None) will be raised and internal
        buffer becomes empty. This partial data may contain a partial separator.

        If chunk cannot be read due to overlimit, LimitOverrunError will be raised
        and data will be left in internal buffer, so it can be read again, in
        some different way.

        If stream was paused, this function will automatically resume it if
        needed.
        rz,Separator should be at least one-byte stringNrz2Separator is not found, and chunk exceed the limitruz2Separator is found, but chunk is longer than limit���)
rrcrirf�findrdrrg�bytesrwrrtro)rZ	separatorrz�offsetZbuflenZisep�chunkrrrru�s4	

zStreamReader.readuntilrccs�|jdk	r|j�n|dkr+dS|dkrg}x2|j|j�DdH}|saPn|j|�q@Wdj|�S|jr�|jr�|jd�DdHnt|jd|��}|jd|�=|j	�|S)a�Read up to `n` bytes from the stream.

        If n is not provided, or set to -1, read until EOF and return all read
        bytes. If the EOF was received and the internal buffer is empty, return
        an empty bytes object.

        If n is zero, return empty bytes object immediatelly.

        If n is positive, this function try to read `n` bytes, and may return
        less or equal bytes than requested, but at least one byte. If EOF was
        received before any byte is read, this function returns empty byte
        object.

        Returned value is not limited with limit, configured at stream creation.

        If stream was paused, this function will automatically resume it if
        needed.
        Nr��read)
rir�rdrTrUrfrgrtr�ro)r�n�blocks�blockrMrrrr�@s$

zStreamReader.readccs�|dkrtd��n|jdk	r6|j�n|dkrFdSg}xr|dkr�|j|�DdH}|s�dj|�}t|t|�|��n|j|�|t|�8}qOWdj|�S)a�Read exactly `n` bytes.

        Raise an `IncompleteReadError` if EOF is reached before `n` bytes can be
        read. The `IncompleteReadError.partial` attribute of the exception will
        contain the partial read bytes.

        if n is zero, return empty bytes object.

        Returned value is not limited with limit, configured at stream creation.

        If stream was paused, this function will automatically resume it if
        needed.
        rz*readexactly size can not be less than zeroNr�)rcrir�rUrrrT)rr�r�r�rrrr�readexactlyrs	
zStreamReader.readexactlycCs|S)Nr)rrrr�	__aiter__�szStreamReader.__aiter__ccs*|j�DdH}|dkr&t�n|S)Nr�)r}ZStopAsyncIteration)r�valrrr�	__anext__�s	zStreamReader.__anext__r~)rrr rkrrWr`r?rmrHrorKrprLrrtr}rur�r�r
ZPY35r�r�rrrrrJs(	 X1,	i)r!�__all__Zsocket�hasattrrq�rr
rrrr�logrrk�EOFErrorr�	Exceptionrrrr	r
ZProtocolr3rrrrrrr�<module>sD		
		"B)G

?>