
    1h:$                    t   S SK J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Jr  SSK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"g)    )annotations)OrderedDictdeque)	dataclassfield)TracebackType)Generic
NamedTupleTypeVar   )BrokenResourceErrorClosedResourceErrorEndOfStream
WouldBlockget_cancelled_exc_class)DeprecatedAwaitable)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'       L/var/www/auris/envauris/lib/python3.13/site-packages/anyio/streams/memory.pyr   r      s&    r.   r   F)eqc                      \ 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)MemoryObjectStreamState#   r!   r"   F)initdefault_factoryzdeque[T_Item]bufferr   r4   defaultr   open_send_channelsopen_receive_channelsz OrderedDict[Event, list[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   lenr6   r"   r9   r:   r<   r;   selfs    r/   
statistics"MemoryObjectStreamState.statistics0   sR    +  ##&&$$%&&'
 	
r.   r'   Nreturnr   )r(   r)   r*   r+   r   r"   r,   r   r6   r9   r:   r   r;   r<   rB   r-   r'   r.   r/   r2   r2   #   sy    "WOU$!ueDFMD#::!&E1!=3=:?K;7  38K3O/ 
r.   r2   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rg)MemoryObjectReceiveStream;   zMemoryObjectStreamState[T_co]_stateFr7   bool_closedc                B    U R                   =R                  S-  sl        g N   )rI   r:   r@   s    r/   __post_init__'MemoryObjectReceiveStream.__post_init__@   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)rK   r   rI   r<   popitemr6   appendsetpopleftr9   r   r   )rA   
send_eventitems      r/   receive_nowait(MemoryObjectReceiveStream.receive_nowaitC   s     <<%%;;&&#{{::BBBNJKK%%d+NN;;;;%%--////r.   c                  #    [        5       I S h  vN    U R                  5       $  N! [         a    [        5       n/ nX R                  R
                  U'    UR                  5       I S h  vN    O! [        5        a    U(       d  e  Of = fU R                  R
                  R                  US 5        O+! U R                  R
                  R                  US 5        f = fU(       a  US   s $ [        ef = f7f)Nr   )
r   rZ   r   r   rI   r;   waitr   popr   )rA   receive_event	containers      r/   receive!MemoryObjectReceiveStream.receive_   s     l	"&&(( 	  	"!GM$&I;DKK))-8G#((****,  ! ! --11-F--11-F |#!!'	"sp   C7&C7( C7.C4A1*A-+A10B41B
B4	B

B4'C44(CC4+C7-C44C7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

rI   )rK   r   rG   rI   r@   s    r/   cloneMemoryObjectReceiveStream.clonex   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.

TrN   r   N)rK   rI   r:   listr<   keysrV   )rA   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r>   rm   r@   s    r/   aclose MemoryObjectReceiveStream.aclose        

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

.. versionadded:: 3.0
rI   rB   r@   s    r/   rB   $MemoryObjectReceiveStream.statistics        {{%%''r.   c                    U $ r>   r'   r@   s    r/   	__enter__#MemoryObjectReceiveStream.__enter__       r.   c                $    U R                  5         g r>   rp   rA   exc_typeexc_valexc_tbs       r/   __exit__"MemoryObjectReceiveStream.__exit__        	

r.   rK   NrE   None)rE   r   )rE   zMemoryObjectReceiveStream[T_co]rD   r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | NonerE   r   )r(   r)   r*   r+   r,   r   rK   rO   rZ   ra   re   rm   rq   rB   r{   r   r-   r'   r.   r/   rG   rG   ;   sl    ))ue4GT4/8"2=  (, & %	
 
r.   rG   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rg)MemoryObjectSendStream   z!MemoryObjectStreamState[T_contra]rI   Fr7   rJ   rK   c                B    U R                   =R                  S-  sl        g rM   )rI   r9   r@   s    r/   rO   $MemoryObjectSendStream.__post_init__   s    &&!+&r.   c                &   U R                   (       a  [        eU R                  R                  (       d  [        eU R                  R
                  (       aG  U R                  R
                  R                  SS9u  p#UR                  U5        UR                  5         Oc[        U R                  R                  5      U R                  R                  :  a&  U R                  R                  R                  U5        O[        e[        U R                  5      $ )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

FrR   )rK   r   rI   r:   r   r;   rT   rU   rV   r?   r6   r"   r   r   send_nowait)rA   rY   r_   r`   s       r/   r   "MemoryObjectSendStream.send_nowait   s     <<%%{{00%%;;(('+{{'D'D'L'LRW'L'X$MT"##$t{{'B'BBKK%%d+"4#3#344r.   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U R                  R
                  R                  US 5      (       a  [        e g f = f7fr>   )
r   r   r   r   rI   r<   r]   BaseExceptionr^   r   )rA   rY   rX   s      r/   sendMemoryObjectSendStream.send   s     l	*T" 	  	*J6:KK''
3 oo'''  ++//
DA {{**..z4@@)) A	*sR   C(C* C,CA1*A-+A10C12B##4C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

rd   )rK   r   r   rI   r@   s    r/   re   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rh   )rK   rI   r9   ri   r;   rj   clearrV   )rA   receive_eventsrl   s      r/   rm   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r>   rp   r@   s    r/   rq   MemoryObjectSendStream.aclose  rs   rt   c                6    U R                   R                  5       $ rv   rw   r@   s    r/   rB   !MemoryObjectSendStream.statistics  ry   r.   c                    U $ r>   r'   r@   s    r/   r{    MemoryObjectSendStream.__enter__  r}   r.   c                $    U R                  5         g r>   rp   r   s       r/   r   MemoryObjectSendStream.__exit__  r   r.   r   Nr   )rY   r   rE   r   )rY   r   rE   r   )rE   z MemoryObjectSendStream[T_contra]rD   r   )r(   r)   r*   r+   r,   r   rK   rO   r   r   re   rm   rq   rB   r{   r   r-   r'   r.   r/   r   r      sl    --ue4GT4,58*": "(, & %	
 
r.   r   N)#
__future__r   collectionsr   r   dataclassesr   r   typesr   typingr	   r
   r    r   r   r   r   r   _core._compatr   abcr   r   r   lowlevelr   r   r   r   r   r2   rG   r   r'   r.   r/   <module>r      s    " * (  / /  0 > > !		v&:T2:  e
gfo 
 
. eo/B4/H o od ehWX.0@0J h hr.   