
    h@)                       S SK Jr  S SKrS SKJrJr  S SKJrJr  S SK	J
r
  S SKJrJrJr  SSKJrJrJrJr  SS	KJrJr  SS
KJrJrJr  SSKJr  \" S5      r\" SSS9r\" SSS9r " S S\5      r \" SS9 " S S\\   5      5       r!\" SS9 " S S\\   5      5       r"\" SS9 " S S\\   \\   5      5       r#\" SS9 " S S\\   \\   5      5       r$g)    )annotationsN)OrderedDictdeque)	dataclassfield)TracebackType)Generic
NamedTupleTypeVar   )BrokenResourceErrorClosedResourceErrorEndOfStream
WouldBlock)TaskInfoget_current_task)EventObjectReceiveStreamObjectSendStream)
checkpointT_ItemT_coT)	covariantT_contra)contravariantc                  R    \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S'   S\S	'   S
rg)MemoryObjectStreamStatistics   intcurrent_buffer_usedfloatmax_buffer_sizeopen_send_streamsopen_receive_streamstasks_waiting_sendtasks_waiting_receive N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r'       F/var/www/html/env/lib/python3.13/site-packages/anyio/streams/memory.pyr   r      s&    r.   r   F)eqc                  N    \ rS rSr% \" S\S9rS\S'   \" SS9rS\S'   SS	 jr	S
r
g)MemoryObjectItemReceiver$   Finitdefault_factoryr   	task_info)r5   r   itemc                p    [        U SS 5      nU R                  R                   SU R                   SU< S3$ )Nr8   z(task_info=z, item=))getattr	__class__r(   r7   )selfr8   s     r/   __repr__!MemoryObjectItemReceiver.__repr__)   s<     tVT*..))*+dnn5EWTHTUVVr.   r'   N)returnstr)r(   r)   r*   r+   r   r   r7   r,   r8   r>   r-   r'   r.   r/   r2   r2   $   s)    U<LMIxMe$D&$Wr.   r2   c                      \ rS rSr% \" 5       rS\S'   \" S\S9rS\S'   \" SSS	9r	S
\S'   \" SSS	9r
S
\S'   \" S\S9rS\S'   \" S\S9rS\S'   SS jrSrg)MemoryObjectStreamState0   r!   r"   Fr4   zdeque[T_Item]bufferr   r5   defaultr   open_send_channelsopen_receive_channelsz4OrderedDict[Event, MemoryObjectItemReceiver[T_Item]]waiting_receiverszOrderedDict[Event, T_Item]waiting_sendersc           
         [        [        U R                  5      U R                  U R                  U R
                  [        U R                  5      [        U R                  5      5      $ N)r   lenrE   r"   rH   rI   rK   rJ   r=   s    r/   
statistics"MemoryObjectStreamState.statistics=   sR    +  ##&&$$%&&'
 	
r.   r'   Nr@   r   )r(   r)   r*   r+   r   r"   r,   r   rE   rH   rI   r   rJ   rK   rP   r-   r'   r.   r/   rC   rC   0   sz    "WOU$!ueDFMD#::!&E1!=3=NSKOK  38K3O/ 
r.   rC   c                      \ rS rSr% S\S'   \" SSS9rS\S'   SS jrSS	 jrSS
 jr	SS jr
SS jrSS jrSS jrSS jr        SS jrSS jrSrg)MemoryObjectReceiveStreamH   zMemoryObjectStreamState[T_co]_stateFrF   bool_closedc                B    U R                   =R                  S-  sl        g N   )rV   rI   rO   s    r/   __post_init__'MemoryObjectReceiveStream.__post_init__M   s    ))Q.)r.   c                   U R                   (       a  [        eU R                  R                  (       aZ  U R                  R                  R	                  SS9u  pU R                  R
                  R                  U5        UR                  5         U R                  R
                  (       a$  U R                  R
                  R                  5       $ U R                  R                  (       d  [        e[        e)ak  
Receive the next item if it can be done without waiting.

:return: the received item
:raises ~anyio.ClosedResourceError: if this send stream has been closed
:raises ~anyio.EndOfStream: if the buffer is empty and this stream has been
    closed from the sending end
:raises ~anyio.WouldBlock: if there are no items in the buffer and no tasks
    waiting to send

Flast)rX   r   rV   rK   popitemrE   appendsetpopleftrH   r   r   )r=   
send_eventr8   s      r/   receive_nowait(MemoryObjectReceiveStream.receive_nowaitP   s     <<%%;;&&#{{::BBBNJKK%%d+NN;;;;%%--////r.   c                  #    [        5       I S h  vN    U R                  5       $  N! [         a    [        5       n[        [
           " 5       nX R                  R                  U'    UR                  5       I S h  vN    U R                  R                  R                  US 5        O+! U R                  R                  R                  US 5        f = f UR                  s $ ! [         a    [        S ef = ff = f7frM   )r   rf   r   r   r2   r   rV   rJ   waitpopr8   AttributeErrorr   )r=   receive_eventreceivers      r/   receive!MemoryObjectReceiveStream.receivel   s     l	,&&(( 	  	,!GM/57H;CKK))-8G#((***--11-F--11-F,}}$! ,!t+,	,sd   C:&C:( C:>C7'B':A=;B' 'C7'(CC7C!C7C:!C33C77C:c                V    U R                   (       a  [        e[        U R                  S9$ )z
Create a clone of this receive stream.

Each clone can be closed separately. Only when all clones have been closed will
the receiving end of the memory stream be considered closed by the sending ends.

:return: the cloned stream

rV   )rX   r   rT   rV   rO   s    r/   cloneMemoryObjectReceiveStream.clone   s      <<%%(<<r.   c                6   U R                   (       d  SU l         U R                  =R                  S-  sl        U R                  R                  S:X  aG  [        U R                  R                  R                  5       5      nU H  nUR                  5         M     gggz
Close the stream.

This works the exact same way as :meth:`aclose`, but is provided as a special
case for the benefit of synchronous callbacks.

Tr[   r   N)rX   rV   rI   listrK   keysrc   )r=   send_eventsevents      r/   closeMemoryObjectReceiveStream.close   ss     ||DLKK--2-{{00A5"4;;#>#>#C#C#EF(EIIK ) 6 r.   c                ,   #    U R                  5         g 7frM   rz   rO   s    r/   aclose MemoryObjectReceiveStream.aclose        

   c                6    U R                   R                  5       $ zR
Return statistics about the current state of this stream.

.. versionadded:: 3.0
rV   rP   rO   s    r/   rP   $MemoryObjectReceiveStream.statistics        {{%%''r.   c                    U $ rM   r'   rO   s    r/   	__enter__#MemoryObjectReceiveStream.__enter__       r.   c                $    U R                  5         g rM   r}   r=   exc_typeexc_valexc_tbs       r/   __exit__"MemoryObjectReceiveStream.__exit__        	

r.   c                    U R                   (       d@  [        R                  " SU R                  R                   S[        U 5      S S3[        U S9  g g Nz
Unclosed <z at x>)sourcerX   warningswarnr<   r(   idResourceWarningrO   s    r/   __del__!MemoryObjectReceiveStream.__del__   C    ||MMT^^445T"T(1QG r.   rX   Nr@   None)r@   r   )r@   zMemoryObjectReceiveStream[T_co]rR   r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner@   r   )r(   r)   r*   r+   r,   r   rX   r\   rf   rn   rr   rz   r~   rP   r   r   r   r-   r'   r.   r/   rT   rT   H   sq    ))ue4GT4/8,(=  (, & %	
 
r.   rT   c                      \ rS rSr% S\S'   \" SSS9rS\S'   SS jrSS	 jrSS
 jr	SS jr
SS jrSS jrSS jrSS jr        SS jrSS jrSrg)MemoryObjectSendStream   z!MemoryObjectStreamState[T_contra]rV   FrF   rW   rX   c                B    U R                   =R                  S-  sl        g rZ   )rV   rH   rO   s    r/   r\   $MemoryObjectSendStream.__post_init__   s    &&!+&r.   c                ^   U R                   (       a  [        eU R                  R                  (       d  [        eU R                  R
                  (       ax  U R                  R
                  R                  SS9u  p#UR                  R                  5       (       d  Xl	        UR                  5         gU R                  R
                  (       a  Mx  [        U R                  R                  5      U R                  R                  :  a&  U R                  R                  R                  U5        g[        e)aa  
Send an item immediately if it can be done without waiting.

:param item: the item to send
:raises ~anyio.ClosedResourceError: if this send stream has been closed
:raises ~anyio.BrokenResourceError: if the stream has been closed from the
    receiving end
:raises ~anyio.WouldBlock: if the buffer is full and there are no tasks waiting
    to receive

Fr_   N)rX   r   rV   rI   r   rJ   ra   r7   has_pending_cancellationr8   rc   rN   rE   r"   rb   r   )r=   r8   rl   rm   s       r/   send_nowait"MemoryObjectSendStream.send_nowait   s     <<%%{{00%%kk++&*kk&C&C&K&KQV&K&W#M%%>>@@ $!!# kk+++ t{{!!"T[[%@%@@KK%%d+r.   c                  #    [        5       I Sh  vN    U R                  U5        g N! [         a    [        5       nXR                  R
                  U'    UR                  5       I Sh  vN    O5! [         a(    U R                  R
                  R                  US5        e f = fX R                  R
                  ;   a  U R                  R
                  U	 [        Se gf = f7f)ae  
Send an item to the stream.

If the buffer is full, this method blocks until there is again room in the
buffer or the item can be sent directly to a receiver.

:param item: the item to send
:raises ~anyio.ClosedResourceError: if this send stream has been closed
:raises ~anyio.BrokenResourceError: if the stream has been closed from the
    receiving end

N)
r   r   r   r   rV   rK   ri   BaseExceptionrj   r   )r=   r8   re   s      r/   sendMemoryObjectSendStream.send   s      l	4T" 	  	4J6:KK''
3 oo'''  ++//
DA [[888KK//
;)t3 9	4sR   C#(C#* C#,C A1*A-+A10C 12B##:C C#C  C#c                V    U R                   (       a  [        e[        U R                  S9$ )z
Create a clone of this send stream.

Each clone can be closed separately. Only when all clones have been closed will
the sending end of the memory stream be considered closed by the receiving ends.

:return: the cloned stream

rq   )rX   r   r   rV   rO   s    r/   rr   MemoryObjectSendStream.clone  s      <<%%%T[[99r.   c                ~   U R                   (       d  SU l         U R                  =R                  S-  sl        U R                  R                  S:X  ak  [        U R                  R                  R                  5       5      nU R                  R                  R                  5         U H  nUR                  5         M     gggru   )rX   rV   rH   rv   rJ   rw   clearrc   )r=   receive_eventsry   s      r/   rz   MemoryObjectSendStream.close  s     ||DLKK**a/*{{--2!%dkk&C&C&H&H&J!K--335+EIIK , 3 r.   c                ,   #    U R                  5         g 7frM   r}   rO   s    r/   r~   MemoryObjectSendStream.aclose!  r   r   c                6    U R                   R                  5       $ r   r   rO   s    r/   rP   !MemoryObjectSendStream.statistics$  r   r.   c                    U $ rM   r'   rO   s    r/   r    MemoryObjectSendStream.__enter__,  r   r.   c                $    U R                  5         g rM   r}   r   s       r/   r   MemoryObjectSendStream.__exit__/  r   r.   c                    U R                   (       d@  [        R                  " SU R                  R                   S[        U 5      S S3[        U S9  g g r   r   rO   s    r/   r   MemoryObjectSendStream.__del__7  r   r.   r   Nr   )r8   r   r@   r   )r@   z MemoryObjectSendStream[T_contra]rR   r   )r(   r)   r*   r+   r,   r   rX   r\   r   r   rr   rz   r~   rP   r   r   r   r-   r'   r.   r/   r   r      sq    --ue4GT4,:4<: "(, & %	
 
r.   r   )%
__future__r   r   collectionsr   r   dataclassesr   r   typesr   typingr	   r
   r    r   r   r   r   _core._testingr   r   abcr   r   r   lowlevelr   r   r   r   r   r2   rC   rT   r   r'   r.   r/   <module>r      s   "  * (  / /  8 > > !		v&:T2	: 	 eWwv W W e
gfo 
 
. er/B4/H r rj e~WX.0@0J ~ ~r.   