AlkantarClanX12

Your IP : 18.227.114.218


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



��Yf�^�	@s�dZdddddddgZdd	lZeed
�rOejddg�d
dlmZd
dlmZd
dlmZd
dlm	Z	d
dlm
Z
d
dlmZd#Z
Gdd�de�ZGdd�de�Ze
d	d	dd	de
dd��Ze
d	d	dd	de
dd��Zeed
�rze
d	dd	de
dd��Ze
d	dd	de
dd��ZGdd�de	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)�	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/python35/lib64/python3.5/asyncio/streams.pyr s	zIncompleteReadError.__init__)�__name__�
__module__�__qualname__�__doc__rrr)rrrscs(eZdZdZ�fdd�Z�S)rz�Reached the buffer limit while looking for a separator.

    Attributes:
    - consumed: total number of to be consumed bytes.
    cst�j|�||_dS)N)rr�consumed)r�messager!)rrrr-szLimitOverrunError.__init__)rrrr rrr)rrr's�loop�limitc	+s�|dkrtj�}td|d|�}t|d|��|j�fdd�|||�EdH\}}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>Ksz!open_connection.<locals>.<lambda>)r�get_event_looprrZcreate_connectionr)	�host�portr#r$�kwds�reader�	transport�_�writerr)r%rr2s)c+sK�dkrtj�����fdd�}�j||||�EdHS)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�factoryks	zstart_server.<locals>.factory)rr'Z
create_server)r/r(r)r#r$r*r0r)r/r$r#rrPsc+s�|dkrtj�}td|d|�}t|d|��|j�fdd�||�EdH\}}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	ws&c+sH�dkrtj�����fdd�}�j|||�EdHS)z=Similar to `start_server` but works with UNIX Domain Sockets.Ncs.td�d��}t|�d��}|S)Nr$r#)rr)r+r%)r/r$r#rrr0�s	z"start_unix_server.<locals>.factory)rr'Zcreate_unix_server)r/r1r#r$r*r0r)r/r$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<|jst�d|_|jj�r8tjd|�dS)NTz%r pauses writing)r4�AssertionErrorr3�	get_debugr�debug)rrrr�
pause_writing�s	zFlowControlMixin.pause_writingcCsr|jst�d|_|jj�r7tjd|�|j}|dk	rnd|_|j�sn|jd�dS)NFz%r resumes writing)	r4r7r3r8rr9r5�done�
set_result)r�waiterrrr�resume_writing�s			zFlowControlMixin.resume_writingcCsud|_|jsdS|j}|dkr/dSd|_|j�rHdS|dkrd|jd�n
|j|�dS)NT)r6r4r5r;r<�
set_exception)r�excr=rrr�connection_lost�s				z FlowControlMixin.connection_lostccsn|jrtd��|js"dS|j}|dksI|j�sIt�|jj�}||_|EdHdS)NzConnection lost)r6�ConnectionResetErrorr4r5�	cancelledr7r3�
create_future)rr=rrr�
_drain_helper�s				zFlowControlMixin._drain_helper)
rrrr rr:r>rArrErrrrr2�s	r2csdeZdZdZdd�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.)
    Ncs;t�jd|�||_d|_||_d|_dS)Nr#F)rr�_stream_reader�_stream_writer�_client_connected_cb�	_over_ssl)rZ
stream_readerr/r#)rrrr�s
			zStreamReaderProtocol.__init__cCs�|jj|�|jd�dk	|_|jdk	r�t|||j|j�|_|j|j|j�}tj	|�r�|jj
|�dS)NZ
sslcontext)rF�
set_transport�get_extra_inforIrHrr3rGrZiscoroutineZcreate_task)rr,�resrrr�connection_made�s	z$StreamReaderProtocol.connection_madecsa|jdk	r;|dkr+|jj�n|jj|�t�j|�d|_d|_dS)N)rF�feed_eofr?rrArG)rr@)rrrrA�s	z$StreamReaderProtocol.connection_lostcCs|jj|�dS)N)rF�	feed_data)r�datarrr�
data_received�sz"StreamReaderProtocol.data_receivedcCs|jj�|jrdSdS)NFT)rFrNrI)rrrr�eof_received�s
	z!StreamReaderProtocol.eof_received)	rrrr rrMrArQrRrr)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.
    cCsI||_||_|dks3t|t�s3t�||_||_dS)N)�
_transport�	_protocol�
isinstancerr7�_readerr3)rr,r%r+r#rrrrs
		!	zStreamWriter.__init__cCsM|jjd|jg}|jdk	r<|jd|j�ddj|�S)Nztransport=%rz	reader=%rz<%s>� )rrrSrV�append�join)r�inforrr�__repr__szStreamWriter.__repr__cCs|jS)N)rS)rrrrr,!szStreamWriter.transportcCs|jj|�dS)N)rS�write)rrPrrrr\%szStreamWriter.writecCs|jj|�dS)N)rS�
writelines)rrPrrrr](szStreamWriter.writelinescCs
|jj�S)N)rS�	write_eof)rrrrr^+szStreamWriter.write_eofcCs
|jj�S)N)rS�
can_write_eof)rrrrr_.szStreamWriter.can_write_eofcCs
|jj�S)N)rS�close)rrrrr`1szStreamWriter.closeNcCs|jj||�S)N)rSrK)r�name�defaultrrrrK4szStreamWriter.get_extra_infoccsi|jdk	r0|jj�}|dk	r0|�|jdk	rS|jj�rSdV|jj�EdHdS)z~Flush the write buffer.

        The intended use is to write

          w.write(data)
          yield from w.drain()
        N)rV�	exceptionrSZ
is_closingrTrE)rr@rrr�drain7s	zStreamWriter.drain)rrrr rr[�propertyr,r\r]r^r_r`rKrrdrrrrr	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'r3�	bytearray�_buffer�_eof�_waiter�
_exceptionrSr4)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>rW)rirXrrjrg�_DEFAULT_LIMITrkrlrSr4rY)rrZrrrr[es 			
				
zStreamReader.__repr__cCs|jS)N)rl)rrrrrcwszStreamReader.exceptioncCsD||_|j}|dk	r@d|_|j�s@|j|�dS)N)rlrkrCr?)rr@r=rrrr?zs			zStreamReader.set_exceptioncCs;|j}|dk	r7d|_|j�s7|jd�dS)z1Wakeup read*() functions waiting for data or EOF.N)rkrCr<)rr=rrr�_wakeup_waiter�s
		zStreamReader._wakeup_waitercCs(|jdkstd��||_dS)NzTransport already set)rSr7)rr,rrrrJ�szStreamReader.set_transportcCs;|jr7t|j�|jkr7d|_|jj�dS)NF)r4rrirgrS�resume_reading)rrrr�_maybe_resume_transport�s!	z$StreamReader._maybe_resume_transportcCsd|_|j�dS)NT)rjro)rrrrrN�s	zStreamReader.feed_eofcCs|jo|jS)z=Return True if the buffer is empty and 'feed_eof' was called.)rjri)rrrr�at_eof�szStreamReader.at_eofcCs�|jstd��|s dS|jj|�|j�|jdk	r�|jr�t|j�d|jkr�y|jj	�Wnt
k
r�d|_Yn
Xd|_dS)Nzfeed_data after feed_eofrT)rjr7ri�extendrorSr4rrgZ
pause_reading�NotImplementedError)rrPrrrrO�s


zStreamReader.feed_dataccs�|jdk	rtd|��|js5td��|jrTd|_|jj�|jj�|_z|jEdHWdd|_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 dataz_wait_for_data after EOFF)	rk�RuntimeErrorrjr7r4rSrpr3rD)rZ	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)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�	readuntilrrrri�
startswithr!�clearrqrf�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)	aVRead data from the stream until ``separator`` is found.

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

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

        If an EOF occurs and the complete separator is still not found,
        an IncompleteReadError exception will be raised, and the internal
        buffer will be reset.  The IncompleteReadError.partial attribute
        may contain the separator partially.

        If the data cannot be read because of over limit, a
        LimitOverrunError exception  will be raised, and the data
        will be left in the internal buffer, so it can be read again.
        rz,Separator should be at least one-byte stringNrz2Separator is not found, and chunk exceed the limitrwz2Separator is found, but chunk is longer than limit���)
rrfrlri�findrgrrj�bytesryrrvrq)rZ	separatorr|�offsetZbuflenZisep�chunkrrrrw�s:			

zStreamReader.readuntilrccs�|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)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 immediately.

        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)
rlr�rgrXrYrirjrvr�rq)r�nZblocks�blockrPrrrr�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)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��readexactly)
rfrlrrirjr�ryrrvrq)rr�Z
incompleterPrrrr�}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�)rrrrnrr[rcr?rorJrqrNrrrOrrvrrwr�r�r
ZPY35r�r�ZPY352rrrrrPs,	 [2*		i)r �__all__Zsocket�hasattrrs�rr
rrr�logrrn�EOFErrorr�	Exceptionrrrr	r
ZProtocolr2rrrrrrr�<module>sB				"B3G