o
    >h	                     @   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   z/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/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.
        )nextr   r   )self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.
        )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,   )
callRemoter   
isinstancer(   r   )r0   r1   r"   oneChunkr   r   r   streamV   s   	r5   N)r   	itertoolsr   typingr   r   r   r   attrsr   r   twisted.protocols.ampr	   r
   r   r   r   r   r   r   r   r+   r(   r#   r5   r   r   r   r   <module>   s    "