
    vg(                        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	m
Z
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 ed          Z G d dee                   Z G d d	          ZdS )    )annotationsN)AsyncIteratorIterable)AnyCallableGenericTypeVar   )ConcurrencyError)	OP_BINARYOP_CONTOP_TEXTFrame)Data	Assemblerzutf-8Tc                  D    e Zd ZdZddZddZdd	ZdddZddZddZ	dS )SimpleQueuez
    Simplified version of :class:`asyncio.Queue`.

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

    returnNonec                t    t          j                    | _        d | _        t	          j                    | _        d S N)asyncioget_running_looploop
get_waitercollectionsdequequeueselfs    X/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/websockets/asyncio/messages.py__init__zSimpleQueue.__init__   s-    ,..	7;+6+<+>+>


    intc                *    t          | j                  S r   )lenr   r    s    r"   __len__zSimpleQueue.__len__"   s    4:r$   itemr   c                    | j                             |           | j        5| j                                        s| j                            d           dS dS dS )z+Put an item into the queue without waiting.N)r   appendr   done
set_result)r!   r)   s     r"   putzSimpleQueue.put%   s]    
$?&t/C/C/E/E&O&&t,,,,, '&&&r$   Tblockboolc                n  K   | j         s|st          d          | j        
J d            | j                                        | _        	 | j         d{V  | j                                         d| _        n%# | j                                         d| _        w xY w| j                                         S )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!   r/   s     r"   getzSimpleQueue.get+   s      z 		' 97888?**,L***"i5577DO'o%%%%%%%&&((("& &&((("&&&&&z!!###s   A9 9"BitemsIterable[T]c                ~    | j         
J d            | j        r
J d            | j                            |           dS )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!   r8   s     r"   resetzSimpleQueue.reset9   sL    &&(O&&&:GGGGGG
%     r$   c                    | j         B| j                                         s+| j                             t          d                     dS dS dS )z8Close the queue, raising EOFError in get() if necessary.Nr2   )r   r,   set_exceptionr3   r    s    r"   abortzSimpleQueue.abort?   sP    ?&t/C/C/E/E&O))(3K*L*LMMMMM '&&&r$   Nr   r   )r   r%   )r)   r   r   r   )T)r/   r0   r   r   )r8   r9   r   r   )
__name__
__module____qualname____doc__r#   r(   r.   r7   r<   r?    r$   r"   r   r      s         ? ? ? ?
   - - - -$ $ $ $ $! ! ! !N N N N N Nr$   r   c                  \    e Zd ZdZddd d fddZdddZdddZddZddZddZ	ddZ
dS ) 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                     d S r   rE   rE   r$   r"   <lambda>zAssembler.<lambda>Y   s    4 r$   c                     d S r   rE   rE   r$   r"   rH   zAssembler.<lambda>Z   s    D r$   high
int | NonelowpauseCallable[[], Any]resumer   r   c                   t                      | _        |||dz  }|||dz  }|,|*|dk     rt          d          ||k     rt          d          ||c| _        | _        || _        || _        d| _        d| _        d| _	        d S )N   r   z%low must be positive or equal to zeroz)high must be greater than or equal to lowF)
r   frames
ValueErrorrJ   rL   rM   rO   pausedget_in_progressclosed)r!   rJ   rL   rM   rO   s        r"   r#   zAssembler.__init__U   s     +6-- !)C<CO7DQww !HIIIczz !LMMM"C	48
  % r$   decodebool | Noner   c                  K   | j         rt          d          d| _         	 | j                            | j                    d{V }|                                  |j        t          u s|j        t          u sJ ||j        t          u }|g}|j	        s	 | j                            | j                    d{V }n.# t          j        $ r | j                            |            w xY w|                                  |j        t          u sJ |                    |           |j	        d| _         n# d| _         w xY wd                    d |D                       }|r|                                S |S )a0  
        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  $   K   | ]}|j         V  d S r   )data).0frames     r"   	<genexpr>z Assembler.get.<locals>.<genexpr>   s$      77u
777777r$   )rU   r   rR   r7   rV   maybe_resumeopcoder   r   finr   CancelledErrorr<   r   r+   joinrW   )r!   rW   r^   rR   r\   s        r"   r7   zAssembler.getw   s     ,  	M"#KLLL#
	)+//dk/::::::::E<7**eli.G.G.G.G~0WF i 
%"&+//dk/"B"BBBBBBBEE-    K%%f---	
 !!###|w....e$$$ i 
% $)D  5D ((((xx7777777 	;;== Ks%   A2D1 &B; :D1 ;+C&&AD1 1	D:AsyncIterator[Data]c                 K   | j         rt          d          d| _         	 | j                            | j                    d{V }n# t
          j        $ r	 d| _          w xY w|                                  |j        t          u s|j        t          u sJ ||j        t          u }|r2t                      }|                    |j        |j                  W V  n
|j        W V  |j        s| j                            | j                    d{V }|                                  |j        t          u sJ |r$|                    |j        |j                  W V  n
|j        W V  |j        d| _         dS )a  
        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.

        rZ   TNF)rU   r   rR   r7   rV   r   rc   r`   ra   r   r   UTF8DecoderrW   r\   rb   r   )r!   rW   r^   decoders       r"   get_iterzAssembler.get_iter   s     2  	M"#KLLL#	+//dk/::::::::EE% 	 	 	#(D 	 	|w&&%,)*C*C*C*C>\W,F 	!mmG..UY7777777* ) 	!
 +//dk/::::::::E<7**** !nnUZ;;;;;;;j     ) 	!  %s   &A A r^   r   c                    | j         rt          d          | j                            |           |                                  dS )z
        Add ``frame`` to the next message.

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

        r2   N)rV   r3   rR   r.   maybe_pause)r!   r^   s     r"   r.   zAssembler.put   sI     ; 	53444r$   c                    | j         dS t          | j                  | j         k    r$| j        sd| _        |                                  dS dS dS )z7Pause the writer if queue is above the high water mark.NT)rJ   r'   rR   rT   rM   r    s    r"   rk   zAssembler.maybe_pause  sW     9F t{di'''DKJJLLLLL ('''r$   c                    | j         dS t          | j                  | j         k    r$| j        rd| _        |                                  dS dS dS )z7Resume the writer if queue is below the low water mark.NF)rL   r'   rR   rT   rO   r    s    r"   r`   zAssembler.maybe_resume  sW     8F t{tx''DK'DKKKMMMMM ('''r$   c                X    | j         rdS d| _         | j                                         dS )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)rV   rR   r?   r    s    r"   closezAssembler.close  s6     ; 	F 	r$   )
rJ   rK   rL   rK   rM   rN   rO   rN   r   r   r   )rW   rX   r   r   )rW   rX   r   re   )r^   r   r   r   r@   )rA   rB   rC   rD   r#   r7   ri   r.   rk   r`   ro   rE   r$   r"   r   r   E   s         "  #/<$0L         D: : : : :xA% A% A% A% A%F   	 	 	 		 	 	 	     r$   )
__future__r   r   codecsr   collections.abcr   r   typingr   r   r   r	   
exceptionsr   rR   r   r   r   r   r   __all__getincrementaldecoderrg   r   r   r   rE   r$   r"   <module>rw      sT   " " " " " "       3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 ) ) ) ) ) ) 7 7 7 7 7 7 7 7 7 7 7 7       -*f*733GCLL-N -N -N -N -N'!* -N -N -N`c c c c c c c c c cr$   