U
    "FZhSV                     @   s  d Z ddlZddlZddlmZmZmZmZm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d	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl#m%Z% ddl#m&Z& ddl#m'Z' ddl#m(Z( ddl#m)Z) ddl#m*Z* dd l+m,Z, d!-ej.Z/ej0d d"k reej1 d#d$d%Z2neej1 d#d&d%Z2e$ee	j3 d'd(d)Z4G d*d+ d+Z5G d,d- d-e5ej6Z6G d.d/ d/e5ej7Z7G d0d1 d1e5ej8Z8G d2d3 d3e5ej9Z9G d4d5 d5ej:Z:d<e;ee$ ee	j3 eee  d6d7d8Z<d=e;e	j=ee$ ee	j3 eee  d9d:d;Z>dS )>z6Invocation-side implementation of gRPC Asyncio Python.    N)AnyIterableListOptionalSequence)_common)_compression)_grpcio_metadata)cygrpc   )
_base_call)_base_channel)StreamStreamCall)StreamUnaryCall)UnaryStreamCall)UnaryUnaryCall)ClientInterceptor)InterceptedStreamStreamCall)InterceptedStreamUnaryCall)InterceptedUnaryStreamCall)InterceptedUnaryUnaryCall)StreamStreamClientInterceptor)StreamUnaryClientInterceptor)UnaryStreamClientInterceptor)UnaryUnaryClientInterceptor)Metadata)ChannelArgumentType)DeserializingFunction)MetadataType)RequestIterableType)RequestType)ResponseType)SerializingFunction)_timeout_to_deadlinezgrpc-python-asyncio/{}   returnc                   C   s
   t j S N)asyncioTask	all_tasks r+   r+   X/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/grpc/aio/_channel.py
_all_tasks7   s    r-   c                   C   s   t  S r'   )r(   r*   r+   r+   r+   r,   r-   <   s    )base_optionscompressionc                 C   s(   t |}tjjtff}t| | | S r'   )r   Zcreate_channel_optionr
   ZChannelArgKeyZprimary_user_agent_string_USER_AGENTtuple)r.   r/   Zcompression_channel_argumentZuser_agent_channel_argumentr+   r+   r,   _augment_channel_arguments@   s    r2   c                	   @   s   e Zd ZU dZejed< ejed< e	ed< e
ed< eed< eee  ed< ee ed< ejed< eje	e
eeee  ee ejd	d
ddZedee eej edddZd	S )_BaseMultiCallablezrBase class of all multi callable objects.

    Handles the initialization logic and stores common attributes.
    _loop_channel_method_request_serializer_response_deserializer_interceptors_referencesN)channelmethodrequest_serializerresponse_deserializerinterceptors
referencesloopr&   c                 C   s.   || _ || _|| _|| _|| _|| _|| _d S r'   )r4   r5   r6   r7   r8   r9   r:   )selfr;   r<   r=   r>   r?   r@   rA   r+   r+   r,   __init__c   s    
z_BaseMultiCallable.__init__)metadatar/   r&   c                 C   s@   | pt  } t| t s(t| tr(t | } |r<t t| | } | S )zBased on the provided values for <metadata> or <compression> initialise the final
        metadata, as it should be used for the current call.
        )r   
isinstancer1   Z
from_tupler   Zaugment_metadata)rD   r/   r+   r+   r,   _init_metadatau   s    


z!_BaseMultiCallable._init_metadata)NN)__name__
__module____qualname____doc__r(   AbstractEventLoop__annotations__r
   
AioChannelbytesr"   r   r   r   r   r   r   rC   staticmethodr   grpcCompressionr   rF   r+   r+   r+   r,   r3   S   s4   




  r3   c                
   @   sV   e Zd Zddddddeee ee eej ee	 eej
 ejeef dddZdS )UnaryUnaryMultiCallableNtimeoutrD   credentialswait_for_readyr/   requestrT   rD   rU   rV   r/   r&   c                C   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r'   )
rF   r9   r   r#   r5   r6   r7   r8   r4   r   rB   rX   rT   rD   rU   rV   r/   callr+   r+   r,   __call__   s8    
z UnaryUnaryMultiCallable.__call__)rG   rH   rI   r    r   floatr   rP   CallCredentialsboolrQ   r   r   r!   r[   r+   r+   r+   r,   rR      s   rR   c                
   @   sV   e Zd Zddddddeee ee eej ee	 eej
 ejeef dddZdS )UnaryStreamMultiCallableNrS   rW   c                C   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r'   )
rF   r9   r   r#   r5   r6   r7   r8   r4   r   rY   r+   r+   r,   r[      s8    
z!UnaryStreamMultiCallable.__call__)rG   rH   rI   r    r   r\   r   rP   r]   r^   rQ   r   r   r!   r[   r+   r+   r+   r,   r_      s   r_   c                	   @   sF   e Zd Zdee ee ee eej ee	 eej
 ejdddZdS )StreamUnaryMultiCallableNrequest_iteratorrT   rD   rU   rV   r/   r&   c                 C   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r'   )
rF   r9   r   r#   r5   r6   r7   r8   r4   r   rB   rb   rT   rD   rU   rV   r/   rZ   r+   r+   r,   r[      s8    	z!StreamUnaryMultiCallable.__call__)NNNNNN)rG   rH   rI   r   r   r\   r   rP   r]   r^   rQ   r   r   r[   r+   r+   r+   r,   r`      s         r`   c                	   @   sF   e Zd Zdee ee ee eej ee	 eej
 ejdddZdS )StreamStreamMultiCallableNra   c                 C   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r'   )
rF   r9   r   r#   r5   r6   r7   r8   r4   r   rc   r+   r+   r,   r[     s8    	z"StreamStreamMultiCallable.__call__)NNNNNN)rG   rH   rI   r   r   r\   r   rP   r]   r^   rQ   r   r   r[   r+   r+   r+   r,   rd     s         rd   c                   @   s  e Zd ZU ejed< ejed< ee	 ed< ee
 ed< ee ed< ee ed< eeeej eej eee  ddd	Zd
d Zdd Zdd Zd,ee dddZdd Zd-eejdddZejddddZddddZ ee!d d!d"Z"d.eee# ee$ ee e%d#d$d%Z&d/eee# ee$ ee e'd#d&d'Z(d0eee# ee$ ee e)d#d(d)Z*d1eee# ee$ ee e+d#d*d+Z,dS )2Channelr4   r5   _unary_unary_interceptors_unary_stream_interceptors_stream_unary_interceptors_stream_stream_interceptors)targetoptionsrU   r/   r?   c                 C   s   g | _ g | _g | _g | _|dk	r|D ]}t|tr@| j | q$t|trX| j| q$t|trp| j| q$t|t	r| j| q$t
d|dtj dtj dtj dt	j q$t | _tt|t|||| j| _dS )a  Constructor.

        Args:
          target: The target to which to connect.
          options: Configuration options for the channel.
          credentials: A cygrpc.ChannelCredentials or None.
          compression: An optional value indicating the compression method to be
            used over the lifetime of the channel.
          interceptors: An optional list of interceptors that would be used for
            intercepting any RPC executed with that channel.
        NzInterceptor {} must be z{} or z{}. )rf   rg   rh   ri   rE   r   appendr   r   r   
ValueErrorformatrG   r
   Zget_working_loopr4   rM   r   encoder2   r5   )rB   rj   rk   rU   r/   r?   Zinterceptorr+   r+   r,   rC   D  s@    








zChannel.__init__c                    s   | S r'   r+   rB   r+   r+   r,   
__aenter__w  s    zChannel.__aenter__c                    s   |  d I d H  d S r'   _close)rB   exc_typeexc_valexc_tbr+   r+   r,   	__aexit__z  s    zChannel.__aexit__c                    sF  | j  rd S | j   t }g }g }|D ]}z|jdd}W n: tk
rx } zdt|krfW Y 
q*n W 5 d }~X Y nX |sq*|d }|jd}	|	d k	r*t	|	t
jr*t|	dr|	j | j k	rq*n,t|	dr|	jj | j k	rq*ntd|	 ||	 || q*|r$|r$tj||d	I d H  |D ]}
|
  q(| j   d S )
Nr   )limitframer   rB   r5   _cython_callzUnrecognized call object: )rT   )r5   closedclosingr-   Z	get_stackAttributeErrorstrf_localsgetrE   r   Callhasattrrz   r
   ZInternalErrorrl   r(   waitcancelclose)rB   gracetasksZcallsZ
call_taskstaskstackZattribute_errorry   	candidaterZ   r+   r+   r,   rs   }  sF    





zChannel._closeN)r   c                    s   |  |I d H  d S r'   rr   )rB   r   r+   r+   r,   r     s    zChannel.closec                 C   s"   t | dr| j s| j  d S )Nr5   )r   r5   r{   r   rp   r+   r+   r,   __del__  s    

zChannel.__del__F)try_to_connectr&   c                 C   s   | j |}tj| S r'   )r5   Zcheck_connectivity_stater   Z1CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY)rB   r   resultr+   r+   r,   	get_state  s    zChannel.get_state)last_observed_stater&   c                    s"   | j |jd d I d H std S )Nr   )r5   Zwatch_connectivity_statevalueAssertionError)rB   r   r+   r+   r,   wait_for_state_change  s     zChannel.wait_for_state_changer%   c                    s:   | j dd}|tjjkr6| |I d H  | j dd}qd S )NT)r   )r   rP   ChannelConnectivityZREADYr   )rB   stater+   r+   r,   channel_ready  s    zChannel.channel_ready)r<   r&   c                 C   s   d S r'   r+   )rB   r<   r+   r+   r,   _get_registered_call_handle  s    z#Channel._get_registered_call_handle)r<   r=   r>   _registered_methodr&   c                 C   s"   t | jt|||| j| g| jS r'   )rR   r5   r   ro   rf   r4   rB   r<   r=   r>   r   r+   r+   r,   unary_unary  s    zChannel.unary_unaryc                 C   s"   t | jt|||| j| g| jS r'   )r_   r5   r   ro   rg   r4   r   r+   r+   r,   unary_stream   s    zChannel.unary_streamc                 C   s"   t | jt|||| j| g| jS r'   )r`   r5   r   ro   rh   r4   r   r+   r+   r,   stream_unary  s    zChannel.stream_unaryc                 C   s"   t | jt|||| j| g| jS r'   )rd   r5   r   ro   ri   r4   r   r+   r+   r,   stream_stream(  s    zChannel.stream_stream)N)F)NNF)NNF)NNF)NNF)-rG   rH   rI   r(   rK   rL   r
   rM   r   r   r   r   r   r~   r   r   rP   ChannelCredentialsrQ   r   r   rC   rq   rw   rs   r\   r   r   r^   r   r   r   r   intr   r"   r   rR   r   r_   r   r`   r   rd   r   r+   r+   r+   r,   re   <  s   



3K 	            re   rj   rk   r/   r?   c                 C   s   t | |dkrdn|d||S )a  Creates an insecure asynchronous Channel to a server.

    Args:
      target: The server address
      options: An optional list of key-value pairs (:term:`channel_arguments`
        in gRPC Core runtime) to configure the channel.
      compression: An optional value indicating the compression method to be
        used over the lifetime of the channel.
      interceptors: An optional sequence of interceptors that will be executed for
        any call executed with this channel.

    Returns:
      A Channel.
    Nr+   )re   r   r+   r+   r,   insecure_channel:  s    r   rj   rU   rk   r/   r?   c                 C   s   t | |dkrdn||j||S )a<  Creates a secure asynchronous Channel to a server.

    Args:
      target: The server address.
      credentials: A ChannelCredentials instance.
      options: An optional list of key-value pairs (:term:`channel_arguments`
        in gRPC Core runtime) to configure the channel.
      compression: An optional value indicating the compression method to be
        used over the lifetime of the channel.
      interceptors: An optional sequence of interceptors that will be executed for
        any call executed with this channel.

    Returns:
      An aio.Channel.
    Nr+   )re   Z_credentialsr   r+   r+   r,   secure_channelW  s    r   )NNN)NNN)?rJ   r(   systypingr   r   r   r   r   rP   r   r   r	   Zgrpc._cythonr
    r   r   Z_callr   r   r   r   Z_interceptorr   r   r   r   r   r   r   r   r   	_metadatar   Z_typingr   r   r   r   r    r!   r"   Z_utilsr#   rn   __version__r0   version_infor)   r-   rQ   r2   r3   rR   r_   r`   rd   re   r~   r   r   r   r+   r+   r+   r,   <module>   s    4
 -
 .
 -
 -     
    
