
    Ag                     |    d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ dZ	 G d d	ej                        Zd
 Zy)z'Utilities for the gRPC Python Beta API.    N)implementations)
interfaces)callable_util)futurez6Exception calling connectivity future "done" callback!c                   `    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dd	Z
dd
ZddZd Zd Zd Zy)_ChannelReadyFuturec                 n    t        j                         | _        || _        d| _        d| _        g | _        y )NF)	threading	Condition
_condition_channel_matured
_cancelled_done_callbacks)selfchannels     H/var/www/openai/venv/lib/python3.12/site-packages/grpc/beta/utilities.py__init__z_ChannelReadyFuture.__init__   s/    #--/!    c                    |d nt        j                          |z   }| j                  5  	 | j                  rt        j                         | j
                  r
	 d d d        y || j                  j                          nL|t        j                          z
  }|dk  rt        j                         | j                  j                  |       # 1 sw Y   y xY w)Nr   )timeout)timer   r   r   CancelledErrorr   waitTimeoutError)r   r   until	remainings       r   _blockz_ChannelReadyFuture._block'   s    TYY[7-B__?? //11]] _ },,.$)DIIK$7	$q="("5"5"77 OO000C  _s   /C
 A*C

Cc                    | j                   5  | j                  s|t        j                  j                  u rcd| _        | j                  j                  | j                         | j                   j                          t        | j                        }d | _        n
	 d d d        y 	 d d d        D ]  }t        j                  |t        |         y # 1 sw Y   ,xY w)NT)r   r   r   ChannelConnectivityREADYr   r   unsubscribe_update
notify_alltupler   r   call_logging_exceptions$_DONE_CALLBACK_EXCEPTION_LOG_MESSAGE)r   connectivitydone_callbacksdone_callbacks       r   r#   z_ChannelReadyFuture._update9   s    __OO J$B$B$H$HH $))$,,7**,!&t';';!<'+$ _ %  ,M11CT , _s   BCCc                 ~   | j                   5  | j                  scd| _        | j                  j	                  | j
                         | j                   j                          t        | j                        }d | _        n
	 d d d        y	 d d d        D ]  }t        j                  |t        |         y# 1 sw Y   ,xY w)NTF)r   r   r   r   r"   r#   r$   r%   r   r   r&   r'   )r   r)   r*   s      r   cancelz_ChannelReadyFuture.cancelL   s    __=="&))$,,7**,!&t';';!<'+$ _ %  ,M11CT ,
  _s   A1B33B<c                 ^    | j                   5  | j                  cd d d        S # 1 sw Y   y xY wN)r   r   r   s    r   	cancelledz_ChannelReadyFuture.cancelled^   s    __?? __s   #,c                 ~    | j                   5  | j                   xr | j                   cd d d        S # 1 sw Y   y xY wr.   r   r   r   r/   s    r   runningz_ChannelReadyFuture.runningb   s)    __&<t}}+< __s   3<c                 z    | j                   5  | j                  xs | j                  cd d d        S # 1 sw Y   y xY wr.   r2   r/   s    r   donez_ChannelReadyFuture.donef   s#    __??3dmm __s   1:Nc                 &    | j                  |       y r.   r   r   r   s     r   resultz_ChannelReadyFuture.resultj       Gr   c                 &    | j                  |       y r.   r7   r8   s     r   	exceptionz_ChannelReadyFuture.exceptionn   r:   r   c                 &    | j                  |       y r.   r7   r8   s     r   	tracebackz_ChannelReadyFuture.tracebackr   r:   r   c                     | j                   5  | j                  s1| j                  s%| j                  j	                  |       	 d d d        y d d d         ||        y # 1 sw Y   xY wr.   )r   r   r   r   append)r   fns     r   add_done_callbackz%_ChannelReadyFuture.add_done_callbackv   sG    __??4==$$++B/ __
 	4 _s   5AA%c                     | j                   5  | j                  j                  | j                  d       d d d        y # 1 sw Y   y xY w)NT)try_to_connect)r   r   	subscriber#   r/   s    r   startz_ChannelReadyFuture.start~   s.    __MM##DLL#F __s	   (>Ac                     | j                   5  | j                  s1| j                  s%| j                  j	                  | j
                         d d d        y # 1 sw Y   y xY wr.   )r   r   r   r   r"   r#   r/   s    r   __del__z_ChannelReadyFuture.__del__   s6    __??4==))$,,7 __s   >AAr.   )__name__
__module____qualname__r   r   r#   r,   r0   r3   r5   r9   r<   r>   rB   rF   rH    r   r   r   r      sE    "D$&$#=4G8r   r   c                 <    t        |       }|j                          |S )a&  Creates a future.Future tracking when an implementations.Channel is ready.

    Cancelling the returned future.Future does not tell the given
    implementations.Channel to abandon attempts it may have been making to
    connect; cancelling merely deactivates the return future.Future's
    subscription to the given implementations.Channel's connectivity.

    Args:
      channel: An implementations.Channel.

    Returns:
      A future.Future that matures when the given Channel has connectivity
        interfaces.ChannelConnectivity.READY.
    )r   rF   )r   ready_futures     r   channel_ready_futurerO      s      'w/Lr   )__doc__r
   r   	grpc.betar   r   grpc.framework.foundationr   r   r'   Futurer   rO   rL   r   r   <module>rT      s@    .   &   3 , = %
g8&-- g8Tr   