
    vKg+                        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	  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   )ConcurrencyError)	OP_BINARYOP_CONTOP_TEXTFrame)Data   )Deadline	Assemblerzutf-8c                      \ 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S	 jj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       X/var/www/highfloat_scraper/venv/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                J   U R                   (       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 endedT)r1   timeoutztimed out in z.1fs)r+   r#   getr!   EmptyEOFErrorTimeoutError)r,   r3   frames      r   get_next_frameAssembler.get_next_frameH   s     ;;Ce4MdGD =344 ;; C78dBC
 ;; M"]73-q#ABLMs   A A< !A9<&B"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)NFr0   )r    appendr#   r5   r!   r6   put)r,   r#   queuedr9   s       r   reset_queueAssembler.reset_queueY   s     ZZFMM$++///">? ;; &    &   ZZs'   B'+<AB'AAB''
B5c                   U R                      U R                  (       a  [        S5      eSU l        SSS5         [        U5      nU R	                  UR                  5       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                  5       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Nf= 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 runningTNFr   c              3  6   #    U H  oR                   v   M     g 7fr   )data).0r9   s     r   	<genexpr> Assembler.get.<locals>.<genexpr>   s     7u

s   )r    r*   r	   r   r:   r3   maybe_resumeopcoder   r
   finr8   r@   r   r=   joindecode)r,   r3   rM   deadliner9   r#   rE   s          r   r5   Assembler.getl   s   4 ZZ##&'OPP#'D  	)(H ''(8(8(:;E!!# <<7*elli.GGG~0WF ii //0@0@0BCE ZZ%%'  ||w...e$ iii $)D xx777;;= KS Z  $  $$V,	
  Z $)D s_   $F6G% 0F"AG% F4 :G% G?G% 
F"
F1,G% 4GG% 
G"G% %	G.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.

rC   TNF)r    r*   r	   r:   rI   rJ   r   r
   UTF8DecoderrM   rE   rK   r   )r,   rM   r9   decoders       r   get_iterAssembler.get_iter   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.

r2   N)r    r+   r7   r#   r>   maybe_pause)r,   r9   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   rV   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    rY   r#   rZ   r)   r(   r[   s    r   rI   Assembler.maybe_resume  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        SSS5        g! , (       d  f       g= f)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[   s    r   closeAssembler.close"  sH     ZZ{{ Z DK##% ZZs   A%3A%%
A3)	r+   r#   r*   r%   r&   r    r'   r)   r(   )
r%   
int | Noner&   rb   r'   Callable[[], Any]r(   rc   returnNoner   )r3   float | Nonerd   r   )r#   zIterable[Frame]rd   re   )NN)r3   rf   rM   bool | Nonerd   r   )rM   rg   rd   zIterator[Data])r9   r   rd   re   )rd   re   )__name__
__module____qualname____firstlineno____doc__r-   r:   r@   r5   rS   r>   rV   rI   r`   __static_attributes__r   r   r   r   r      sv       #/$0$$ $ !	$
 "$ 
$L"'&CJ<%|2&r   )
__future__r   codecsr!   r   typingr   r   r   r   
exceptionsr	   r#   r
   r   r   r   r   utilsr   __all__getincrementaldecoderrQ   r   r   r   r   <module>ru      sK    "    4 4 ) 7 7   -**73_& _&r   