Ë
    ÛvžjQ&  ã                  ó¦   — d dl mZ d dlZd dlZd dlZd dlmZmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZ dgZ ej"                  d	«      Z G d
„ d«      Zy)é    )ÚannotationsN)ÚIteratorÚcasté   )ÚConcurrencyError)Ú	OP_BINARYÚOP_CONTÚOP_TEXTÚFrame)ÚDataÚ	Assemblerzutf-8c                  ó:   — e Zd ZdZdd„Zd	d
d„Zdd„Zdd„Zdd„Zy)r   z)
    Assemble messages from frames.

    c                óî   — t        j                  «       | _        t        j                  «       | _        t        j                  «       | _        d| _        d| _        d | _        g | _	        d | _
        d| _        y )NF)Ú	threadingÚLockÚmutexÚEventÚmessage_completeÚmessage_fetchedÚget_in_progressÚput_in_progressÚdecoderÚchunksÚchunks_queueÚclosed©Úselfs    úi/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/websockets/sync/messages.pyÚ__init__zAssembler.__init__   sk   € ô —^‘^Ó%ˆŒ
ô !*§¡Ó 1ˆÔä(Ÿ™Ó0ˆÔð  %ˆÔà$ˆÔð :>ˆŒð #%ˆŒð DHˆÔð ˆ�ó    Nc                óæ  — | j                   5  | j                  rt        d«      ‚| j                  rt	        d«      ‚d| _        ddd«       | j
                  j                  |«      }| j                   5  d| _        |st        d|d›d�«      ‚| j                  rt        d«      ‚| j
                  j                  «       sJ ‚| j
                  j                  «        | j                  €d	nd
}|j                  | j                  «      }g | _        | j                  �J ‚| j                  j                  «       rJ ‚| j                  j                  «        |cddd«       S # 1 sw Y   �ŒxY w# 1 sw Y   yxY w)a#  
        Read the next message.

        :meth:`get` returns a single :class:`str` or :class:`bytes`.

        If the message is fragmented, :meth:`get` waits until the last frame is
        received, then it reassembles the message and returns it. To receive
        messages frame by frame, use :meth:`get_iter` instead.

        Args:
            timeout: If a timeout is provided and elapses before a complete
                message is received, :meth:`get` raises :exc:`TimeoutError`.

        Raises:
            EOFError: If the stream of frames has ended.
            ConcurrencyError: If two threads run :meth:`get` or :meth:`get_iter`
                concurrently.
            TimeoutError: If a timeout is provided and elapses before a
                complete message is received.

        ústream of frames endedú&get() or get_iter() is already runningTNFztimed out in z.1fÚsr    Ú )r   r   ÚEOFErrorr   r   r   ÚwaitÚTimeoutErrorÚis_setÚclearr   Újoinr   r   r   Úset)r   ÚtimeoutÚ	completedÚjoinerÚmessages        r   ÚgetzAssembler.get>   s@  € ð, �Z‹ZØ�{Š{ÜÐ7Ó8Ð8à×#Ò#Ü&Ð'OÓPÐPà#'ˆDÔ ÷ ð ×)Ñ)×.Ñ.¨wÓ7ˆ	à�Z‹ZØ#(ˆDÔ ñ Ü" ]°7¸3°-¸qÐ#AÓBÐBð �{Š{ÜÐ7Ó8Ð8à×(Ñ(×/Ñ/Ô1Ð1Ð1Ø×!Ñ!×'Ñ'Ô)à"&§,¡,Ð"6™3¸BˆFà"ŸK™K¨¯©Ó4ˆGàˆDŒKØ×$Ñ$Ð,Ð,Ð,à×+Ñ+×2Ñ2Ô4Ð4Ð4Ø× Ñ ×$Ñ$Ô&à÷1 ‰Z÷ ‰Zú÷ ˆZús   �6EÁ2CE'ÅE$Å'E0c              #  ó¦  K  — | j                   5  | j                  rt        d«      ‚| j                  rt	        d«      ‚| j
                  }g | _        t        dt        j                  «       «      | _	        | j                  j                  «       r| j                  j                  d«       d| _        ddd«       D ]  }|–— Œ | j                  j                  «       x}�!|–— | j                  j                  «       x}�Œ!| j                   5  d| _        | j                  rt        d«      ‚| j                  j                  «       sJ ‚| j                  j                  «        | j
                  g k(  sJ ‚d| _	        | j                  j                  «       rJ ‚| j                  j!                  «        ddd«       y# 1 sw Y   �Œ
xY w# 1 sw Y   yxY w­w)a~  
        Stream the next message.

        Iterating the return value of :meth:`get_iter` yields a :class:`str` or
        :class:`bytes` for each frame in the message.

        The iterator must be fully consumed before calling :meth:`get_iter` or
        :meth:`get` again. Else, :exc:`ConcurrencyError` is raised.

        This method only makes sense for fragmented messages. If messages aren't
        fragmented, use :meth:`get` instead.

        Raises:
            EOFError: If the stream of frames has ended.
            ConcurrencyError: If two threads run :meth:`get` or :meth:`get_iter`
                concurrently.

        r"   r#   zqueue.SimpleQueue[Data | None]NTF)r   r   r&   r   r   r   r   ÚqueueÚSimpleQueuer   r   r)   Úputr1   r*   r   r,   )r   r   Úchunks      r   Úget_iterzAssembler.get_iter|   sŽ  è ø€ ð& �Z‹ZØ�{Š{ÜÐ7Ó8Ð8à×#Ò#Ü&Ð'OÓPÐPà—[‘[ˆFØˆDŒKÜ $à0Ü×!Ñ!Ó#ó!ˆDÔð ×$Ñ$×+Ñ+Ô-Ø×!Ñ!×%Ñ% dÔ+à#'ˆDÔ ÷+ ó2 ˆEØ‹Kð à×)Ñ)×-Ñ-Ó/Ð/ˆuÐ<ØŠKð ×)Ñ)×-Ñ-Ó/Ð/ˆuÑ<ð �Z‹ZØ#(ˆDÔ ð �{Š{ÜÐ7Ó8Ð8à×(Ñ(×/Ñ/Ô1Ð1Ð1Ø×!Ñ!×'Ñ'Ô)à—;‘; "Ò$Ð$Ð$Ø $ˆDÔà×+Ñ+×2Ñ2Ô4Ð4Ð4Ø× Ñ ×$Ñ$Ô&÷ ˆZ÷= ‰Zú÷< ˆZüs=   ‚G�B!F8Â0AGÄ GÄB#GÆ/	GÆ8GÆ=GÇGÇ
Gc                ó¶  — | j                   5  | j                  rt        d«      ‚| j                  rt	        d«      ‚|j
                  t        u rt        d¬«      | _        n.|j
                  t        u rd| _        n|j
                  t        u sJ ‚| j                  �1| j                  j                  |j                  |j                  «      }n|j                  }| j                  €| j                  j!                  |«       n| j                  j#                  |«       |j                  s
	 ddd«       y| j$                  j'                  «       rJ ‚| j$                  j)                  «        | j                  �| j                  j#                  d«       | j*                  j'                  «       rJ ‚d| _        ddd«       | j*                  j-                  «        | j                   5  d| _        | j                  rt        d«      ‚| j*                  j'                  «       sJ ‚| j*                  j/                  «        d| _        ddd«       y# 1 sw Y   Œ”xY w# 1 sw Y   yxY w)a,  
        Add ``frame`` to the next message.

        When ``frame`` is the final frame in a message, :meth:`put` waits until
        the message is fetched, which can be achieved by calling :meth:`get` or
        by fully consuming the return value of :meth:`get_iter`.

        :meth:`put` assumes that the stream of frames respects the protocol. If
        it doesn't, the behavior is undefined.

        Raises:
            EOFError: If the stream of frames has ended.
            ConcurrencyError: If two threads run :meth:`put` concurrently.

        r"   zput is already runningÚstrict)ÚerrorsNTF)r   r   r&   r   r   Úopcoder
   ÚUTF8Decoderr   r   r	   ÚdecodeÚdataÚfinr   r   Úappendr5   r   r)   r,   r   r'   r*   )r   Úframer>   s      r   r5   zAssembler.put½   sÛ  € ð  �Z‹ZØ�{Š{ÜÐ7Ó8Ð8à×#Ò#Ü&Ð'?Ó@Ð@à�|‰|œwÑ&Ü*°(Ô;�•Ø—‘¤Ñ*Ø#�•à—|‘|¤wÑ.Ð.Ð.ð �|‰|Ð'Ø—|‘|×*Ñ*¨5¯:©:°u·y±yÓA‘à—z‘z�à× Ñ Ð(Ø—‘×"Ñ" 4Õ(à×!Ñ!×%Ñ% dÔ+à—9’9Ø÷5 ˆZð< ×,Ñ,×3Ñ3Ô5Ð5Ð5Ø×!Ñ!×%Ñ%Ô'à× Ñ Ð,Ø×!Ñ!×%Ñ% dÔ+à×+Ñ+×2Ñ2Ô4Ð4Ð4à#'ˆDÔ ÷M ðT 	×Ñ×!Ñ!Ô#à�Z‹ZØ#(ˆDÔ ð �{Š{ÜÐ7Ó8Ð8à×'Ñ'×.Ñ.Ô0Ð0Ð0Ø× Ñ ×&Ñ&Ô(àˆDŒL÷ ˆZ÷Y ˆZú÷X ˆZús    �DIÄ0B IÇAIÉIÉIc                óf  — | j                   5  | j                  r
	 ddd«       yd| _        | j                  rA| j                  j	                  «        | j
                  �| j
                  j                  d«       | j                  r| j                  j	                  «        ddd«       y# 1 sw Y   yxY w)z¾
        End the stream of frames.

        Callling :meth:`close` concurrently with :meth:`get`, :meth:`get_iter`,
        or :meth:`put` is safe. They will raise :exc:`EOFError`.

        NT)	r   r   r   r   r,   r   r5   r   r   r   s    r   ÚclosezAssembler.close  s‰   € ð �Z‹ZØ�{Š{Ø÷ ˆZð ˆDŒKð ×#Ò#Ø×%Ñ%×)Ñ)Ô+Ø×$Ñ$Ð0Ø×%Ñ%×)Ñ)¨$Ô/ð ×#Ò#Ø×$Ñ$×(Ñ(Ô*÷ �Z‰Zús   �B'¤A:B'Â'B0)ÚreturnÚNone)N)r-   zfloat | NonerD   r   )rD   zIterator[Data])rA   r   rD   rE   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   r7   r5   rC   © r    r   r   r      s%   „ ñó
$ôL<ó|?'óBF ôP+r    )Ú
__future__r   Úcodecsr3   r   Útypingr   r   Ú
exceptionsr   Úframesr   r	   r
   r   r   Ú__all__Úgetincrementaldecoderr<   r   rJ   r    r   Ú<module>rR      sG   ðÝ "ã Û Û ß !å )ß 7Ó 7Ý ð ˆ-€à*ˆf×*Ñ*¨7Ó3€÷I+ò I+r    