o
    ˷eM                     @   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 rd eej. fd!d"Z/n
d eej. fd#d"Z/d$e$d%ee	j0 f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 d0d1 d1e2ej6Z6G d2d3 d3ej7Z7			d<d4e8d5ee$ d%ee	j0 d6eee  fd7d8Z9			d<d4e8d9e	j:d5ee$ d%ee	j0 d6e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)SerializingFunction)_timeout_to_deadlinezgrpc-python-asyncio/{}   returnc                   C   s
   t j S N)asyncioTask	all_tasks r'   r'   H/var/www/ideatree/venv/lib/python3.10/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   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   r3   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jed< dejd	e	d
e
dede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channelmethodrequest_serializerresponse_deserializerinterceptorsloopr"   Nc                 C   s(   || _ || _|| _|| _|| _|| _d S r#   )r5   r6   r7   r8   r9   r:   )selfr;   r<   r=   r>   r?   r@   r'   r'   r(   __init__V   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)rC   r+   r'   r'   r(   _init_metadataf   s   

z!_BaseMultiCallable._init_metadataNN)__name__
__module____qualname____doc__r$   AbstractEventLoop__annotations__r
   
AioChannelbytesr   r   r   r   r   rB   staticmethodr   grpcCompressionrE   r'   r'   r'   r(   r4   H   sD   
 




r4   c                   @   Z   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fd
dZdS )UnaryUnaryMultiCallableNtimeoutrC   credentialswait_for_readyr+   requestrU   rC   rV   rW   r+   r"   c                C   sj   |  ||}| jst|t||||| j| j| j| j| j
}|S t	| j|||||| j| j| j| j| j}|S r#   )
rE   r:   r   r    r6   r7   r8   r9   r5   r   )rA   rX   rU   rC   rV   rW   r+   callr'   r'   r(   __call__w   s    

z UnaryUnaryMultiCallable.__call__)rG   rH   rI   r   r   floatr   rP   CallCredentialsboolrQ   r   r   rZ   r'   r'   r'   r(   rS   t   *    	rS   c                   @   rR   )UnaryStreamMultiCallableNrT   rX   rU   rC   rV   rW   r+   r"   c          	      C   n   |  ||}t|}| js!t|||||| j| j| j| j| j
}|S t	| j|||||| j| j| j| j| j}|S r#   )
rE   r    r:   r   r6   r7   r8   r9   r5   r   )	rA   rX   rU   rC   rV   rW   r+   deadlinerY   r'   r'   r(   rZ      s    


z!UnaryStreamMultiCallable.__call__)rG   rH   rI   r   r   r[   r   rP   r\   r]   rQ   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_iteratorrU   rC   rV   rW   r+   r"   c           	      C   r`   r#   )
rE   r    r:   r   r6   r7   r8   r9   r5   r   	rA   rd   rU   rC   rV   rW   r+   ra   rY   r'   r'   r(   rZ          

z!StreamUnaryMultiCallable.__call__NNNNNN)rG   rH   rI   r   r   r[   r   rP   r\   r]   rQ   r   r   rZ   r'   r'   r'   r(   rc      ,    rc   c                   @   rb   )StreamStreamMultiCallableNrd   rU   rC   rV   rW   r+   r"   c           	      C   r`   r#   )
rE   r    r:   r   r6   r7   r8   r9   r5   r   re   r'   r'   r(   rZ      rf   z"StreamStreamMultiCallable.__call__rg   )rG   rH   rI   r   r   r[   r   rP   r\   r]   rQ   r   r   rZ   r'   r'   r'   r(   ri      rh   ri   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edejfddZdejddfddZd/d d!Z		d0d"ed#ee  d$ee! de"fd%d&Z#		d0d"ed#ee  d$ee! de$fd'd(Z%		d0d"ed#ee  d$ee! de&fd)d*Z'		d0d"ed#ee  d$ee! de(fd+d,Z)dS )1Channelr5   r6   _unary_unary_interceptors_unary_stream_interceptors_stream_unary_interceptors_stream_stream_interceptorstargetoptionsrV   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{}. )rk   rl   rm   rn   
isinstancer   appendr   r   r   
ValueErrorformatrG   r
   get_working_loopr5   rM   r   encoder3   r6   )rA   ro   rp   rV   r+   r?   interceptorr'   r'   r(   rB      s>   










zChannel.__init__c                    s   | S r#   r'   )rA   r'   r'   r(   
__aenter__%  s   zChannel.__aenter__c                    s   |  d I d H  d S r#   _close)rA   exc_typeexc_valexc_tbr'   r'   r(   	__aexit__(     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   rA   r6   _cython_callzUnrecognized call object: )rU   )r6   closedclosingr)   	get_stackAttributeErrorstrf_localsgetrq   r   Callhasattrr   r
   InternalErrorrr   r$   waitcancelclose)rA   gracetaskscalls
call_taskstaskstackattribute_errorr   	candidaterY   r'   r'   r(   rz   +  sR   






zChannel._closeNr   c                    s   |  |I d H  d S r#   ry   )rA   r   r'   r'   r(   r   r  r   zChannel.closeFtry_to_connectr"   c                 C   s   | j |}tj| S r#   )r6   check_connectivity_stater   1CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY)rA   r   resultr'   r'   r(   	get_stateu  s   
zChannel.get_statelast_observed_statec                    s$   | j |jd d I d H sJ d S )Nr   )r6   watch_connectivity_statevalue)rA   r   r'   r'   r(   wait_for_state_changez  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   rP   ChannelConnectivityREADYr   )rA   stater'   r'   r(   channel_ready  s   zChannel.channel_readyr<   r=   r>   c                 C      t | jt|||| j| jS r#   )rS   r6   r   rv   rk   r5   rA   r<   r=   r>   r'   r'   r(   unary_unary     zChannel.unary_unaryc                 C   r   r#   )r_   r6   r   rv   rl   r5   r   r'   r'   r(   unary_stream  r   zChannel.unary_streamc                 C   r   r#   )rc   r6   r   rv   rm   r5   r   r'   r'   r(   stream_unary  r   zChannel.stream_unaryc                 C   r   r#   )ri   r6   r   rv   rn   r5   r   r'   r'   r(   stream_stream  r   zChannel.stream_streamr#   )F)r"   NrF   )*rG   rH   rI   r$   rK   rL   r
   rM   r   r   r   r   r   r   r   r   rP   ChannelCredentialsrQ   r   r   rB   rx   r~   rz   r[   r   r]   r   r   r   r   r   r   rS   r   r_   r   rc   r   ri   r   r'   r'   r'   r(   rj      s   
 




,G


	


rj   ro   rp   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'   )rj   )ro   rp   r+   r?   r'   r'   r(   insecure_channel  s   r   rV   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'   )rj   _credentials)ro   rV   rp   r+   r?   r'   r'   r(   secure_channel  s   r   )NNN)<rJ   r$   systypingr   r   r   r   r   rP   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   _utilsr    rt   __version__r/   version_infor%   r)   rQ   r3   r4   rS   r_   rc   ri   rj   r   r   r   r   r'   r'   r'   r(   <module>   s   
,  J


