a
    v=icE                     @   sf   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	 d	ej
Zd
d ZdS )z'Utilities for the gRPC Python Beta API.    N)implementations)
interfaces)callable_util)futurez6Exception calling connectivity future "done" callback!c                   @   sz   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dddZ
dddZdddZdd Zdd Zdd ZdS )_ChannelReadyFuturec                 C   s&   t  | _|| _d| _d| _g | _d S )NF)	threading	Condition
_condition_channel_matured
_cancelled_done_callbacks)selfchannel r   d/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/grpc/beta/utilities.py__init__   s
    
z_ChannelReadyFuture.__init__c                 C   s   |d u rd n
t   | }| jx | jr0t q | jrFW d    d S |d u rZ| j  q |t    }|dk rxt q | jj|d q W d    n1 s0    Y  d S )Nr   )timeout)timer	   r   r   CancelledErrorr   waitTimeoutError)r   r   Zuntil	remainingr   r   r   _block'   s    

z_ChannelReadyFuture._blockc                 C   s   | j b | jsJ|tjju rJd| _| j| j | j 	  t
| j}d | _nW d    d S W d    n1 sn0    Y  |D ]}t|t|  q|d S )NT)r	   r   r   ZChannelConnectivityZREADYr   r
   unsubscribe_update
notify_alltupler   r   call_logging_exceptions$_DONE_CALLBACK_EXCEPTION_LOG_MESSAGE)r   Zconnectivitydone_callbacksdone_callbackr   r   r   r   9   s    


.z_ChannelReadyFuture._updatec                 C   s   | j V | js>d| _| j| j | j   t| j}d | _nW d    dS W d    n1 sb0    Y  |D ]}t	
|t|  qpdS )NTF)r	   r   r   r
   r   r   r   r   r   r   r   r   )r   r    r!   r   r   r   cancelI   s    

.z_ChannelReadyFuture.cancelc                 C   s0   | j  | jW  d    S 1 s"0    Y  d S N)r	   r   r   r   r   r   	cancelledZ   s    z_ChannelReadyFuture.cancelledc                 C   s:   | j   | j o| j W  d    S 1 s,0    Y  d S r#   r	   r   r   r$   r   r   r   running^   s    z_ChannelReadyFuture.runningc                 C   s6   | j  | jp| jW  d    S 1 s(0    Y  d S r#   r&   r$   r   r   r   doneb   s    z_ChannelReadyFuture.doneNc                 C   s   |  | d S r#   r   r   r   r   r   r   resultf   s    
z_ChannelReadyFuture.resultc                 C   s   |  | d S r#   r)   r*   r   r   r   	exceptionj   s    
z_ChannelReadyFuture.exceptionc                 C   s   |  | d S r#   r)   r*   r   r   r   	tracebackn   s    
z_ChannelReadyFuture.tracebackc                 C   sZ   | j 8 | js0| js0| j| W d    d S W d    n1 sD0    Y  ||  d S r#   )r	   r   r   r   append)r   fnr   r   r   add_done_callbackr   s
    .z%_ChannelReadyFuture.add_done_callbackc                 C   s<   | j " | jj| jdd W d    n1 s.0    Y  d S )NT)Ztry_to_connect)r	   r
   	subscriber   r$   r   r   r   startz   s    z_ChannelReadyFuture.startc                 C   sD   | j * | js"| js"| j| j W d    n1 s60    Y  d S r#   )r	   r   r   r
   r   r   r$   r   r   r   __del__~   s    z_ChannelReadyFuture.__del__)N)N)N)__name__
__module____qualname__r   r   r   r"   r%   r'   r(   r+   r,   r-   r0   r2   r3   r   r   r   r   r      s   


r   c                 C   s   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   r2   )r   Zready_futurer   r   r   channel_ready_future   s    r7   )__doc__r   r   Z	grpc.betar   r   Zgrpc.framework.foundationr   r   r   Futurer   r7   r   r   r   r   <module>   s   g