Ë
    RPf%  ã                  óš   — d dl mZ d dlZd dlZd dlZd dlmZmZmZm	Z	 ddl
mZmZ ddlmZ dgZ ej                  d«      Z G d	„ d«      Zy)
é    )ÚannotationsN)ÚIteratorÚListÚOptionalÚcasté   )ÚFrameÚOpcode)Ú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    úR/var/www/fastapitest/venv/lib/python3.12/site-packages/websockets/sync/messages.pyÚ__init__zAssembler.__init__   sl   € ô —^‘^Ó%ˆŒ
ô
 !*§¡Ó 1ˆÔä(Ÿ™Ó0ˆÔð  %ˆÔà$ˆÔð =AˆŒð #%ˆŒð LPˆÔð ˆ�ó    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                  «      }| j                  j                  «       rJ ‚| j                  j                  «        g | _        | 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.
            RuntimeError: If two threads run :meth:`get` or :meth:``get_iter`
                concurrently.

        ústream of frames endedú"get or get_iter is already runningTNFztimed out in z.1fÚsr   Ú )r   r   ÚEOFErrorr   ÚRuntimeErrorr   ÚwaitÚTimeoutErrorÚis_setÚclearr   Újoinr   r   Úsetr   )r   ÚtimeoutÚ	completedÚjoinerÚmessages        r   ÚgetzAssembler.get;   sS  € ð( �Z‰Zñ 	(Ø�{Š{ÜÐ7Ó8Ð8à×#Ò#Ü"Ð#GÓHÐHà#'ˆ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à×+Ñ+×2Ñ2Ô4Ð4Ð4Ø× Ñ ×$Ñ$Ô&àˆDŒKØ×$Ñ$Ð,Ð,Ð,à÷1	ñ 	÷	(ñ 	(ú÷	ð 	ús   �6EÁ2CE'ÅE$Å'E0c              #  ór  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«       E d{  –—†  	 | j                  j                  «       }|€n|–— Œ"| j                   5  d| _        | j                  j                  «       sJ ‚| j                  j                  «        | j                  rt        d«      ‚| j                  j                  «       rJ ‚| j                  j!                  «        | j
                  g k(  sJ ‚d| _	        ddd«       y# 1 sw Y   ŒîxY w7 Œë# 1 sw Y   yxY w­w)aw  
        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:`RuntimeError` 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.
            RuntimeError: If two threads run :meth:`get` or :meth:``get_iter`
                concurrently.

        r!   r"   z!queue.SimpleQueue[Optional[Data]]NTF)r   r   r%   r   r&   r   r   ÚqueueÚSimpleQueuer   r   r)   Úputr1   r*   r   r,   )r   r   Úchunks      r   Úget_iterzAssembler.get_iterw   s�  è ø€ ð& �Z‰Zñ 	(Ø�{Š{ÜÐ7Ó8Ð8à×#Ò#Ü"Ð#GÓHÐHà—[‘[ˆFØˆDŒKÜ $à3Ü×!Ñ!Ó#ó!ˆDÔð ×$Ñ$×+Ñ+Ô-Ø×!Ñ!×%Ñ% dÔ+à#'ˆDÔ ÷+	(ð0 ×ÐØØ×%Ñ%×)Ñ)Ó+ˆEØˆ}ØØŠKð	 ð �Z‰Zñ 	%Ø#(ˆDÔ à×(Ñ(×/Ñ/Ô1Ð1Ð1Ø×!Ñ!×'Ñ'Ô)ð �{Š{ÜÐ7Ó8Ð8à×+Ñ+×2Ñ2Ô4Ð4Ð4Ø× Ñ ×$Ñ$Ô&à—;‘; "Ò$Ð$Ð$Ø $ˆDÔ÷	%ð 	%÷?	(ð 	(úð0 	ø÷	%ð 	%üsB   ‚F7�B!FÂ0F7Â=F)Â>3F7Ã1B#F+Æ	F7ÆF&Æ"F7Æ+F4Æ0F7c                ó  — | j                   5  | j                  rt        d«      ‚| j                  rt	        d«      ‚|j
                  t        j                  u rt        d¬«      | _	        nK|j
                  t        j                  u rd| _	        n'|j
                  t        j                  u rn
	 ddd«       y| 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,                  j)                  «       sJ ‚| j,                  j1                  «        | j                  rt        d«      ‚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, either 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.
            RuntimeError: If two threads run :meth:`put` concurrently.

        r!   zput is already runningÚstrict)ÚerrorsNTF)r   r   r%   r   r&   Úopcoder
   ÚTEXTÚUTF8Decoderr   ÚBINARYÚCONTÚdecodeÚdataÚfinr   r   Úappendr5   r   r)   r,   r   r'   r*   )r   ÚframerA   s      r   r5   zAssembler.put¹   s
  € ð  �Z‰Zñ )	(Ø�{Š{ÜÐ7Ó8Ð8à×#Ò#Ü"Ð#;Ó<Ð<à�|‰|œvŸ{™{Ñ*Ü*°(Ô;�•Ø—‘¤§¡Ñ.Ø#�•Ø—‘¤§¡Ñ,Øð ÷)	(ð )	(ð$ �|‰|Ð'Ø—|‘|×*Ñ*¨5¯:©:°u·y±yÓA‘à—z‘z�à× Ñ Ð(Ø—‘×"Ñ" 4Õ(à×!Ñ!×%Ñ% dÔ+à—9’9Ø÷;)	(ð )	(ðB ×,Ñ,×3Ñ3Ô5Ð5Ð5Ø×!Ñ!×%Ñ%Ô'à× Ñ Ð,Ø×!Ñ!×%Ñ% dÔ+à×+Ñ+×2Ñ2Ô4Ð4Ð4à#'ˆDÔ ÷S)	(ðX 	×Ñ×!Ñ!Ô#à�Z‰Zñ 
	 Ø#(ˆDÔ à×'Ñ'×.Ñ.Ô0Ð0Ð0Ø× Ñ ×&Ñ&Ô(ð �{Š{ÜÐ7Ó8Ð8àˆDŒL÷
	 ð 
	 ÷])	(ð )	(ú÷\
	 ð 
	 ús'   �BI*Â5BI*ÅB I*ÈAI6É*I3É6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ñ 	+Ø�{Š{Ø÷	+ð 	+ð ˆDŒKð ×#Ò#Ø×%Ñ%×)Ñ)Ô+Ø×$Ñ$Ð0Ø×%Ñ%×)Ñ)¨$Ô/ð ×#Ò#Ø×$Ñ$×(Ñ(Ô*÷	+÷ 	+ñ 	+ús   �B'¤A:B'Â'B0)ÚreturnÚNone)N)r-   zOptional[float]rG   r   )rG   zIterator[Data])rD   r	   rG   rH   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   r7   r5   rF   © r   r   r   r      s&   „ ñó
"ôH:óx@%óDH ôT+r   )Ú
__future__r   Úcodecsr3   r   Útypingr   r   r   r   Úframesr	   r
   r   Ú__all__Úgetincrementaldecoderr=   r   rM   r   r   ú<module>rT      sD   ðÝ "ã Û Û ß 1Ó 1ç "Ý ð ˆ-€à*ˆf×*Ñ*¨7Ó3€÷H+ò H+r   