o
    i eP                     @   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 ,ej-Z.ej/d d!k rd"eej0 fd#d$Z1n
d"eej0 fd%d$Z1d&e$d'ee	j2 fd(d)Z3G d*d+ d+Z4G d,d- d-e4ej5Z5G d.d/ d/e4ej6Z6G d0d1 d1e4ej7Z7G d2d3 d3e4ej8Z8G d4d5 d5ej9Z9			d>d6e:d7ee$ d'ee	j2 d8eee  fd9d:Z;			d>d6e:d;e	j<d7ee$ d'ee	j2 d8eee  f
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)RequestIterableType)RequestType)ResponseType)SerializingFunction)_timeout_to_deadlinezgrpc-python-asyncio/{}   returnc                   C   s
   t j S N)asyncioTask	all_tasks r)   r)   @/var/www/myenv/lib/python3.10/site-packages/grpc/aio/_channel.py
_all_tasks6   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   create_channel_optionr
   ChannelArgKeyprimary_user_agent_string_USER_AGENTtuple)r,   r-   compression_channel_argumentuser_agent_channel_argumentr)   r)   r*   _augment_channel_arguments?   s   r5   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< d	ejd
e	de
dedeee  dee dejddfddZe		ddee deej def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_referenceschannelmethodrequest_serializerresponse_deserializerinterceptors
referencesloopr$   Nc                 C   s.   || _ || _|| _|| _|| _|| _|| _d S r%   )r7   r8   r9   r:   r;   r<   r=   )selfr>   r?   r@   rA   rB   rC   rD   r)   r)   r*   __init__b   s   

z_BaseMultiCallable.__init__metadatar-   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   augment_metadata)rG   r-   r)   r)   r*   _init_metadatat   s   

z!_BaseMultiCallable._init_metadataNN)__name__
__module____qualname____doc__r&   AbstractEventLoop__annotations__r
   
AioChannelbytesr!   r   r   r   r   r   r   rF   staticmethodr   grpcCompressionrI   r)   r)   r)   r*   r6   R   sJ   
 



	
r6   c                   @   b   e Zd Zdddddddedee dee deej dee	 deej
 d	ejeef fd
dZdS )UnaryUnaryMultiCallableNtimeoutrG   credentialswait_for_readyr-   requestrY   rG   rZ   r[   r-   r$   c                C   j   |  ||}| jst|t||||| j| j| j| j| j
}|S t	| j|||||| j| j| j| j| j}|S r%   )
rI   r<   r   r"   r8   r9   r:   r;   r7   r   rE   r\   rY   rG   rZ   r[   r-   callr)   r)   r*   __call__   s:   
z UnaryUnaryMultiCallable.__call__)rK   rL   rM   r   r   floatr   rT   CallCredentialsboolrU   r   r   r    r`   r)   r)   r)   r*   rW      *    	rW   c                   @   rV   )UnaryStreamMultiCallableNrX   r\   rY   rG   rZ   r[   r-   r$   c                C   r]   r%   )
rI   r<   r   r"   r8   r9   r:   r;   r7   r   r^   r)   r)   r*   r`      s:   
z!UnaryStreamMultiCallable.__call__)rK   rL   rM   r   r   ra   r   rT   rb   rc   rU   r   r   r    r`   r)   r)   r)   r*   re      rd   re   c                   @   ^   e Zd Z						ddee dee dee deej dee	 deej
 dejfd	d
ZdS )StreamUnaryMultiCallableNrequest_iteratorrY   rG   rZ   r[   r-   r$   c                 C   r]   r%   )
rI   r<   r   r"   r8   r9   r:   r;   r7   r   rE   rh   rY   rG   rZ   r[   r-   r_   r)   r)   r*   r`      :   	z!StreamUnaryMultiCallable.__call__NNNNNN)rK   rL   rM   r   r   ra   r   rT   rb   rc   rU   r   r   r`   r)   r)   r)   r*   rg      ,    rg   c                   @   rf   )StreamStreamMultiCallableNrh   rY   rG   rZ   r[   r-   r$   c                 C   r]   r%   )
rI   r<   r   r"   r8   r9   r:   r;   r7   r   ri   r)   r)   r*   r`     rj   z"StreamStreamMultiCallable.__call__rk   )rK   rL   rM   r   r   ra   r   rT   rb   rc   rU   r   r   r`   r)   r)   r)   r*   rm     rl   rm   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< deded	eej d
eej deee  f
ddZdd Zdd Zdd Zd/dee fddZdd Z	d0dedejfddZdejddfd d!Zd1d"d#Z 		d2d$ed%ee! d&ee" de#fd'd(Z$		d2d$ed%ee! d&ee" de%fd)d*Z&		d2d$ed%ee! d&ee" de'fd+d,Z(		d2d$ed%ee! d&ee" de)fd-d.Z*dS )3Channelr7   r8   _unary_unary_interceptors_unary_stream_interceptors_stream_unary_interceptors_stream_stream_interceptorstargetoptionsrZ   r-   rB   c                 C   s   g | _ g | _g | _g | _|durc|D ]P}t|tr | j | qt|tr,| j| qt|tr8| j| qt|t	rD| j| qt
d|dtj dtj dtj dt	j 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{}. )ro   rp   rq   rr   
isinstancer   appendr   r   r   
ValueErrorformatrK   r
   get_working_loopr7   rQ   r   encoder5   r8   )rE   rs   rt   rZ   r-   rB   interceptorr)   r)   r*   rF   A  s@   









zChannel.__init__c                    s   | S r%   r)   rE   r)   r)   r*   
__aenter__t  s   zChannel.__aenter__c                    s   |  d I d H  d S r%   _close)rE   exc_typeexc_valexc_tbr)   r)   r*   	__aexit__w     zChannel.__aexit__c                    s6  | j  rd S | j   t }g }g }|D ]f}z|jdd}W n ty9 } zdt|v r4W Y d }~q d }~ww |s=q|d }|jd}	|	r|t	|	t
jr|t|	dr\|	j | j ur[qnt|	drj|	jj | j uriqntd|	 ||	 || q|r|rtj||d	I d H  |D ]}
|
  q| j   d S )
Nr   )limitframer   rE   r8   _cython_callzUnrecognized call object: )rY   )r8   closedclosingr+   	get_stackAttributeErrorstrf_localsgetru   r   Callhasattrr   r
   InternalErrorrv   r&   waitcancelclose)rE   gracetaskscalls
call_taskstaskstackattribute_errorr   	candidater_   r)   r)   r*   r   z  sR   






zChannel._closeNr   c                    s   |  |I d H  d S r%   r~   )rE   r   r)   r)   r*   r     r   zChannel.closec                 C   s*   t | dr| j s| j  d S d S d S )Nr8   )r   r8   r   r   r|   r)   r)   r*   __del__  s
   

zChannel.__del__Ftry_to_connectr$   c                 C   s   | j |}tj| S r%   )r8   check_connectivity_stater   1CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY)rE   r   resultr)   r)   r*   	get_state  s   
zChannel.get_statelast_observed_statec                    s$   | j |jd d I d H sJ d S )Nr   )r8   watch_connectivity_statevalue)rE   r   r)   r)   r*   wait_for_state_change  s   
zChannel.wait_for_state_changec                    sJ   | j dd}|tjjkr#| |I d H  | j dd}|tjjksd S d S )NT)r   )r   rT   ChannelConnectivityREADYr   )rE   stater)   r)   r*   channel_ready  s   zChannel.channel_readyr?   r@   rA   c                 C   "   t | jt|||| j| g| jS r%   )rW   r8   r   rz   ro   r7   rE   r?   r@   rA   r)   r)   r*   unary_unary     zChannel.unary_unaryc                 C   r   r%   )re   r8   r   rz   rp   r7   r   r)   r)   r*   unary_stream  r   zChannel.unary_streamc                 C   r   r%   )rg   r8   r   rz   rq   r7   r   r)   r)   r*   stream_unary  r   zChannel.stream_unaryc                 C   r   r%   )rm   r8   r   rz   rr   r7   r   r)   r)   r*   stream_stream  r   zChannel.stream_streamr%   )F)r$   NrJ   )+rK   rL   rM   r&   rO   rP   r
   rQ   r   r   r   r   r   r   r   r   rT   ChannelCredentialsrU   r   r   rF   r}   r   r   ra   r   r   rc   r   r   r   r   r!   r   rW   r   re   r   rg   r   rm   r   r)   r)   r)   r*   rn   9  s   
 



3H


	


rn   rs   rt   rB   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.
      interceptors: An optional sequence of interceptors that will be executed for
        any call executed with this channel.

    Returns:
      A Channel.
    Nr)   )rn   )rs   rt   r-   rB   r)   r)   r*   insecure_channel  s   r   rZ   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.
      interceptors: An optional sequence of interceptors that will be executed for
        any call executed with this channel.

    Returns:
      An aio.Channel.
    Nr)   )rn   _credentials)rs   rZ   rt   r-   rB   r)   r)   r*   secure_channel<  s   r   )NNN)>rN   r&   systypingr   r   r   r   r   rT   r   r   r	   grpc._cythonr
    r   r   _callr   r   r   r   _interceptorr   r   r   r   r   r   r   r   r   	_metadatar   _typingr   r   r   r   r    r!   _utilsr"   rx   __version__r1   version_infor'   r+   rU   r5   r6   rW   re   rg   rm   rn   r   r   r   r   r)   r)   r)   r*   <module>   s   

2
-
.
-- i

 
