a
    v=icN                     @   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*ej+Z,ej-d dk reej. d d!d"Z/neej. d d#d"Z/e$ee	j0 d$d%d&Z1G d'd( d(Z2G d)d* d*e2ej3Z3G d+d, d,e2ej4Z4G d-d. d.e2ej5Z5G d/d0 d0e2ej6Z6G d1d2 d2ej7Z7d9e8ee$ ee	j0 eee  d3d4d5Z9d:e8e	j:ee$ ee	j0 eee  d6d7d8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)RequestIterableType)SerializingFunction)_timeout_to_deadlinezgrpc-python-asyncio/{}   returnc                   C   s
   t j S N)asyncioTask	all_tasks r(   r(   b/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/grpc/aio/_channel.py
_all_tasks4   s    r*   c                   C   s   t  S r$   )r%   r'   r(   r(   r(   r)   r*   8   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    r/   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$   )r1   r2   r3   r4   r5   r6   r7   )selfr8   r9   r:   r;   r<   r=   r>   r(   r(   r)   __init__W   s    
z_BaseMultiCallable.__init__)metadatar,   r#   c                 C   s"   | p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   r   Zaugment_metadata)rA   r,   r(   r(   r)   _init_metadatai   s    

z!_BaseMultiCallable._init_metadata)NN)__name__
__module____qualname____doc__r%   AbstractEventLoop__annotations__r
   
AioChannelbytesr   r   r   r   r   r   r   r@   staticmethodr   grpcCompressionrB   r(   r(   r(   r)   r0   H   s2   




  
r0   c                	   @   sN   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dddZdS )UnaryUnaryMultiCallableNtimeoutrA   credentialswait_for_readyr,   requestrP   rA   rQ   rR   r,   r#   c                C   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r$   )
rB   r6   r   r    r2   r3   r4   r5   r1   r   )r?   rT   rP   rA   rQ   rR   r,   callr(   r(   r)   __call__z   s    

z UnaryUnaryMultiCallable.__call__)rC   rD   rE   r   r   floatr   rL   CallCredentialsboolrM   r   r   rV   r(   r(   r(   r)   rN   w   s   rN   c                	   @   sN   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dddZdS )UnaryStreamMultiCallableNrO   rS   c          	      C   sl   |  ||}t|}| js@t|||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r$   )
rB   r    r6   r   r2   r3   r4   r5   r1   r   )	r?   rT   rP   rA   rQ   rR   r,   deadlinerU   r(   r(   r)   rV      s    


z!UnaryStreamMultiCallable.__call__)rC   rD   rE   r   r   rW   r   rL   rX   rY   rM   r   r   rV   r(   r(   r(   r)   rZ      s   rZ   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_iteratorrP   rA   rQ   rR   r,   r#   c           	      C   sl   |  ||}t|}| js@t|||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r$   )
rB   r    r6   r   r2   r3   r4   r5   r1   r   	r?   r^   rP   rA   rQ   rR   r,   r[   rU   r(   r(   r)   rV      s    

z!StreamUnaryMultiCallable.__call__)NNNNNN)rC   rD   rE   r   r   rW   r   rL   rX   rY   rM   r   r   rV   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 )StreamStreamMultiCallableNr]   c           	      C   sl   |  ||}t|}| js@t|||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r$   )
rB   r    r6   r   r2   r3   r4   r5   r1   r   r_   r(   r(   r)   rV      s    

z"StreamStreamMultiCallable.__call__)NNNNNN)rC   rD   rE   r   r   rW   r   rL   rX   rY   rM   r   r   rV   r(   r(   r(   r)   r`      s         r`   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 d+eee! ee" e#d d!d"Z$d,eee! ee" e%d d#d$Z&d-eee! ee" e'd d%d&Z(d.eee! ee" e)d d'd(Z*dS )/Channelr1   r2   _unary_unary_interceptors_unary_stream_interceptors_stream_unary_interceptors_stream_stream_interceptors)targetoptionsrQ   r,   r<   c                 C   s   g | _ g | _g | _g | _|du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{}. )rb   rc   rd   re   
isinstancer   appendr   r   r   
ValueErrorformatrC   r
   Zget_working_loopr1   rI   r   encoder/   r2   )r?   rf   rg   rQ   r,   r<   Zinterceptorr(   r(   r)   r@      s>    









zChannel.__init__c                    s   | S r$   r(   r?   r(   r(   r)   
__aenter__(  s    zChannel.__aenter__c                    s   |  d I d H  d S r$   _close)r?   exc_typeexc_valexc_tbr(   r(   r)   	__aexit__+  s    zChannel.__aexit__c                    sH  | j  rd S | j   t }g }g }|D ]}z|jdd}W n@ ty~ } z(dt|v rhW Y d }~q*n W Y d }~n
d }~0 0 |sq*|d }|jd}	|	r*t	|	t
jr*t|	dr|	j | j urq*n,t|	dr|	jj | j urq*ntd|	 ||	 || q*|r&|r&tj||d	I d H  |D ]}
|
  q*| j   d S )
Nr   )limitframer   r?   r2   _cython_callzUnrecognized call object: )rP   )r2   closedclosingr*   	get_stackAttributeErrorstrf_localsgetrh   r   Callhasattrrw   r
   ZInternalErrorri   r%   waitcancelclose)r?   gracetasksZcallsZ
call_taskstaskstackZattribute_errorrv   	candidaterU   r(   r(   r)   rp   .  sF    




zChannel._closeN)r   c                    s   |  |I d H  d S r$   ro   )r?   r   r(   r(   r)   r   u  s    zChannel.closec                 C   s"   t | dr| j s| j  d S )Nr2   )r   r2   rx   r   rm   r(   r(   r)   __del__x  s    

zChannel.__del__F)try_to_connectr#   c                 C   s   | j |}tj| S r$   )r2   Zcheck_connectivity_stater   Z1CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY)r?   r   resultr(   r(   r)   	get_state}  s    zChannel.get_state)last_observed_stater#   c                    s"   | j |jd d I d H sJ d S )Nr   )r2   Zwatch_connectivity_statevalue)r?   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   rL   ChannelConnectivityZREADYr   )r?   stater(   r(   r)   channel_ready  s    zChannel.channel_ready)r9   r:   r;   r#   c                 C   s"   t | jt|||| j| g| jS r$   )rN   r2   r   rl   rb   r1   r?   r9   r:   r;   r(   r(   r)   unary_unary  s    zChannel.unary_unaryc                 C   s"   t | jt|||| j| g| jS r$   )rZ   r2   r   rl   rc   r1   r   r(   r(   r)   unary_stream  s    zChannel.unary_streamc                 C   s"   t | jt|||| j| g| jS r$   )r\   r2   r   rl   rd   r1   r   r(   r(   r)   stream_unary  s    zChannel.stream_unaryc                 C   s"   t | jt|||| j| g| jS r$   )r`   r2   r   rl   re   r1   r   r(   r(   r)   stream_stream  s    zChannel.stream_stream)N)F)NN)NN)NN)NN)+rC   rD   rE   r%   rG   rH   r
   rI   r   r   r   r   r   r|   r   r   rL   ChannelCredentialsrM   r   r   r@   rn   rt   rp   rW   r   r   rY   r   r   r   r   r   r   rN   r   rZ   r   r\   r   r`   r   r(   r(   r(   r)   ra      sp   



,G 	        ra   rf   rg   r,   r<   c                 C   s   t | |du 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. This is an EXPERIMENTAL option.
      interceptors: An optional sequence of interceptors that will be executed for
        any call executed with this channel.

    Returns:
      A Channel.
    Nr(   )ra   r   r(   r(   r)   insecure_channel  s    r   rf   rQ   rg   r,   r<   c                 C   s   t | |du 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. This is an EXPERIMENTAL option.
      interceptors: An optional sequence of interceptors that will be executed for
        any call executed with this channel.

    Returns:
      An aio.Channel.
    Nr(   )ra   Z_credentialsr   r(   r(   r)   secure_channel  s    r   )NNN)NNN)<rF   r%   systypingr   r   r   r   r   rL   r   r   r	   Zgrpc._cythonr
    r   r   _callr   r   r   r   Z_interceptorr   r   r   r   r   r   r   r   r   	_metadatar   Z_typingr   r   r   r   _utilsr    rk   __version__r-   version_infor&   r*   rM   r/   r0   rN   rZ   r\   r`   ra   r|   r   r   r   r(   r(   r(   r)   <module>   s   /  O   
   
