a
    
dP                     @   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 reej0 d"d#d$Z1neej0 d"d%d$Z1e$ee	j2 d&d'd(Z3G d)d* d*Z4G d+d, d,e4ej5Z5G d-d. d.e4ej6Z6G d/d0 d0e4ej7Z7G d1d2 d2e4ej8Z8G d3d4 d4ej9Z9d;e:ee$ ee	j2 eee  d5d6d7Z;d<e:e	j<ee$ ee	j2 eee  d8d9d: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*   Z/var/www/html/stable-diffusion-webui/venv/lib/python3.9/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    r1   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&   )r3   r4   r5   r6   r7   r8   r9   )selfr:   r;   r<   r=   r>   r?   r@   r*   r*   r+   __init__b   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)rC   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   rB   staticmethodr   grpcCompressionrD   r*   r*   r*   r+   r2   R   s4   




  r2   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timeoutrC   credentialswait_for_readyr.   requestrR   rC   rS   rT   r.   r%   c                C   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r&   )
rD   r8   r   r"   r4   r5   r6   r7   r3   r   rA   rV   rR   rC   rS   rT   r.   callr*   r*   r+   __call__   s8    
z UnaryUnaryMultiCallable.__call__)rE   rF   rG   r   r   floatr   rN   CallCredentialsboolrO   r   r   r    rY   r*   r*   r*   r+   rP      s   rP   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 )UnaryStreamMultiCallableNrQ   rU   c                C   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r&   )
rD   r8   r   r"   r4   r5   r6   r7   r3   r   rW   r*   r*   r+   rY      s8    
z!UnaryStreamMultiCallable.__call__)rE   rF   rG   r   r   rZ   r   rN   r[   r\   rO   r   r   r    rY   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_iteratorrR   rC   rS   rT   r.   r%   c                 C   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r&   )
rD   r8   r   r"   r4   r5   r6   r7   r3   r   rA   r`   rR   rC   rS   rT   r.   rX   r*   r*   r+   rY      s8    	z!StreamUnaryMultiCallable.__call__)NNNNNN)rE   rF   rG   r   r   rZ   r   rN   r[   r\   rO   r   r   rY   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   sh   |  ||}| js<t|t||||| j| j| j| j| j
}n(t	| j|||||| j| j| j| j| j}|S r&   )
rD   r8   r   r"   r4   r5   r6   r7   r3   r   ra   r*   r*   r+   rY     s8    	z"StreamStreamMultiCallable.__call__)NNNNNN)rE   rF   rG   r   r   rZ   r   rN   r[   r\   rO   r   r   rY   r*   r*   r*   r+   rb     s         rb   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 )/Channelr3   r4   _unary_unary_interceptors_unary_stream_interceptors_stream_unary_interceptors_stream_stream_interceptors)targetoptionsrS   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{}. )rd   re   rf   rg   
isinstancer   appendr   r   r   
ValueErrorformatrE   r
   Zget_working_loopr3   rK   r   encoder1   r4   )rA   rh   ri   rS   r.   r>   Zinterceptorr*   r*   r+   rB   A  s@    








zChannel.__init__c                    s   | S r&   r*   rA   r*   r*   r+   
__aenter__t  s    zChannel.__aenter__c                    s   |  d I d H  d S r&   _close)rA   exc_typeexc_valexc_tbr*   r*   r+   	__aexit__w  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   rA   r4   _cython_callzUnrecognized call object: )rR   )r4   closedclosingr,   Z	get_stackAttributeErrorstrf_localsgetrj   r   Callhasattrry   r
   ZInternalErrorrk   r'   waitcancelclose)rA   graceZtasksZcallsZ
call_tasksZtaskstackZattribute_errorrx   	candidaterX   r*   r*   r+   rr   z  sF    




zChannel._closeN)r   c                    s   |  |I d H  d S r&   rq   )rA   r   r*   r*   r+   r     s    zChannel.closec                 C   s"   t | dr| j s| j  d S )Nr4   )r   r4   rz   r   ro   r*   r*   r+   __del__  s    

zChannel.__del__F)try_to_connectr%   c                 C   s   | j |}tj| S r&   )r4   Zcheck_connectivity_stater   Z1CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY)rA   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   )r4   Zwatch_connectivity_statevalue)rA   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   rN   ChannelConnectivityZREADYr   )rA   stater*   r*   r+   channel_ready  s    zChannel.channel_ready)r;   r<   r=   r%   c                 C   s"   t | jt|||| j| g| jS r&   )rP   r4   r   rn   rd   r3   rA   r;   r<   r=   r*   r*   r+   unary_unary  s    zChannel.unary_unaryc                 C   s"   t | jt|||| j| g| jS r&   )r]   r4   r   rn   re   r3   r   r*   r*   r+   unary_stream  s    zChannel.unary_streamc                 C   s"   t | jt|||| j| g| jS r&   )r^   r4   r   rn   rf   r3   r   r*   r*   r+   stream_unary  s    zChannel.stream_unaryc                 C   s"   t | jt|||| j| g| jS r&   )rb   r4   r   rn   rg   r3   r   r*   r*   r+   stream_stream  s    zChannel.stream_stream)N)F)NN)NN)NN)NN)+rE   rF   rG   r'   rI   rJ   r
   rK   r   r   r   r   r   r}   r   r   rN   ChannelCredentialsrO   r   r   rB   rp   rv   rr   rZ   r   r   r\   r   r   r   r   r!   r   rP   r   r]   r   r^   r   rb   r   r*   r*   r*   r+   rc   9  st   



3H 	        rc   rh   ri   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.
      interceptors: An optional sequence of interceptors that will be executed for
        any call executed with this channel.

    Returns:
      A Channel.
    Nr*   )rc   r   r*   r*   r+   insecure_channel  s    r   rh   rS   ri   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.
      interceptors: An optional sequence of interceptors that will be executed for
        any call executed with this channel.

    Returns:
      An aio.Channel.
    Nr*   )rc   Z_credentialsr   r*   r*   r+   secure_channel<  s    r   )NNN)NNN)>rH   r'   systypingr   r   r   r   r   rN   r   r   r	   Zgrpc._cythonr
    r   r   Z_callr   r   r   r   Z_interceptorr   r   r   r   r   r   r   r   r   	_metadatar   _typingr   r   r   r   r    r!   _utilsr"   rm   __version__r/   version_infor(   r,   rO   r1   r2   rP   r]   r^   rb   rc   r}   r   r   r   r*   r*   r*   r+   <module>   s   
2
-
.
-
- i   
    
