
    5h?1                        S SK Jr  S SKrS SKrS SKrS SKJrJrJrJ	r	J
r
Jr  SSKJr  SSKJrJrJrJr  SSKJr  SS	KJr  S
/r\R.                  " S5      r " S S
5      rg)    )annotationsN)AnyCallableIterableIteratorLiteraloverload   )ConcurrencyError)	OP_BINARYOP_CONTOP_TEXTFrame)Data   )Deadline	Assemblerzutf-8c                  P   \ rS rSrSrSSS S 4         SS jjrSSS jjrSS jr\SS	 j5       r	\SS
 j5       r	\SSS jj5       r	\SSS jj5       r	\SSS jj5       r	SSS jjr	\S S j5       r
\S!S j5       r
\SS"S jj5       r
SS"S jjr
S#S jrS$S jrS$S jrS$S jrSrg)%r      a  
Assemble messages from frames.

:class:`Assembler` expects only data frames. The stream of frames must
respect the protocol; if it doesn't, the behavior is undefined.

Args:
    pause: Called when the buffer of frames goes above the high water mark;
        should pause reading from the network.
    resume: Called when the buffer of frames goes below the low water mark;
        should resume reading from the network.

Nc                     g N r       c/var/www/html/cementerio_25MayoBackend/env/lib/python3.13/site-packages/websockets/sync/messages.py<lambda>Assembler.<lambda>&   s    4r   c                     g r   r   r   r   r   r   r   '   s    Dr   c                D   [         R                  " 5       U l        [        R                  " 5       U l        Ub  Uc  US-  nUc  Ub  US-  nUb$  Ub!  US:  a  [        S5      eX:  a  [        S5      eXsU l        U l        X0l	        X@l
        SU l        SU l        SU l        g )N   r   z%low must be positive or equal to zeroz)high must be greater than or equal to lowF)	threadingLockmutexqueueSimpleQueueframes
ValueErrorhighlowpauseresumepausedget_in_progressclosed)selfr'   r(   r)   r*   s        r   __init__Assembler.__init__"   s     ^^%
 8=7H7H7J !)C<CO7DQw !HIIz !LMM"	48
  % r   c                   U R                   (       a   U R                  R                  SS9nO? Ub   US::  a  U R                  R                  SS9nOU R                  R                  SUS9n Uc  [        S5      eU$ ! [        R                   a    [        S5      S ef = f! [        R                   a    [        SUS S	35      S ef = f)
NFblockstream of frames endedr   T)r3   timeoutztimed out in z.1fs)r-   r%   getr#   EmptyEOFErrorTimeoutError)r.   r5   frames      r   get_next_frameAssembler.get_next_frameH   s     ;;Ce4M &7a< KKOO%O8E KKOO$OHE =344 ;; C78dBC ;; M"]73-q#ABLMs   A< "B  B  <!B &Cc                p   U R                      / n  UR                  U R                  R                  SS95        M*  ! [        R
                   a     Of = fU H  nU R                  R                  U5        M      U H  nU R                  R                  U5        M      S S S 5        g ! , (       d  f       g = f)NFr2   )r"   appendr%   r7   r#   r8   put)r.   r%   queuedr;   s       r   reset_queueAssembler.reset_queue^   s     ZZFMM$++///">? ;; &    &   ZZs'   B'+<AB'AAB''
B5c                    g r   r   r.   r5   decodes      r   r7   Assembler.gett   s    HKr   c                    g r   r   rE   s      r   r7   rG   w   s    KNr   c                   g r   r   rE   s      r   r7   rG   z   s    RUr   c                   g r   r   rE   s      r   r7   rG   }       UXr   c                    g r   r   rE   s      r   r7   rG      rK   r   c                   U R                      U R                  (       a  [        S5      eSU l        SSS5         [        U5      nU R	                  UR                  SS95      nU R                      U R                  5         SSS5        UR                  [        L d  UR                  [        L d   eUc  UR                  [        L nU/nUR                  (       d}   U R	                  UR                  SS95      nU R                      U R                  5         SSS5        UR                  [        L d   eUR                  U5        UR                  (       d  M}  SU l        SR                  S U 5       5      nU(       a  UR!                  5       $ U$ ! , (       d  f       GNd= f! , (       d  f       GN'= f! [         a    U R                  U5        e f = f! , (       d  f       N= f! SU l        f = f)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`.
    decode: :obj:`False` disables UTF-8 decoding of text frames and
        returns :class:`bytes`. :obj:`True` forces UTF-8 decoding of
        binary frames and returns :class:`str`.

Raises:
    EOFError: If the stream of frames has ended.
    UnicodeDecodeError: If a text frame contains invalid UTF-8.
    ConcurrencyError: If two coroutines run :meth:`get` or
        :meth:`get_iter` concurrently.
    TimeoutError: If a timeout is provided and elapses before a
        complete message is received.

&get() or get_iter() is already runningTNF)raise_if_elapsedr   c              3  6   #    U H  oR                   v   M     g 7fr   )data).0r;   s     r   	<genexpr> Assembler.get.<locals>.<genexpr>   s     7u

s   )r"   r,   r   r   r<   r5   maybe_resumeopcoder   r   finr:   rB   r   r?   joinrF   )r.   r5   rF   deadliner;   r%   rQ   s          r   r7   rG      s   4 ZZ##&'OPP#'D  	)(H ''(8(8%(8(PQE!!# <<7*elli.GGG~0WF ii // ((%(@E ZZ%%'  ||w...e$ iii  $)D xx777;;= KW Z  $  $$V,	
  Z $)D s_   $F5G# /F  AG# F2 8G# G?G# 
F 
F/*G# 2GG# 
G G# #	G,c                    g r   r   r.   rF   s     r   get_iterAssembler.get_iter   s    @Cr   c                    g r   r   r[   s     r   r\   r]      s    CFr   c                    g r   r   r[   s     r   r\   r]      s    FIr   c              #    #    U R                      U R                  (       a  [        S5      eSU l        SSS5        U R                  5       nU R                      U R	                  5         SSS5        UR
                  [        L d  UR
                  [        L d   eUc  UR
                  [        L nU(       a3  [        5       nUR                  UR                  UR                  5      v   OUR                  v   UR                  (       d  U R                  5       nU R                      U R	                  5         SSS5        UR
                  [        L d   eU(       a)  WR                  UR                  UR                  5      v   OUR                  v   UR                  (       d  M  SU l        g! , (       d  f       GN}= f! , (       d  f       GNZ= f! , (       d  f       N= f7f)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.

Args:
    decode: :obj:`False` disables UTF-8 decoding of text frames and
        returns :class:`bytes`. :obj:`True` forces UTF-8 decoding of
        binary frames and returns :class:`str`.

Raises:
    EOFError: If the stream of frames has ended.
    UnicodeDecodeError: If a text frame contains invalid UTF-8.
    ConcurrencyError: If two coroutines run :meth:`get` or
        :meth:`get_iter` concurrently.

rN   TNF)r"   r,   r   r<   rU   rV   r   r   UTF8DecoderrF   rQ   rW   r   )r.   rF   r;   decoders       r   r\   r]      sI    2 ZZ##&'OPP#'D   ##%ZZ ||w&%,,)*CCC>\\W,F!mG..UYY77** ))'')E!!# <<7***nnUZZ;;jj  )))  %G Z Z sS   G$F)$GF;(B:G"G3A,G!G)
F83G;
G
G
GGc                    U R                      U R                  (       a  [        S5      eU R                  R	                  U5        U R                  5         SSS5        g! , (       d  f       g= f)z_
Add ``frame`` to the next message.

Raises:
    EOFError: If the stream of frames has ended.

r4   N)r"   r-   r9   r%   r@   maybe_pause)r.   r;   s     r   r@   Assembler.put  sD     ZZ{{788KKOOE" ZZs   AA
A,c                   U R                   c  gU R                  R                  5       (       d   eU R                  R	                  5       U R                   :  a*  U R
                  (       d  SU l        U R                  5         ggg)z7Pause the writer if queue is above the high water mark.NT)r'   r"   lockedr%   qsizer+   r)   r.   s    r   rd   Assembler.maybe_pause*  sc     99zz  """" ;;*4;;DKJJL 4?*r   c                   U R                   c  gU R                  R                  5       (       d   eU R                  R	                  5       U R                   ::  a*  U R
                  (       a  SU l        U R                  5         ggg)z7Resume the writer if queue is below the low water mark.NF)r(   r"   rg   r%   rh   r+   r*   ri   s    r   rU   Assembler.maybe_resume7  sc     88zz  """" ;;$((*t{{DKKKM 0;*r   c                <   U R                      U R                  (       a
   SSS5        gSU l        U R                  (       a  U R                  R	                  S5        U R
                  (       a  SU l        U R                  5         SSS5        g! , (       d  f       g= f)z
End the stream of frames.

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

NTF)r"   r-   r,   r%   r@   r+   r*   ri   s    r   closeAssembler.closeD  s_     ZZ{{ Z DK##%{{# ZZs   BAB
B)	r-   r%   r,   r'   r(   r"   r)   r+   r*   )
r'   
int | Noner(   rp   r)   Callable[[], Any]r*   rq   returnNoner   )r5   float | Nonerr   r   )r%   zIterable[Frame]rr   rs   )r5   rt   rF   Literal[True]rr   str)r5   rt   rF   Literal[False]rr   bytes)NN)r5   rt   rF   bool | Nonerr   r   )rF   ru   rr   zIterator[str])rF   rw   rr   zIterator[bytes])rF   ry   rr   zIterator[Data])r;   r   rr   rs   )rr   rs   )__name__
__module____qualname____firstlineno____doc__r/   r<   rB   r	   r7   r\   r@   rd   rU   rn   __static_attributes__r   r   r   r   r      s       #/$0$$ $ !	$
 "$ 
$L,', K KN NU UX XX XEN C CF FI I<%|2r   )
__future__r   codecsr#   r    typingr   r   r   r   r   r	   
exceptionsr   r%   r   r   r   r   r   utilsr   __all__getincrementaldecoderra   r   r   r   r   <module>r      sK    "    G G ) 7 7   -**73F Fr   