
    F\h^                     P   S r SSKrSSKrSSKJr  SSKJrJrJrJ	r	J
r
  SSKJrJr  / SQr " S S	\\R                  5      r\R                  R!                  S
\5      rS rS r\S.S jrS r " S S5      r\" 5       r " S S\5      r " S S\5      r\R8                  " \\5        g)z-Cross-interpreter Channels High Level Module.    N   )_crossinterp)ChannelErrorChannelNotFoundErrorChannelClosedErrorChannelEmptyErrorChannelNotEmptyError)UNBOUND_ERRORUNBOUND_REMOVE)UNBOUNDr
   r   createlist_allSendChannelRecvChannelr   r   r   ItemInterpreterDestroyedc                       \ rS rSrSrSrg)r      z#Raised from get() and get_nowait(). N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       9/usr/lib/python3.13/test/support/interpreters/channels.pyr   r      s    -r   r   queuec                 `    U [         L a  [        R                   n [        R                  " U 5      $ N)r   r   serialize_unboundunbounds    r   _serialize_unboundr#   "   s&    '&&))'22r   c                 n    [         R                  " U [        5      nU[         R                  L a  [        nU$ r   )r   resolve_unboundr   r   )flagresolveds     r   _resolve_unboundr(   (   s-    ++D2JKH<'''Or   )unbounditemsc                 x    [        U 5      nUu  n[        R                  " U5      n[        U5      [	        X1S9pTXE4$ )a9  Return (recv, send) for a new cross-interpreter channel.

The channel may be used to pass data safely between interpreters.

"unbounditems" sets the default for the send end of the channel.
See SendChannel.send() for supported values.  The default value
is UNBOUND, which replaces the unbound item when received.
_unbound)r#   	_channelsr   r   r   )r)   r"   	unboundopcidrecvsends         r   r   r   /   s>     !.GJI


9
%CS!;s#E$:r   c            
          [         R                  " 5        V Vs/ s H  u  p[        U 5      [        XS94PM     snn $ s  snn f )z4Return a list of (recv, send) for all open channels.r+   )r-   r   r   r   )r/   r"   s     r   r   r   ?   sC     !* 2 2 46 4 {3AB 46 6 6s    =c                   ~   ^  \ rS rSrSrSrU 4S jrS rS rS r	S r
S	 r\S
 5       r\S 5       r\S 5       rSrU =r$ )_ChannelEndE   z/The base class for RecvChannel and SendChannel.Nc                    > [         TU ]  U 5      nUR                  S:X  a  [        R                  " USSS9nO<UR                  S:X  a  [        R                  " USSS9nO[        UR                  5      eXl        U$ )Nr1   T)r1   forcer0   )r0   r7   )super__new___endr-   _channel_idNotImplementedError_id)clsr/   self	__class__s      r   r9   _ChannelEnd.__new__J   sj    ws#99''$dCCYY& ''$dCC%dii00r   c                 ^    [        U 5      R                   S[        U R                  5       S3$ )Nz(id=))typer   intr=   r?   s    r   __repr___ChannelEnd.__repr__U   s(    t*%%&d3txx=/;;r   c                 ,    [        U R                  5      $ r   )hashr=   rF   s    r   __hash___ChannelEnd.__hash__X   s    DHH~r   c                     [        U [        5      (       a  [        U[        5      (       d  [        $ O[        U[        5      (       d  [        $ UR                  U R                  :H  $ r   )
isinstancer   NotImplementedr   r=   )r?   others     r   __eq___ChannelEnd.__eq__[   sM    dK((e[11%% 2E;//!!yyDHH$$r   c                 .    [        U R                  5      4$ r   )rE   r=   rF   s    r   __getnewargs___ChannelEnd.__getnewargs__d   s    DHHr   c                     g r   r   rF   s    r   __getstate___ChannelEnd.__getstate__h   s    r   c                     U R                   $ r   r=   rF   s    r   id_ChannelEnd.idk   s    xxr   c                 B    [         R                  " U R                  5      $ r   )r-   get_infor=   rF   s    r   _info_ChannelEnd._infoo   s    !!$((++r   c                 .    U R                   R                  $ r   )r_   closedrF   s    r   	is_closed_ChannelEnd.is_closeds   s    zz   r   rZ   )r   r   r   r   r   r:   r9   rG   rK   rQ   rT   rW   propertyr[   r_   rc   r   __classcell__r@   s   @r   r4   r4   E   se    9D	<%    , , ! !r   r4   c                   L    \ rS rSrSrSrS\" 5       SS.S jjr\4S jr	S	 r
S
rg)r   {   z1The receiving end of a cross-interpreter channel.r0   Ng{Gz?)	_sentinel_delayc                   Ub4  [        U5      nUS:  a  [        S5      e[        R                  " 5       U-   n[        R                  " U R
                  U5      u  pVXRL aa  [        R                  " U5        Ub  [        R                  " 5       W:  a  [        e[        R                  " U R
                  U5      u  pVXRL a  Ma  Ub  Ub   [        U5      5       e[        U5      $ U$ )zuReturn the next object from the channel.

This blocks until an object has been sent, if none have been
sent already.
r   z"timeout value must be non-negative)
rE   
ValueErrortimer-   r0   r=   sleepTimeoutErrorreprr(   )r?   timeoutrj   rk   endobjr.   s          r   r0   RecvChannel.recv   s     'lG{ #EGG))+'C")<JJv"tyy{c'9""&^^DHHi@NC	 
  ;)S	);#I..
r   c                     U[         L a#  [        R                  " U R                  5      u  p#O#[        R                  " U R                  U5      u  p#Ub  Ub   [	        U5      5       e[        U5      $ U$ )zReturn the next object from the channel.

If none have been sent then return the default if one
is provided or fail with ChannelEmptyError.  Otherwise this
is the same as recv().
)_NOT_SETr-   r0   r=   rq   r(   )r?   defaultrt   r.   s       r   recv_nowaitRecvChannel.recv_nowait   sa     h&^^DHH5NC&^^DHHg>NC ;)S	);#I..
r   c                 B    [         R                  " U R                  SS9  g )NT)r0   r-   closer=   rF   s    r   r}   RecvChannel.close       t,r   r   r   )r   r   r   r   r   r:   objectr0   rw   ry   r}   r   r   r   r   r   r   {   s+    ;Dx2 #+  -r   r   c                      ^  \ rS rSrSrSrSS.U 4S jjr\S 5       rSSS.S	 jjr	SS.S
 jr
SSS.S jjrSS.S jrS rSrU =r$ )r      z/The sending end of a cross-interpreter channel.r1   Nr+   c                   > Uc   [         R                  " U5      nU4n[
        TU ]  X5      nX$l        U$ ! [         a    [        [        5      n N2f = fr   )r-   get_channel_defaultsr   r#   r   r8   r9   r,   )r>   r/   r,   opr?   r@   s        r   r9   SendChannel.__new__   sZ    733C85 ws( 	 ( 7-g67s   6 AAc                 X    U R                   nUR                  =(       d    UR                  $ r   )r_   rb   closing)r?   infos     r   rc   SendChannel.is_closed   s    zz{{*dll*r   r!   c                    Uc  U R                   u  nO[        U5      u  n[        R                  " U R                  XUSS9  g)zkSend the object (i.e. its data) to the channel's receiving end.

This blocks until the object is received.
NTrr   blockingr,   r#   r-   r1   r=   r?   rt   rr   r"   r.   s        r   r1   SendChannel.send   s6     ?JI+G4JItxx4Pr   c                    Uc  U R                   u  nO[        U5      u  n[        R                  " U R                  XSS9$ )zSend the object to the channel's receiving end.

If the object is immediately received then return True
(else False).  Otherwise this is the same as send().
Fr   r   r?   rt   r"   r.   s       r   send_nowaitSendChannel.send_nowait   s9     ?JI+G4JI ~~dhhGGr   c                    Uc  U R                   u  nO[        U5      u  n[        R                  " U R                  XUSS9  g)zdSend the object's buffer to the channel's receiving end.

This blocks until the object is received.
NTr   r,   r#   r-   send_bufferr=   r   s        r   r   SendChannel.send_buffer   s;     ?JI+G4JIdhh&-	>r   c                    Uc  U R                   u  nO[        U5      u  n[        R                  " U R                  XSS9$ )zSend the object's buffer to the channel's receiving end.

If the object is immediately received then return True
(else False).  Otherwise this is the same as send().
Fr   r   r   s       r   send_buffer_nowaitSendChannel.send_buffer_nowait   s9     ?JI+G4JI$$TXXsNNr   c                 B    [         R                  " U R                  SS9  g )NT)r1   r|   rF   s    r   r}   SendChannel.close   r   r   r   )r   r   r   r   r   r:   r9   re   rc   r1   r   r   r   r}   r   rf   rg   s   @r   r   r      sh    9D&* 	 	 + +QQ !H"> > $(O- -r   r   )r   rn   _interpchannelsr-    r   r   r   r   r   r	   r
   r   __all__r   UnboundItem	singletonr   r   r#   r(   r   r   r4   r   rw   r   r   _register_end_typesr   r   r   <module>r      s    3  #  
.|+DD.
 
"
"
,
,Wh
?3 #  60! 0!f 8/-+ /-dP-+ P-h 
  k; 7r   