
    Yf	                        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dS )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dS )
StreamOpenz
    Open a new stream.
       streamIdN)__name__
__module____qualname____doc__r   response     L/var/www/html/env/lib/python3.11/site-packages/twisted/trial/_dist/stream.pyr   r      s-          ggii()HHHr   r   c                   B    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=         
 
ggii 	%%''IIIr   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dS )StreamReceiverz9
    Buffering de-multiplexing byte stream receiver.
    _counter_streamsreturnc                 B    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                 F    | 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)   s      r   writezStreamReceiver.write3   s%     	h&&u-----r   c                 6    | 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   "   s           $eggHhsm%%%'.wt}}Hd3U#$444c    .c .% .D . . . .+s +tE{ + + + + + +r   r   data	chunkSizer"   c              #      K   d}|t          |           k     r)| |||z            V  ||z  }|t          |           k     '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)r4   r5   poss      r   r)   r)   E   sY       C
D		//3y())))y D		//////r   ampchunksc                    K   |                      t                     d{V d         }t          |t                    sJ |D ]%}|                      t          ||           d{V  &|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(   r4   )
callRemoter   
isinstancer0   r   )r9   r:   r(   oneChunks       r   streamr?   V   s       nnZ00000000*=Hh$$$$$ L Lnn[8(nKKKKKKKKKKOr   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 0 0 0 0 0 0 0 0 0 0 ! ! ! ! ! ! ! ! H H H H H H H H H H H HGCLL* * * * * * * *    '    + + + + + + + +D # (5/    "c 8E? s      r   