
    Ng                     z    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dS )z'Utilities for the gRPC Python Beta API.    N)implementations)
interfaces)callable_util)futurez6Exception calling connectivity future "done" callback!c                   b    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dS )_ChannelReadyFuturec                 n    t          j                    | _        || _        d| _        d| _        g | _        d S )NF)	threading	Condition
_condition_channel_matured
_cancelled_done_callbacks)selfchannels     O/var/www/html/ai-engine/env/lib/python3.11/site-packages/grpc/beta/utilities.py__init__z_ChannelReadyFuture.__init__   s5    #-//!    c                    |d nt          j                     |z   }| j        5  	 | j        rt          j                    | j        r	 d d d            d S || j                                         nJ|t          j                     z
  }|dk     rt          j                    | j                            |           # 1 swxY w Y   d S )NTr   )timeout)timer   r   r   CancelledErrorr   waitTimeoutError)r   r   until	remainings       r   _blockz_ChannelReadyFuture._block'   s-   TY[[7-B_ 	D 	DD? D /111] 
D	D 	D 	D 	D 	D 	D 	D 	D },,....$)DIKK$7	$q=="("5"7"77 O000CCCD	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   $B:A'B::B>B>c                    | j         5  | j        sn|t          j        j        u r[d| _        | j                            | j                   | j         	                                 t          | j                  }d | _        n	 d d d            d S 	 d d d            n# 1 swxY w Y   |D ]}t          j        |t          |            d S )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   s5   _ 	 	O
 J$B$HHH $))$,777**,,,!&t';!<!<'+$$	 	 	 	 	 	 	 	 %	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 , 	 	M1CT   	 	s   A7BB Bc                 f   | j         5  | j        s[d| _        | j                            | j                   | j                                          t          | j                  }d | _        n	 d d d            dS 	 d d d            n# 1 swxY w Y   |D ]}t          j
        |t          |            dS )NTF)r   r   r   r   r"   r#   r$   r%   r   r   r&   r'   )r   r)   r*   s      r   cancelz_ChannelReadyFuture.cancelL   s!   _ 	 	= "&))$,777**,,,!&t';!<!<'+$$	 	 	 	 	 	 	 	 %	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 , 	 	M1CT    ts   A$BB
B
c                 R    | j         5  | j        cd d d            S # 1 swxY w Y   d S N)r   r   r   s    r   	cancelledz_ChannelReadyFuture.cancelled^   ss    _ 	# 	#?	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s     c                 d    | j         5  | j         o| j         cd d d            S # 1 swxY w Y   d S r.   r   r   r   r/   s    r   runningz_ChannelReadyFuture.runningb   s    _ 	= 	=&<t}+<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s   %))c                 `    | j         5  | j        p| j        cd d d            S # 1 swxY w Y   d S r.   r2   r/   s    r   donez_ChannelReadyFuture.donef   sz    _ 	4 	4?3dm	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   #''Nc                 0    |                      |           d S r.   r   r   r   s     r   resultz_ChannelReadyFuture.resultj       Gtr   c                 0    |                      |           d S r.   r7   r8   s     r   	exceptionz_ChannelReadyFuture.exceptionn   r:   r   c                 0    |                      |           d S r.   r7   r8   s     r   	tracebackz_ChannelReadyFuture.tracebackr   r:   r   c                     | j         5  | j        s/| j        s(| j                            |           	 d d d            d S d d d            n# 1 swxY w Y    ||            d S r.   )r   r   r   r   append)r   fns     r   add_done_callbackz%_ChannelReadyFuture.add_done_callbackv   s    _ 	 	? 4= $++B///	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 	4s   *AAAc                     | j         5  | j                            | j        d           d d d            d S # 1 swxY w Y   d S )NT)try_to_connect)r   r   	subscriber#   r/   s    r   startz_ChannelReadyFuture.start~   s    _ 	G 	GM##DL#FFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   "7;;c                     | j         5  | j        s&| j        s| j                            | j                   d d d            d S # 1 swxY w Y   d S r.   )r   r   r   r   r"   r#   r/   s    r   __del__z_ChannelReadyFuture.__del__   s    _ 	8 	8? 84= 8))$,777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   .AA
Ar.   )__name__
__module____qualname__r   r   r#   r,   r0   r3   r5   r9   r<   r>   rB   rF   rH    r   r   r   r      s        " " "D D D$  &  $# # #= = =4 4 4           G G G8 8 8 8 8r   r   c                 L    t          |           }|                                 |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 3 3 3 3 3 , , , , , , = %
g8 g8 g8 g8 g8&- g8 g8 g8T    r   