Your IP : 18.118.208.127


Current Path : /opt/alt/python310/lib64/python3.10/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/asyncio/__pycache__/streams.cpython-310.pyc

o

6��f�d�@s&dZddlZddlZddlZddlZddlZeed�red7ZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZddl
mZddlmZd
Zded�dd�Zded�dd�Zeed�rpd ed�dd�Zd ed�dd�ZGdd�dej�ZGdd�deej�ZGdd�d�ZGdd�d�ZdS)!)�StreamReader�StreamWriter�StreamReaderProtocol�open_connection�start_server�NZAF_UNIX)�open_unix_connection�start_unix_server�)�
coroutines)�events)�
exceptions)�format_helpers)�	protocols)�logger)�sleepi)�limitc	�s`�t��}t||d�}t||d��|j�fdd�||fi|��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.)
    �r�loop�rc��S�N�r��protocolr�6/opt/alt/python310/lib64/python3.10/asyncio/streams.py�<lambda>1�z!open_connection.<locals>.<lambda>N)r�get_running_looprrZcreate_connectionr)	�host�portr�kwdsr�reader�	transport�_�writerrrrrs���rc�s6�t������fdd�}�j|||fi|��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.
    c�t��d�}t|��d�}|S�Nrr�rr�r!r��client_connected_cbrrrr�factoryO�
�zstart_server.<locals>.factoryN)rrZ
create_server)r*rrrr r+rr)rr6s�rc�s^�t��}t||d�}t||d��|j�fdd�|fi|��IdH\}}t|�||�}||fS)z@Similar to `open_connection` but works with UNIX Domain Sockets.rrcrrrrrrrrcrz&open_unix_connection.<locals>.<lambda>N)rrrrZcreate_unix_connectionr)�pathrr rr!r"r#r$rrrr[s���rc�s4�t������fdd�}�j||fi|��IdHS)z=Similar to `start_server` but works with UNIX Domain Sockets.cr%r&r'r(r)rrr+lr,z"start_unix_server.<locals>.factoryN)rrZcreate_unix_server)r*r-rr r+rr)rrgs�rc@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�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.
    NcCs8|durtjdd�|_n||_d|_t��|_d|_dS)N�)�
stacklevelF)r�_get_event_loop�_loop�_paused�collections�deque�_drain_waiters�_connection_lost)�selfrrrr�__init__s

zFlowControlMixin.__init__cCs.|jrJ�d|_|j��rt�d|�dSdS)NTz%r pauses writing)r3r2�	get_debugr�debug�r8rrr�
pause_writing�s


�zFlowControlMixin.pause_writingcCsH|jsJ�d|_|j��rt�d|�|jD]}|��s!|�d�qdS)NFz%r resumes writing)r3r2r:rr;r6�done�
set_result�r8�waiterrrr�resume_writing�s



��zFlowControlMixin.resume_writingcCsFd|_|jsdS|jD]}|��s |dur|�d�q|�|�qdS�NT)r7r3r6r>r?�
set_exception�r8�excrArrr�connection_lost�s

��z FlowControlMixin.connection_lostc	�s\�|jrtd��|js
dS|j��}|j�|�z|IdHW|j�|�dS|j�|�w)NzConnection lost)r7�ConnectionResetErrorr3r2�
create_futurer6�append�remover@rrr�
_drain_helper�s�
zFlowControlMixin._drain_helpercCst�r)�NotImplementedError�r8�streamrrr�_get_close_waiter��z"FlowControlMixin._get_close_waiterr)
�__name__�
__module__�__qualname__�__doc__r9r=rBrGrLrPrrrrr.us
		

r.csfeZdZdZdZd�fdd�	Zedd��Zdd�Z�fd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
�ZS)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.)
    Ncstt�j|d�|durt�|�|_|j|_nd|_|dur ||_d|_d|_d|_	d|_
||_d|_|j
��|_dS)NrF)�superr9�weakref�ref�_stream_reader_wr�_source_traceback�_strong_reader�_reject_connection�_stream_writer�_task�
_transport�_client_connected_cb�	_over_sslr2rI�_closed)r8Z
stream_readerr*r��	__class__rrr9�s
zStreamReaderProtocol.__init__cCs|jdurdS|��Sr)rYr<rrr�_stream_reader�s
z#StreamReaderProtocol._stream_readercCs�|jrddi}|jr|j|d<|j�|�|��dS||_|j}|dur*|�|�|�d�du|_	|j
durXt||||j�|_|�
||j�}t
�|�rS|j�|�|_d|_dSdS)N�messagezpAn open stream was garbage collected prior to establishing network connection; call "stream.close()" explicitly.Zsource_tracebackZ
sslcontext)r\rZr2Zcall_exception_handler�abortr_re�
set_transport�get_extra_inforar`rr]r
ZiscoroutineZcreate_taskr^r[)r8r"�contextr!�resrrr�connection_made�s2�


��

�z$StreamReaderProtocol.connection_madecs~|j}|dur|dur|��n|�|�|j��s+|dur%|j�d�n|j�|�t��|�d|_d|_	d|_
d|_dSr)re�feed_eofrDrbr>r?rVrGrYr]r^r_)r8rFr!rcrrrG�s



z$StreamReaderProtocol.connection_lostcCs |j}|dur|�|�dSdSr)re�	feed_data)r8�datar!rrr�
data_receiveds�z"StreamReaderProtocol.data_receivedcCs$|j}|dur|��|jrdSdS)NFT)rermra)r8r!rrr�eof_receivedsz!StreamReaderProtocol.eof_receivedcC�|jSr)rbrNrrrrP�z&StreamReaderProtocol._get_close_waitercCsDz|j}Wn
tyYdSw|��r|��s |��dSdSdSr)rb�AttributeErrorr>�	cancelled�	exception)r8�closedrrr�__del__s
��zStreamReaderProtocol.__del__�NN)rRrSrTrUrZr9�propertyrerlrGrprqrPrx�
__classcell__rrrcrr�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.
    cCsJ||_||_|dust|t�sJ�||_||_|j��|_|j�d�dSr)	r_�	_protocol�
isinstancer�_readerr2rIZ
_complete_futr?)r8r"rr!rrrrr90szStreamWriter.__init__cCs@|jjd|j��g}|jdur|�d|j���d�d�|��S)N�
transport=zreader=�<{}>� )rdrRr_r~rJ�format�join�r8�inforrr�__repr__:s
zStreamWriter.__repr__cCrrr�r_r<rrrr"@szStreamWriter.transportcC�|j�|�dSr)r_�write�r8rorrrr�D�zStreamWriter.writecCr�r)r_�
writelinesr�rrrr�Gr�zStreamWriter.writelinescC�
|j��Sr)r_�	write_eofr<rrrr�J�
zStreamWriter.write_eofcCr�r)r_�
can_write_eofr<rrrr�Mr�zStreamWriter.can_write_eofcCr�r)r_�closer<rrrr�Pr�zStreamWriter.closecCr�r)r_�
is_closingr<rrrr�Sr�zStreamWriter.is_closingc�s�|j�|�IdHdSr)r|rPr<rrr�wait_closedVs�zStreamWriter.wait_closedNcCs|j�||�Sr)r_ri)r8�name�defaultrrrriYszStreamWriter.get_extra_infoc�sN�|jdur|j��}|dur|�|j��rtd�IdH|j��IdHdS)zyFlush the write buffer.

        The intended use is to write

          w.write(data)
          await w.drain()
        Nr)r~rvr_r�rr|rL)r8rFrrr�drain\s�



zStreamWriter.drainr)rRrSrTrUr9r�rzr"r�r�r�r�r�r�r�rir�rrrrr&s	


rc@s�eZdZdZedfdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd&dd�Zd'dd�Zd d!�Zd"d#�Zd$d%�ZdS)(rNcCsz|dkrtd��||_|durt��|_n||_t�|_d|_d|_d|_	d|_
d|_|j��r;t
�t�d��|_dSdS)NrzLimit cannot be <= 0Fr	)�
ValueError�_limitrr1r2�	bytearray�_buffer�_eof�_waiter�
_exceptionr_r3r:r
�
extract_stack�sys�	_getframerZ)r8rrrrrr9zs"

��zStreamReader.__init__cCs�dg}|jr|�t|j��d��|jr|�d�|jtkr'|�d|j���|jr3|�d|j���|jr?|�d|j���|jrK|�d|j���|j	rS|�d�d	�
d
�|��S)Nrz bytes�eofzlimit=zwaiter=z
exception=rZpausedr�r�)r�rJ�lenr�r��_DEFAULT_LIMITr�r�r_r3r�r�r�rrrr��s 


zStreamReader.__repr__cCrrr)r�r<rrrrv�rszStreamReader.exceptioncCs8||_|j}|durd|_|��s|�|�dSdSdSr)r�r�rurDrErrrrD�s�zStreamReader.set_exceptioncCs2|j}|durd|_|��s|�d�dSdSdS)z1Wakeup read*() functions waiting for data or EOF.N)r�rur?r@rrr�_wakeup_waiter�s�zStreamReader._wakeup_waitercCs|jdus	Jd��||_dS)NzTransport already setr�)r8r"rrrrh�s
zStreamReader.set_transportcCs2|jrt|j�|jkrd|_|j��dSdSdS)NF)r3r�r�r�r_�resume_readingr<rrr�_maybe_resume_transport�s�z$StreamReader._maybe_resume_transportcCsd|_|��dSrC)r�r�r<rrrrm�szStreamReader.feed_eofcCs|jo|jS)z=Return True if the buffer is empty and 'feed_eof' was called.)r�r�r<rrr�at_eof�szStreamReader.at_eofcCs�|jrJd��|sdS|j�|�|��|jdurA|jsCt|j�d|jkrEz|j��Wn
t	y;d|_YdSwd|_dSdSdSdS)Nzfeed_data after feed_eof�T)
r�r��extendr�r_r3r�r�Z
pause_readingrMr�rrrrn�s"
��
�zStreamReader.feed_datac�sl�|jdur
t|�d���|jrJd��|jrd|_|j��|j��|_z|jIdHWd|_dSd|_w)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)r��RuntimeErrorr�r3r_r�r2rI)r8Z	func_namerrr�_wait_for_data�s�
	�
zStreamReader._wait_for_datac
�s��d}t|�}z|�|�IdH}W|Stjy(}z	|jWYd}~Sd}~wtjyV}z"|j�||j�rB|jd|j|�=n|j�	�|�
�t|jd��d}~ww)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��	readuntilr�IncompleteReadError�partial�LimitOverrunErrorr��
startswith�consumed�clearr�r��args)r8�sep�seplen�line�errr�readline�s"�
��
��zStreamReader.readliner�c�s�t|�}|dkr
td��|jdur|j�d}	t|j�}|||kr@|j�||�}|dkr/n-|d|}||jkr@t�d|��|jrSt	|j�}|j�
�t�|d��|�d�IdHq||jkrgt�d	|��|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 stringNT���r	z2Separator is not found, and chunk exceed the limitr�z2Separator is found, but chunk is longer than limit)r�r�r�r��findr�rr�r��bytesr�r�r�r�)r8Z	separatorr��offsetZbuflenZisep�chunkrrrr�sB�


�

�
 �zStreamReader.readuntilr�c�s��|jdur	|j�|dkrdS|dkr-g}	|�|j�IdH}|s"n|�|�qd�|�S|js;|js;|�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, then return all read bytes.
        If EOF was received and the internal buffer is empty,
        return an empty bytes object.

        If `n` is 0, return an empty bytes object immediately.

        If `n` is positive, return at most `n` available bytes
        as soon as at least 1 byte is available in the internal buffer.
        If EOF is received before any byte is read, return an 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.
        Nr�T�read)
r�r�r�rJr�r�r�r�r�r�)r8�nZblocks�blockrorrrr�ss(�

�
zStreamReader.readc�s��|dkr	td��|jdur|j�|dkrdSt|j�|kr@|jr1t|j�}|j��t�||��|�	d�IdHt|j�|kst|j�|krRt|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)r�r�r�r�r�r�r�rr�r�r�)r8r�Z
incompleterorrrr��s*�


�
zStreamReader.readexactlycCs|Srrr<rrr�	__aiter__�rQzStreamReader.__aiter__c�s �|��IdH}|dkrt�|S)Nr�)r��StopAsyncIteration)r8�valrrr�	__anext__�s
�zStreamReader.__anext__)r�)r�)rRrSrTrZr�r9r�rvrDr�rhr�rmr�rnr�r�r�r�r�r�r�rrrrrvs&	

[3)rryr)�__all__r4Zsocketr��warningsrW�hasattr�r
rrr
r�logrZtasksrr�rrrrZProtocolr.rrrrrrr�<module>sB
��
"��@qP

?>