Hacked By AnonymousFox

Current Path : /proc/thread-self/root/proc/self/root/opt/alt/python37/lib64/python3.7/asyncio/__pycache__/
Upload File :
Current File : //proc/thread-self/root/proc/self/root/opt/alt/python37/lib64/python3.7/asyncio/__pycache__/streams.cpython-37.pyc

B

� f`�@sdZddlZeed�red7ZddlmZddlmZddlmZdd	lmZdd
l	m
Z
dZGdd
�d
e�Z
Gdd�de�Zd!ded�dd�Zd"ded�dd�Zeed�r�d#ded�dd�Zd$ded�dd�ZGdd�dej�ZGdd�deej�ZGdd�d�ZGdd �d �ZdS)%)�StreamReader�StreamWriter�StreamReaderProtocol�open_connection�start_server�IncompleteReadError�LimitOverrunError�NZAF_UNIX)�open_unix_connection�start_unix_server�)�
coroutines)�events)�	protocols)�logger)�sleepics(eZdZdZ�fdd�Zdd�Z�ZS)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)
    cs,t��t|��d|�d��||_||_dS)Nz bytes read on a total of z expected bytes)�super�__init__�len�partial�expected)�selfrr)�	__class__��4/opt/alt/python37/lib64/python3.7/asyncio/streams.pyrszIncompleteReadError.__init__cCst|�|j|jffS)N)�typerr)rrrr�
__reduce__#szIncompleteReadError.__reduce__)�__name__�
__module__�__qualname__�__doc__rr�
__classcell__rr)rrrsrcs(eZdZdZ�fdd�Zdd�Z�ZS)rz�Reached the buffer limit while looking for a separator.

    Attributes:
    - consumed: total number of to be consumed bytes.
    cst��|�||_dS)N)rr�consumed)r�messager!)rrrr-szLimitOverrunError.__init__cCst|�|jd|jffS)Nr)r�argsr!)rrrrr1szLimitOverrunError.__reduce__)rrrrrrr rr)rrr'sr)�loop�limitc	�sb|dkrt��}t||d�}t||d��|j�fdd�||f|�IdH\}}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.)
    N)r%r$)r$cs�S)Nrr)�protocolrr�<lambda>M�z!open_connection.<locals>.<lambda>)r
�get_event_looprrZcreate_connectionr)	�host�portr$r%�kwds�reader�	transport�_�writerr)r&rr5s rc�s8�dkrt������fdd�}�j|||f|�IdHS)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.
    Ncst��d�}t|��d�}|S)N)r%r$)r$)rr)r-r&)�client_connected_cbr%r$rr�factorylszstart_server.<locals>.factory)r
r)Z
create_server)r1r*r+r$r%r,r2r)r1r%r$rrRsrc�s`|dkrt��}t||d�}t||d��|j�fdd�|f|�IdH\}}t|�||�}||fS)z@Similar to `open_connection` but works with UNIX Domain Sockets.N)r%r$)r$cs�S)Nrr)r&rrr'�r(z&open_unix_connection.<locals>.<lambda>)r
r)rrZcreate_unix_connectionr)�pathr$r%r,r-r.r/r0r)r&rr	xsr	c�s6�dkrt������fdd�}�j||f|�IdHS)z=Similar to `start_server` but works with UNIX Domain Sockets.Ncst��d�}t|��d�}|S)N)r%r$)r$)rr)r-r&)r1r%r$rrr2�sz"start_unix_server.<locals>.factory)r
r)Zcreate_unix_server)r1r3r$r%r,r2r)r1r%r$rr
�sr
c@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�FlowControlMixina)Reusable flow control logic for StreamWriter.drain().

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

    StreamWriter.drain() must wait for _drain_helper() coroutine.
    NcCs0|dkrt��|_n||_d|_d|_d|_dS)NF)r
r)�_loop�_paused�
_drain_waiter�_connection_lost)rr$rrrr�szFlowControlMixin.__init__cCs*|jr
t�d|_|j��r&t�d|�dS)NTz%r pauses writing)r6�AssertionErrorr5�	get_debugr�debug)rrrr�
pause_writing�s

zFlowControlMixin.pause_writingcCsP|js
t�d|_|j��r&t�d|�|j}|dk	rLd|_|��sL|�d�dS)NFz%r resumes writing)	r6r9r5r:rr;r7�done�
set_result)r�waiterrrr�resume_writing�s

zFlowControlMixin.resume_writingcCsVd|_|jsdS|j}|dkr"dSd|_|��r4dS|dkrH|�d�n
|�|�dS)NT)r8r6r7r=r>�
set_exception)r�excr?rrr�connection_lost�sz FlowControlMixin.connection_lostc�sP|jrtd��|jsdS|j}|dks2|��s2t�|j��}||_|IdHdS)NzConnection lost)r8�ConnectionResetErrorr6r7�	cancelledr9r5�
create_future)rr?rrr�
_drain_helper�s
zFlowControlMixin._drain_helper)N)	rrrrrr<r@rCrGrrrrr4�s
	r4csNeZdZdZd�fdd�	Zdd�Z�fdd�Zd	d
�Zdd�Zd
d�Z	�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.)
    Ncs6t�j|d�||_d|_||_d|_|j��|_dS)N)r$F)	rr�_stream_reader�_stream_writer�_client_connected_cb�	_over_sslr5rF�_closed)rZ
stream_readerr1r$)rrrr�szStreamReaderProtocol.__init__cCsd|j�|�|�d�dk	|_|jdk	r`t|||j|j�|_|�|j|j�}t�	|�r`|j�
|�dS)NZ
sslcontext)rH�
set_transport�get_extra_inforKrJrr5rIrZiscoroutineZcreate_task)rr.Zresrrr�connection_made�s


z$StreamReaderProtocol.connection_madecsr|jdk	r*|dkr|j��n|j�|�|j��sV|dkrJ|j�d�n|j�|�t��|�d|_d|_dS)N)	rH�feed_eofrArLr=r>rrCrI)rrB)rrrrC�s

z$StreamReaderProtocol.connection_lostcCs|j�|�dS)N)rH�	feed_data)r�datarrr�
data_receivedsz"StreamReaderProtocol.data_receivedcCs|j��|jrdSdS)NFT)rHrPrK)rrrr�eof_receiveds
z!StreamReaderProtocol.eof_receivedcCs"|j}|��r|��s|��dS)N)rLr=rE�	exception)r�closedrrr�__del__szStreamReaderProtocol.__del__)NN)rrrrrrOrCrSrTrWr rr)rrr�s	rc@sveZdZdZdd�Zdd�Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zddd�Zdd�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.
    cCs2||_||_|dks"t|t�s"t�||_||_dS)N)�
_transport�	_protocol�
isinstancerr9�_readerr5)rr.r&r-r$rrrrs
zStreamWriter.__init__cCs@|jjd|j��g}|jdk	r0|�d|j���d�d�|��S)Nz
transport=zreader=z<{}>� )rrrXr[�append�format�join)r�inforrr�__repr__&s
zStreamWriter.__repr__cCs|jS)N)rX)rrrrr.,szStreamWriter.transportcCs|j�|�dS)N)rX�write)rrRrrrrb0szStreamWriter.writecCs|j�|�dS)N)rX�
writelines)rrRrrrrc3szStreamWriter.writelinescCs
|j��S)N)rX�	write_eof)rrrrrd6szStreamWriter.write_eofcCs
|j��S)N)rX�
can_write_eof)rrrrre9szStreamWriter.can_write_eofcCs
|j��S)N)rX�close)rrrrrf<szStreamWriter.closecCs
|j��S)N)rX�
is_closing)rrrrrg?szStreamWriter.is_closingc�s|jjIdHdS)N)rYrL)rrrr�wait_closedBszStreamWriter.wait_closedNcCs|j�||�S)N)rXrN)r�name�defaultrrrrNEszStreamWriter.get_extra_infoc�sR|jdk	r |j��}|dk	r |�|j��r>td|jd�IdH|j��IdHdS)zyFlush the write buffer.

        The intended use is to write

          w.write(data)
          await w.drain()
        Nr)r$)r[rUrXrgrr5rYrG)rrBrrr�drainHs


zStreamWriter.drain)N)rrrrrra�propertyr.rbrcrdrerfrgrhrNrkrrrrrs
rc@s�eZdZedfdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd&dd�Zd'dd�Zd d!�Zd"d#�Zd$d%�ZdS)(rNcCsZ|dkrtd��||_|dkr*t��|_n||_t�|_d|_d|_d|_	d|_
d|_dS)NrzLimit cannot be <= 0F)�
ValueError�_limitr
r)r5�	bytearray�_buffer�_eof�_waiter�
_exceptionrXr6)rr%r$rrrraszStreamReader.__init__cCs�dg}|jr"|�t|j��d��|jr2|�d�|jtkrN|�d|j���|jrf|�d|j���|jr~|�d|j���|jr�|�d|j���|j	r�|�d�d	�
d
�|��S)Nrz bytes�eofzlimit=zwaiter=z
exception=z
transport=Zpausedz<{}>r\)rpr]rrqrn�_DEFAULT_LIMITrrrsrXr6r^r_)rr`rrrrats 


zStreamReader.__repr__cCs|jS)N)rs)rrrrrU�szStreamReader.exceptioncCs0||_|j}|dk	r,d|_|��s,|�|�dS)N)rsrrrErA)rrBr?rrrrA�szStreamReader.set_exceptioncCs*|j}|dk	r&d|_|��s&|�d�dS)z1Wakeup read*() functions waiting for data or EOF.N)rrrEr>)rr?rrr�_wakeup_waiter�s
zStreamReader._wakeup_waitercCs|jdkstd��||_dS)NzTransport already set)rXr9)rr.rrrrM�szStreamReader.set_transportcCs*|jr&t|j�|jkr&d|_|j��dS)NF)r6rrprnrX�resume_reading)rrrr�_maybe_resume_transport�sz$StreamReader._maybe_resume_transportcCsd|_|��dS)NT)rqrv)rrrrrP�szStreamReader.feed_eofcCs|jo|jS)z=Return True if the buffer is empty and 'feed_eof' was called.)rqrp)rrrr�at_eof�szStreamReader.at_eofcCs�|jrtd��|sdS|j�|�|��|jdk	r~|js~t|j�d|jkr~y|j�	�Wnt
k
rvd|_YnXd|_dS)Nzfeed_data after feed_eof�T)rqr9rp�extendrvrXr6rrnZ
pause_reading�NotImplementedError)rrRrrrrQ�s
zStreamReader.feed_datac�sf|jdk	rt|�d���|jr&td��|jr<d|_|j��|j��|_z|jIdHWdd|_XdS)zpWait until feed_data() or feed_eof() is called.

        If stream was paused, automatically resume it.
        NzF() called while another coroutine is already waiting for incoming dataz_wait_for_data after EOFF)	rr�RuntimeErrorrqr9r6rXrwr5rF)rZ	func_namerrr�_wait_for_data�s	

zStreamReader._wait_for_datac
�s�d}t|�}y|�|�IdH}Wn�tk
rD}z|jSd}~XYnftk
r�}zH|j�||j�rx|jd|j|�=n
|j��|�	�t
|jd��Wdd}~XYnX|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.
        �
Nr)r�	readuntilrrrrp�
startswithr!�clearrxrmr#)r�sep�seplen�line�errr�readline�s
 zStreamReader.readlinerc�s�t|�}|dkrtd��|jdk	r(|j�d}x�t|j�}|||kr||j�||�}|dkr\P|d|}||jkr|td|��|jr�t|j�}|j�	�t
|d��|�d�IdHq.W||jkr�td|��|jd||�}|jd||�=|��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 stringN���rz2Separator is not found, and chunk exceed the limitr�z2Separator is found, but chunk is longer than limit)
rrmrsrp�findrnrrq�bytesr�rr~rx)rZ	separatorr��offsetZbuflenZisep�chunkrrrr��s:






zStreamReader.readuntilr�c�s�|jdk	r|j�|dkrdS|dkrZg}x&|�|j�IdH}|sBP|�|�q*Wd�|�S|jsv|jsv|�d�IdHt|jd|��}|jd|�=|�	�|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.
        Nrr(�read)
rsr�rnr]r_rprqr~r�rx)r�nZblocks�blockrRrrrr�Ws$

zStreamReader.readc�s�|dkrtd��|jdk	r |j�|dkr,dSxFt|j�|krr|jr`t|j�}|j��t||��|�d�IdHq.Wt|j�|kr�t|j�}|j��nt|jd|��}|jd|�=|�	�|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)
rmrsrrprqr�r�rr~rx)rr�Z
incompleterRrrrr��s&




zStreamReader.readexactlycCs|S)Nr)rrrr�	__aiter__�szStreamReader.__aiter__c�s|��IdH}|dkrt�|S)Nr()r��StopAsyncIteration)r�valrrr�	__anext__�szStreamReader.__anext__)r)r�)rrrrurrarUrArvrMrxrPryrQr~r�r�r�r�r�r�rrrrr_s"	
[
2)r)NN)NN)N)N)�__all__Zsocket�hasattr�rr
r�logrZtasksrru�EOFErrorr�	Exceptionrrrr	r
ZProtocolr4rrrrrrr�<module>s0
"
A@K

Hacked By AnonymousFox1.0, Coded By AnonymousFox