
    Vh	                         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e      Z G d	 d
e      Ze
 G d d             Zdededee   fdZdedee   defdZy)z
Buffer byte streams.
    )count)DictIteratorListTypeVar)Factorydefine)AMPCommandIntegerStringTc                   $    e Zd ZdZd e       fgZy)
StreamOpenz
    Open a new stream.
       streamIdN)__name__
__module____qualname____doc__r   response     J/home/dcms/DCMS/lib/python3.12/site-packages/twisted/trial/_dist/stream.pyr   r      s     gi()Hr   r   c                   4    e Zd ZdZd e       fd e       fgZy)StreamWritez,
    Write a chunk of data to a stream.
    r   s   dataN)r   r   r   r   r   Bytes	argumentsr   r   r   r   r      s$    
 
gi 	%'Ir   r   c                       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Zdededdfd	Zdedee   fd
Zy)StreamReceiverz9
    Buffering de-multiplexing byte stream receiver.
    _counter_streamsreturnc                 N    t        | j                        }g | j                  |<   |S )zE
        Open a new stream and return its unique identifier.
        )nextr    r!   )selfnewIds     r   openzStreamReceiver.open+   s%     T]]#!er   streamIdchunkNc                 @    | j                   |   j                  |       y)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)   s      r   writezStreamReceiver.write3   s     	h&&u-r   c                 8    | j                   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(   s     r   finishzStreamReceiver.finish;   s     }}  **r   )r   r   r   r   r   r    r   int__annotations__r   dictr!   r   r   bytesr'   r,   r/   r   r   r   r   r   "   sr     $gHhsm%'.t}Hd3U#$4c .c .% .D .+s +tE{ +r   r   data	chunkSizer"   c              #   j   K   d}|t        |       k  r| |||z     ||z  }|t        |       k  ryyw)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)r4   r5   poss      r   r)   r)   E   s@      C
D	/3y))y D	/s   .33ampchunksc                    K   | j                  t               d{   d   }t        |t              sJ |D ]"  }| j                  t        ||       d{    $ |S 7 B7 
w)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(   r4   )
callRemoter   
isinstancer0   r   )r9   r:   r(   oneChunks       r   streamr?   V   sh      nnZ00*=Hh$$$ Lnn[8(nKKKLO 1 	Ls!   A"A9A"A 	A" A"N)r   	itertoolsr   typingr   r   r   r   attrsr   r	   twisted.protocols.ampr
   r   r   r   r   r   r   r   r   r3   r0   r)   r?   r   r   r   <module>rD      s     0 0 ! H HCL* *'  + + +D # (5/ "c 8E? s r   