
    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  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	/r\R,                  " S
5      r\" S5      r " S S\\   5      r " S S	5      rg)    )annotationsN)AsyncIteratorIterable)AnyCallableGenericTypeVar   )ConcurrencyError)	OP_BINARYOP_CONTOP_TEXTFrame)Data	Assemblerzutf-8Tc                  X    \ rS rSrSrSS jrSS jrSS jrSSS jjrSS jr	SS jr
S	rg
)SimpleQueue   zy
Simplified version of :class:`asyncio.Queue`.

Provides only the subset of functionality needed by :class:`Assembler`.

c                z    [         R                  " 5       U l        S U l        [        R
                  " 5       U l        g N)asyncioget_running_looploop
get_waitercollectionsdequequeueselfs    [/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/websockets/asyncio/messages.py__init__SimpleQueue.__init__   s)    ,,.	7;+6+<+<+>
    c                ,    [        U R                  5      $ r   )lenr   r   s    r!   __len__SimpleQueue.__len__"   s    4::r$   c                    U R                   R                  U5        U R                  b<  U R                  R                  5       (       d  U R                  R	                  S5        ggg)z+Put an item into the queue without waiting.N)r   appendr   done
set_result)r    items     r!   putSimpleQueue.put%   sK    

$??&t/C/C/E/EOO&&t, 0F&r$   c                  #    U R                   (       d{  U(       d  [        S5      eU R                  b   S5       eU R                  R	                  5       U l         U R                  I Sh  vN   U R                  R                  5         SU l        U R                   R                  5       $  N?! U R                  R                  5         SU l        f = f7f)z?Remove and return an item from the queue, waiting if necessary.stream of frames endedNzcannot call get() concurrently)r   EOFErrorr   r   create_futurecancelpopleft)r    blocks     r!   getSimpleQueue.get+   s     zz788??*L,LL*"ii557DO'oo%%&&("&zz!!##	 &&&("&s0   ACB+ )B)*B+ .;C)B+ +#CCc                    U R                   b   S5       eU R                  (       a   S5       eU R                  R                  U5        g)z)Put back items into an empty, idle queue.Nz%cannot reset() while get() is runningz&cannot reset() while queue isn't empty)r   r   extend)r    itemss     r!   resetSimpleQueue.reset9   s<    &O(OO&::GGG~

% r$   c                    U R                   bE  U R                   R                  5       (       d%  U R                   R                  [        S5      5        ggg)z8Close the queue, raising EOFError in get() if necessary.Nr1   )r   r+   set_exceptionr2   r   s    r!   abortSimpleQueue.abort?   s?    ??&t/C/C/E/EOO))(3K*LM 0F&r$   )r   r   r   NreturnNone)rC   int)r-   r   rC   rD   )T)r6   boolrC   r   )r;   zIterable[T]rC   rD   )__name__
__module____qualname____firstlineno____doc__r"   r'   r.   r7   r<   r@   __static_attributes__ r$   r!   r   r      s&    ?
-$!Nr$   r   c                      \ 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S jjrSS	 jrSS
 jr	SS jr
SS jrSrg)r   E   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 r   rM   rM   r$   r!   <lambda>Assembler.<lambda>Y   s    4r$   c                     g r   rM   rM   r$   r!   rQ   rR   Z   s    Dr$   c                    [        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)
r   frames
ValueErrorhighlowpauseresumepausedget_in_progressclosed)r    rX   rY   rZ   r[   s        r!   r"   Assembler.__init__U   s     +6- !)C<CO7DQw !HIIz !LMM"	48
  % r$   c                j  #    U R                   (       a  [        S5      eSU l          U R                  R                  U R                  (       + 5      I Sh  vN nU R                  5         UR                  [        L d  UR                  [        L d   eUc  UR                  [        L nU/nUR                  (       d|   U R                  R                  U R                  (       + 5      I Sh  vN nU R                  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$  GN N! [        R                   a    U R                  R                  U5        e f = f! SU l         f = f7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:
    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.

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

s   )r]   r   rV   r7   r^   maybe_resumeopcoder   r   finr   CancelledErrorr<   r   r*   joindecode)r    rm   re   rV   rc   s        r!   r7   Assembler.getw   sZ    , "#KLL#
	)++//dkk/::E<<7*elli.GGG~0WF ii"&++//dkk/"BBE !!#||w...e$ iii $)D xx777;;= K7 ; C--  KK%%f-	 $)D sZ   $F3-F' E.A%F' ;-E3 (E1)E3 -AF' 68F3.F' 1E3 31F$$F' '	F00F3c                 #    U R                   (       a  [        S5      eSU l          U R                  R                  U R                  (       + 5      I Sh  vN nU R                  5         UR                  [        L d  UR                  [        L d   eUc  UR                  [        L nU(       a4  [        5       nUR                  UR                  UR                  5      7v   OUR                  7v   UR                  (       d  U R                  R                  U R                  (       + 5      I Sh  vN nU R                  5         UR                  [        L d   eU(       a*  WR                  UR                  UR                  5      7v   OUR                  7v   UR                  (       d  M  SU l         g GN_! [
        R                   a	    SU l         e f = f N7f)a0  
Stream the next message.

Iterating the return value of :meth:`get_iter` asynchronously 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.

ra   TNF)r]   r   rV   r7   r^   r   rk   rh   ri   r   r   UTF8Decoderrm   rc   rj   r   )r    rm   re   decoders       r!   get_iterAssembler.get_iter   sX    2 "#KLL#	++//dkk/::E 	||w&%,,)*CCC>\\W,F!mG..UYY77** ))
 ++//dkk/::E<<7***nnUZZ;;jj  )))  %9 ;%% 	#(D 	& ;sB   $G-F6 F3F6 CG.G/A:G+G3F6 6GGc                    U R                   (       a  [        S5      eU R                  R                  U5        U R	                  5         g)z_
Add ``frame`` to the next message.

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

r1   N)r^   r2   rV   r.   maybe_pause)r    re   s     r!   r.   Assembler.put   s3     ;;344r$   c                    U R                   c  g[        U 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)rX   r&   rV   r\   rZ   r   s    r!   ru   Assembler.maybe_pause  sF     99 t{{dii'DKJJL 1<'r$   c                    U R                   c  g[        U 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)rY   r&   rV   r\   r[   r   s    r!   rh   Assembler.maybe_resume  sF     88 t{{txx'DKKDKKKM -8'r$   c                j    U R                   (       a  gSU l         U R                  R                  5         g)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^   rV   r@   r   s    r!   closeAssembler.close  s'     ;; 	r$   )r^   rV   r]   rX   rY   rZ   r\   r[   )
rX   
int | NonerY   r~   rZ   Callable[[], Any]r[   r   rC   rD   r   )rm   bool | NonerC   r   )rm   r   rC   zAsyncIterator[Data])re   r   rC   rD   rB   )rG   rH   rI   rJ   rK   r"   r7   rr   r.   ru   rh   r|   rL   rM   r$   r!   r   r   E   sl    "  #/$0     !	 
 "  
 D:xA%F		r$   )
__future__r   r   codecsr   collections.abcr   r   typingr   r   r   r	   
exceptionsr   rV   r   r   r   r   r   __all__getincrementaldecoderrp   r   r   r   rM   r$   r!   <module>r      sg    "    3 2 2 ) 7 7  -**73CL-N'!* -N`c cr$   