
    ,h*                        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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j0                  d
      Z ed      Z G d dee         Z G d d	      Zy)    )annotationsN)AsyncIteratorIterable)AnyCallableGenericLiteralTypeVaroverload   )ConcurrencyError)	OP_BINARYOP_CONTOP_TEXTFrame)Data	Assemblerzutf-8Tc                  B    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	y)SimpleQueuez
    Simplified version of :class:`asyncio.Queue`.

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

    c                v    t        j                         | _        d | _        t	        j
                         | _        y N)asyncioget_running_looploop
get_waitercollectionsdequequeueselfs    ]/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/websockets/asyncio/messages.py__init__zSimpleQueue.__init__   s)    ,,.	7;+6+<+<+>
    c                ,    t        | j                        S r   )lenr   r    s    r"   __len__zSimpleQueue.__len__"   s    4::r$   c                    | j                   j                  |       | j                  7| j                  j                         s| j                  j	                  d       yyy)z+Put an item into the queue without waiting.N)r   appendr   done
set_result)r!   items     r"   putzSimpleQueue.put%   sH    

$??&t/C/C/EOO&&t, 0F&r$   c                  K   | j                   su|st        d      | j                  J d       | j                  j	                         | _        	 | j                   d{    | j                  j                          d| _        | j                   j                         S 7 ?# | j                  j                          d| _        w xY ww)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"   getz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                    | j                   J d       | j                  rJ d       | j                  j                  |       y)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"   resetzSimpleQueue.reset9   s7    &O(OO::GGG

% r$   c                    | j                   @| j                   j                         s%| j                   j                  t        d             yyy)z8Close the queue, raising EOFError in get() if necessary.Nr/   )r   r*   set_exceptionr0   r    s    r"   abortzSimpleQueue.abort?   s<    ??&t/C/C/EOO))(3K*LM 0F&r$   NreturnNone)r>   int)r,   r   r>   r?   )T)r4   boolr>   r   )r8   zIterable[T]r>   r?   )
__name__
__module____qualname____doc__r#   r'   r-   r5   r9   r<    r$   r"   r   r      s&    ?
-$!Nr$   r   c                      e Zd ZdZddd d f	 	 	 	 	 	 	 	 	 ddZedd       Zedd       Zeddd       Zddd	Zedd
       Zedd       Zeddd       ZdddZddZddZ	ddZ
ddZy)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                      y r   rF   rF   r$   r"   <lambda>zAssembler.<lambda>Y       r$   c                      y r   rF   rF   r$   r"   rI   zAssembler.<lambda>Z   rJ   r$   c                    t               | _        |||dz  }|||dz  }|"| |dk  rt        d      ||k  rt        d      ||c| _        | _        || _        || _        d| _        d| _        d| _	        y )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!   rP   rQ   rR   rS   s        r"   r#   zAssembler.__init__U   s     +6- !)C<CO7DQw !HIIcz !LMM"C	48
  % r$   c                   K   y wr   rF   r!   decodes     r"   r5   zAssembler.getw   s	     7:   c                   K   y wr   rF   rX   s     r"   r5   zAssembler.getz   s	     :=rZ   c                   K   y wr   rF   rX   s     r"   r5   zAssembler.get}   s	     =@rZ   c                &  K   | j                   rt        d      d| _         	 | j                  j                  | j                          d{   }| j                          |j                  t        u s|j                  t        u sJ ||j                  t        u }|g}|j                  sq	 | j                  j                  | j                          d{   }| j                          |j                  t        u sJ |j                  |       |j                  sqd| _         dj                  d |D              }|r|j!                         S |S 7 7 |# t        j                  $ r | j                  j                  |        w xY w# d| _         w xY ww)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  4   K   | ]  }|j                     y wr   )data).0frames     r"   	<genexpr>z Assembler.get.<locals>.<genexpr>   s     7u

7s   )rU   r   rN   r5   rV   maybe_resumeopcoder   r   finr   CancelledErrorr9   r   r)   joinrY   )r!   rY   rb   rN   r`   s        r"   r5   zAssembler.get   sT    , "#KLL#
	)++//dkk/::E<<7*elli.GG~0WF ii"&++//dkk/"BBE !!#||w..e$ ii $)D xx777;;= K7 ; C--  KK%%f-	 $)D sZ   F)F EAF *)E EE AF 3FF E 0FF 	FFc                     y r   rF   rX   s     r"   get_iterzAssembler.get_iter   s    EHr$   c                     y r   rF   rX   s     r"   rj   zAssembler.get_iter   s    HKr$   c                     y r   rF   rX   s     r"   rj   zAssembler.get_iter   s    KNr$   c               f  K   | j                   rt        d      d| _         	 | j                  j                  | j                          d{   }| j                          |j                  t        u s|j                  t        u sJ ||j                  t        u }|r4t               }|j                  |j                  |j                         n|j                   |j                  s| j                  j                  | j                          d{   }| j                          |j                  t        u sJ |r*j                  |j                  |j                         n|j                   |j                  sd| _         y7 B# t
        j                  $ r	 d| _          w xY w7 w)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.

        r^   TNF)rU   r   rN   r5   rV   r   rg   rd   re   r   r   UTF8DecoderrY   r`   rf   r   )r!   rY   rb   decoders       r"   rj   zAssembler.get_iter   sQ    2 "#KLL#	++//dkk/::E 	||w&%,,)*CC>\\W,F!mG..UYY77** ))
 ++//dkk/::E<<7**nnUZZ;;jj  ))  %9 ;%% 	#(D 	& ;sB   F1)F FF CF1F/A/F1F1F F,,F1c                    | j                   rt        d      | j                  j                  |       | j	                          y)z
        Add ``frame`` to the next message.

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

        r/   N)rV   r0   rN   r-   maybe_pause)r!   rb   s     r"   r-   zAssembler.put  s3     ;;344r$   c                    | j                   yt        | j                        | j                   kD  r%| j                  sd| _        | j	                          yyy)z7Pause the writer if queue is above the high water mark.NT)rP   r&   rN   rT   rR   r    s    r"   rq   zAssembler.maybe_pause  sF     99 t{{dii'DKJJL 1<'r$   c                    | j                   yt        | j                        | j                   k  r%| j                  rd| _        | j	                          yyy)z7Resume the writer if queue is below the low water mark.NF)rQ   r&   rN   rT   rS   r    s    r"   rd   zAssembler.maybe_resume!  sF     88 t{{txx'DKKDKKKM -8'r$   c                `    | j                   ryd| _         | j                  j                          y)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`.

        NT)rV   rN   r<   r    s    r"   closezAssembler.close,  s'     ;; 	r$   )
rP   
int | NonerQ   rv   rR   Callable[[], Any]rS   rw   r>   r?   )rY   Literal[True]r>   str)rY   Literal[False]r>   bytesr   )rY   bool | Noner>   r   )rY   rx   r>   zAsyncIterator[str])rY   rz   r>   zAsyncIterator[bytes])rY   r|   r>   zAsyncIterator[Data])rb   r   r>   r?   r=   )rB   rC   rD   rE   r#   r   r5   rj   r-   rq   rd   ru   rF   r$   r"   r   r   E   s    "  #/$0     !	 
 "  
 D : := =@ @:x H HK KN NA%F		r$   )
__future__r   r   codecsr   collections.abcr   r   typingr   r   r   r	   r
   r   
exceptionsr   rN   r   r   r   r   r   __all__getincrementaldecoderrn   r   r   r   rF   r$   r"   <module>r      si    "    3 E E ) 7 7  -*f**73CL-N'!* -N`u ur$   