o
    aeS                     @   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)   AD:\Projects\ConvertPro\env\Lib\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   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   r0   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%   )r2   r3   r4   r5   r6   r7   r8   )selfr9   r:   r;   r<   r=   r>   r?   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   Zaugment_metadata)rB   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   rA   staticmethodr   grpcCompressionrC   r)   r)   r)   r*   r1   R   sJ   
 



	
r1   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timeoutrB   credentialswait_for_readyr-   requestrS   rB   rT   rU   r-   r$   c                C   j   |  ||}| jst|t||||| j| j| j| j| j
}|S t	| j|||||| j| j| j| j| j}|S r%   )
rC   r7   r   r"   r3   r4   r5   r6   r2   r   r@   rV   rS   rB   rT   rU   r-   callr)   r)   r*   __call__   s:   
z UnaryUnaryMultiCallable.__call__)rE   rF   rG   r   r   floatr   rN   CallCredentialsboolrO   r   r   r    rZ   r)   r)   r)   r*   rQ      *    	rQ   c                   @   rP   )UnaryStreamMultiCallableNrR   rV   rS   rB   rT   rU   r-   r$   c                C   rW   r%   )
rC   r7   r   r"   r3   r4   r5   r6   r2   r   rX   r)   r)   r*   rZ      s:   
z!UnaryStreamMultiCallable.__call__)rE   rF   rG   r   r   r[   r   rN   r\   r]   rO   r   r   r    rZ   r)   r)   r)   r*   r_      r^   r_   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_iteratorrS   rB   rT   rU   r-   r$   c                 C   rW   r%   )
rC   r7   r   r"   r3   r4   r5   r6   r2   r   r@   rb   rS   rB   rT   rU   r-   rY   r)   r)   r*   rZ      :   	z!StreamUnaryMultiCallable.__call__NNNNNN)rE   rF   rG   r   r   r[   r   rN   r\   r]   rO   r   r   rZ   r)   r)   r)   r*   ra      ,    ra   c                   @   r`   )StreamStreamMultiCallableNrb   rS   rB   rT   rU   r-   r$   c                 C   rW   r%   )
rC   r7   r   r"   r3   r4   r5   r6   r2   r   rc   r)   r)   r*   rZ     rd   z"StreamStreamMultiCallable.__call__re   )rE   rF   rG   r   r   r[   r   rN   r\   r]   rO   r   r   rZ   r)   r)   r)   r*   rg     rf   rg   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Channelr2   r3   _unary_unary_interceptors_unary_stream_interceptors_stream_unary_interceptors_stream_stream_interceptorstargetoptionsrT   r-   r=   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{}. )ri   rj   rk   rl   
isinstancer   appendr   r   r   
ValueErrorformatrE   r
   Zget_working_loopr2   rK   r   encoder0   r3   )r@   rm   rn   rT   r-   r=   Zinterceptorr)   r)   r*   rA   A  s@   









zChannel.__init__c                    s   | S r%   r)   r@   r)   r)   r*   
__aenter__t  s   zChannel.__aenter__c                    s   |  d I d H  d S r%   _close)r@   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   r@   r3   _cython_callzUnrecognized call object: )rS   )r3   closedclosingr+   	get_stackAttributeErrorstrf_localsgetro   r   Callhasattrr   r
   ZInternalErrorrp   r&   waitcancelclose)r@   gracetasksZcallsZ
call_taskstaskstackZattribute_errorr~   	candidaterY   r)   r)   r*   rw   z  sR   






zChannel._closeNr   c                    s   |  |I d H  d S r%   rv   )r@   r   r)   r)   r*   r     r|   zChannel.closec                 C   s*   t | dr| j s| j  d S d S d S )Nr3   )r   r3   r   r   rt   r)   r)   r*   __del__  s
   

zChannel.__del__Ftry_to_connectr$   c                 C   s   | j |}tj| S r%   )r3   Zcheck_connectivity_stater   Z1CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY)r@   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   )r3   Zwatch_connectivity_statevalue)r@   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   rN   ChannelConnectivityZREADYr   )r@   stater)   r)   r*   channel_ready  s   zChannel.channel_readyr:   r;   r<   c                 C   "   t | jt|||| j| g| jS r%   )rQ   r3   r   rs   ri   r2   r@   r:   r;   r<   r)   r)   r*   unary_unary     zChannel.unary_unaryc                 C   r   r%   )r_   r3   r   rs   rj   r2   r   r)   r)   r*   unary_stream  r   zChannel.unary_streamc                 C   r   r%   )ra   r3   r   rs   rk   r2   r   r)   r)   r*   stream_unary  r   zChannel.stream_unaryc                 C   r   r%   )rg   r3   r   rs   rl   r2   r   r)   r)   r*   stream_stream  r   zChannel.stream_streamr%   )F)r$   NrD   )+rE   rF   rG   r&   rI   rJ   r
   rK   r   r   r   r   r   r   r   r   rN   ChannelCredentialsrO   r   r   rA   ru   r{   rw   r[   r   r   r]   r   r   r   r   r!   r   rQ   r   r_   r   ra   r   rg   r   r)   r)   r)   r*   rh   9  s   
 



3H


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

    Returns:
      A Channel.
    Nr)   )rh   )rm   rn   r-   r=   r)   r)   r*   insecure_channel  s   r   rT   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)   )rh   Z_credentials)rm   rT   rn   r-   r=   r)   r)   r*   secure_channel<  s   r   )NNN)>rH   r&   systypingr   r   r   r   r   rN   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   r    r!   _utilsr"   rr   __version__r.   version_infor'   r+   rO   r0   r1   rQ   r_   ra   rg   rh   r   r   r   r   r)   r)   r)   r*   <module>   s   

2
-
.
-- i

 
