o
    Óó·iŠ	  ã                   @   sÂ   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
 ddlmZmZmZmZ edƒZG dd„ deƒZG d	d
„ d
eƒZe
G dd„ dƒƒZdededee fdd„Zdedee defdd„ZdS )z
Buffer byte streams.
é    )Úcount)ÚDictÚIteratorÚListÚTypeVar)ÚFactoryÚdefine)ÚAMPÚCommandÚIntegerÚStringÚTc                   @   s   e Zd ZdZdeƒ fgZdS )Ú
StreamOpenz
    Open a new stream.
    ó   streamIdN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úresponse© r   r   ú`C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/trial/_dist/stream.pyr      s    r   c                   @   s$   e Zd ZdZdeƒ fdeƒ fgZdS )ÚStreamWritez,
    Write a chunk of data to a stream.
    r   s   dataN)r   r   r   r   r   ÚBytesÚ	argumentsr   r   r   r   r      s
    þr   c                   @   sz   e Zd ZU dZeƒ Zee ed< e	e
ƒZeeee f ed< defdd„Zdededd	fd
d„Zdedee fdd„Zd	S )ÚStreamReceiverz9
    Buffering de-multiplexing byte stream receiver.
    Ú_counterÚ_streamsÚreturnc                 C   s   t | jƒ}g | j|< |S )zE
        Open a new stream and return its unique identifier.
        N)Únextr   r   )ÚselfZnewIdr   r   r   Úopen+   s   

zStreamReceiver.openÚstreamIdÚchunkNc                 C   s   | j |  |¡ dS )z�
        Write to an open stream using its unique identifier.

        @raise KeyError: If there is no such open stream.
        N)r   Úappend)r   r!   r"   r   r   r   Úwrite3   s   zStreamReceiver.writec                 C   s   | j  |¡S )z°
        Indicate an open stream may receive no further data and return all of
        its current contents.

        @raise KeyError: If there is no such open stream.
        N)r   Úpop)r   r!   r   r   r   Úfinish;   s   zStreamReceiver.finish)r   r   r   r   r   r   r   ÚintÚ__annotations__r   Údictr   r   r   Úbytesr    r$   r&   r   r   r   r   r   "   s   
 r   ÚdataÚ	chunkSizer   c                 c   s@   � d}|t | ƒk r| ||| … V  ||7 }|t | ƒk s	dS dS )a  
    Break a byte string into pieces of no more than ``chunkSize`` length.

    @param data: The byte string.

    @param chunkSize: The maximum length of the resulting pieces.  All pieces
        except possibly the last will be this length.

    @return: The pieces.
    r   N)Úlen)r+   r,   Úposr   r   r   r"   E   s   €þr"   ÚampÚchunksc                 Ã   sH   �|   t¡I dH d }t|tƒsJ ‚|D ]}| j t||d�I dH  q|S )zö
    Send the given stream chunks, one by one, over the given connection.

    The chunks are sent using L{StreamWrite} over a stream opened using
    L{StreamOpen}.

    @return: The identifier of the stream over which the chunks were sent.
    Nr!   )r!   r+   )Z
callRemoter   Ú
isinstancer'   r   )r/   r0   r!   ZoneChunkr   r   r   ÚstreamV   s   €	r2   N)r   Ú	itertoolsr   Útypingr   r   r   r   Úattrsr   r   Ztwisted.protocols.ampr	   r
   r   r   r   r   r   r   r   r*   r'   r"   r2   r   r   r   r   Ú<module>   s    "