
    9h+,                        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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\R0                  " S
5      r\" S5      r " S S\\   5      r " S S	5      rg)    )annotationsN)AsyncIteratorIterable)AnyCallableGenericLiteralTypeVaroverload   )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    `C:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\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.Nr3   )r   r-   set_exceptionr4   r!   s    r#   abortSimpleQueue.abort?   s?    ??&t/C/C/E/EOO))(3K*LM 0F&r&   )r   r   r    NreturnNone)rE   int)r/   r   rE   rF   )T)r8   boolrE   r   )r=   zIterable[T]rE   rF   )__name__
__module____qualname____firstlineno____doc__r$   r)   r0   r9   r>   rB   __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 j5       r\SS 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   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   rO   rO   r&   r#   <lambda>Assembler.<lambda>Y   s    4r&   c                     g r   rO   rO   r&   r#   rS   rT   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"   rZ   r[   r\   r]   s        r#   r$   Assembler.__init__U   s     +6- !)C<CO7DQw !HIIz !LMM"	48
  % r&   c                   #    g 7fr   rO   r"   decodes     r#   r9   Assembler.getw   s     7:   c                   #    g 7fr   rO   rc   s     r#   r9   re   z   s     :=rf   c                   #    g 7fr   rO   rc   s     r#   r9   re   }   s     =@rf   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  8   #    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   rX   r9   r`   maybe_resumeopcoder   r   finr   CancelledErrorr>   r   r,   joinrd   )r"   rd   rn   rX   rl   s        r#   r9   re      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                    g r   rO   rc   s     r#   get_iterAssembler.get_iter   s    EHr&   c                    g r   rO   rc   s     r#   rw   rx      s    HKr&   c                    g r   rO   rc   s     r#   rw   rx      s    KNr&   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.

rj   TNF)r_   r   rX   r9   r`   r   rt   rq   rr   r   r   UTF8Decoderrd   rl   rs   r   )r"   rd   rn   decoders       r#   rw   rx      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.

r3   N)r`   r4   rX   r0   maybe_pause)r"   rn   s     r#   r0   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)rZ   r(   rX   r^   r\   r!   s    r#   r   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)r[   r(   rX   r^   r]   r!   s    r#   rq   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.

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

NT)r`   rX   rB   r!   s    r#   closeAssembler.close,  s'     ;; 	r&   )r`   rX   r_   rZ   r[   r\   r^   r]   )
rZ   
int | Noner[   r   r\   Callable[[], Any]r]   r   rE   rF   )rd   Literal[True]rE   str)rd   Literal[False]rE   bytesr   )rd   bool | NonerE   r   )rd   r   rE   zAsyncIterator[str])rd   r   rE   zAsyncIterator[bytes])rd   r   rE   zAsyncIterator[Data])rn   r   rE   rF   rD   )rI   rJ   rK   rL   rM   r$   r   r9   rw   r0   r   rq   r   rN   rO   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   rX   r   r   r   r   r   __all__getincrementaldecoderr|   r   r   r   rO   r&   r#   <module>r      sg    "    3 E E ) 7 7  -**73CL-N'!* -N`u ur&   