U
    ËZjSV  ã                   @   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 �rºe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+   úT/var/www/html/TRUCKING_PROJECT/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 )z—Based 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 |s€q*|d }|j d¡}	|	d k	r*t	|	t
jƒr*t|	dƒrÂ|	j | j k	rîq*n,t|	dƒrÞ|	jj | j k	rîq*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
 ÿ-
 ÿ.
 ÿ-
 ÿ-     ü
ü    û
û