o
    7?eja                     @   s  d Z ddlZddlZddlZddlmZ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 G d
d deZdeeej  dee fddZG dd deddejZdejdejde	eeeejeejf fddZG dd dejej ej!Z"G dd dej!ej Z#G dd dej$Z%G dd dej&Z'G dd  d ej(Z)G d!d" d"ej*Z+G d#d$ d$ej,Z-d%ej,deee
ej.ej/ej0ej1f   dej,fd&d'Z2dS )(z+Implementation of gRPC Python interceptors.    N)AnyCallableOptionalSequenceTupleUnion   )DeserializingFunction)DoneCallbackType)MetadataType)RequestIterableType)SerializingFunctionc                   @   s~   e Zd ZU eej ed< deej fddZde	de
de	fddZde	de
d	ejdejfd
dZde	d	ejdejfddZdS )_ServicePipelineinterceptorsc                 C   s   t || _d S N)tupler   )selfr    r   R/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/grpc/_interceptor.py__init__!      z_ServicePipeline.__init__thunkindexreturnc                    s    fddS )Nc                    s     | S r   _intercept_at)contextr   r   r   r   r   <lambda>%   s    z0_ServicePipeline._continuation.<locals>.<lambda>r   )r   r   r   r   r   r   _continuation$      z_ServicePipeline._continuationr   c                 C   s<   |t | jk r| j| }| ||d }|||S ||S )Nr   )lenr   r   Zintercept_service)r   r   r   r   interceptorr   r   r   r   '   s
   
z_ServicePipeline._intercept_atc                 C   s   |  |d|S )Nr   r   )r   r   r   r   r   r   execute1   s   z_ServicePipeline.executeN)__name__
__module____qualname__r   grpcServerInterceptor__annotations__r   r   r   intr   ZHandlerCallDetailsZRpcMethodHandlerr   r#   r   r   r   r   r      s(   
 

r   r   r   c                 C   s   | rt | S d S r   )r   )r   r   r   r   service_pipeline7   s   r+   c                   @   s   e Zd ZdS )_ClientCallDetailsN)r$   r%   r&   r   r   r   r   r,   =   s    r,   )methodtimeoutmetadatacredentialswait_for_readycompressioncall_detailsdefault_detailsc                 C   s   z| j }W n ty   |j }Y nw z| j}W n ty#   |j}Y nw z| j}W n ty5   |j}Y nw z| j}W n tyG   |j}Y nw z| j}W n tyY   |j}Y nw z| j}W n tyk   |j}Y nw ||||||fS r   )r-   AttributeErrorr.   r/   r0   r1   r2   )r3   r4   r-   r.   r/   r0   r1   r2   r   r   r   _unwrap_client_call_detailsN   sJ   





r6   c                       sh  e Zd ZU eed< ejed< dedejf fddZdee	 fdd	Z
dee	 fd
dZdeej fddZdee fddZdefddZdefddZdefddZdee fddZdefddZdefddZd/dee fddZ	d/dee dee fd d!Z	d/dee deej fd"d#Zdefd$d%Zd&eddfd'd(Zd)d* Zd+d, Z d-d. Z!  Z"S )0_FailureOutcome
_exception
_traceback	exception	tracebackc                    s   t t|   || _|| _d S r   )superr7   r   r8   r9   )r   r:   r;   	__class__r   r   r      s   
z_FailureOutcome.__init__r   c                 C      d S r   r   r   r   r   r   initial_metadata      z _FailureOutcome.initial_metadatac                 C   r?   r   r   r@   r   r   r   trailing_metadata   rB   z!_FailureOutcome.trailing_metadatac                 C   s   t jjS r   )r'   
StatusCodeZINTERNALr@   r   r   r   code      z_FailureOutcome.codec                 C      dS )Nz+Exception raised while intercepting the RPCr   r@   r   r   r   details   rB   z_FailureOutcome.detailsc                 C   rG   NFr   r@   r   r   r   cancel   rB   z_FailureOutcome.cancelc                 C   rG   rI   r   r@   r   r   r   	cancelled   rB   z_FailureOutcome.cancelledc                 C   rG   rI   r   r@   r   r   r   	is_active   rB   z_FailureOutcome.is_activec                 C   r?   r   r   r@   r   r   r   time_remaining   rB   z_FailureOutcome.time_remainingc                 C   rG   rI   r   r@   r   r   r   running   rB   z_FailureOutcome.runningc                 C   rG   NTr   r@   r   r   r   done   rB   z_FailureOutcome.doneNignored_timeoutc                 C      | j r   r8   r   rQ   r   r   r   result      z_FailureOutcome.resultc                 C      | j S r   rS   rT   r   r   r   r:         z_FailureOutcome.exceptionc                 C   rW   r   )r9   rT   r   r   r   r;      rX   z_FailureOutcome.tracebackc                 C   rG   rI   r   )r   Zunused_callbackr   r   r   add_callback   rB   z_FailureOutcome.add_callbackfnc                 C      ||  d S r   r   r   rZ   r   r   r   add_done_callback      z!_FailureOutcome.add_done_callbackc                 C      | S r   r   r@   r   r   r   __iter__   rB   z_FailureOutcome.__iter__c                 C   rR   r   rS   r@   r   r   r   __next__   rV   z_FailureOutcome.__next__c                 C   s   |   S r   )ra   r@   r   r   r   next   rF   z_FailureOutcome.nextr   )#r$   r%   r&   	Exceptionr)   typesTracebackTyper   r   r   rA   rC   r'   rD   rE   strrH   boolrJ   rK   rL   floatrM   rN   rP   rU   r:   r;   rY   r
   r]   r`   ra   rb   __classcell__r   r   r=   r   r7      s@   
 


r7   c                   @   s2  e Zd ZU eed< ejed< dedejfddZdee	 fdd	Z
dee	 fd
dZdeej fddZdee fddZdefddZdee fddZdefddZdefddZdefddZdefddZdefddZd)dee fd d!Zd)dee fd"d#Zd)dee fd$d%Zd&eddfd'd(ZdS )*_UnaryOutcome	_response_callresponsecallc                 C      || _ || _d S r   )rk   rl   )r   rm   rn   r   r   r   r      s   
z_UnaryOutcome.__init__r   c                 C   
   | j  S r   )rl   rA   r@   r   r   r   rA         
z_UnaryOutcome.initial_metadatac                 C   rp   r   )rl   rC   r@   r   r   r   rC      rq   z_UnaryOutcome.trailing_metadatac                 C   rp   r   )rl   rE   r@   r   r   r   rE      rq   z_UnaryOutcome.codec                 C   rp   r   )rl   rH   r@   r   r   r   rH      rq   z_UnaryOutcome.detailsc                 C   rp   r   )rl   rL   r@   r   r   r   rL      rq   z_UnaryOutcome.is_activec                 C   rp   r   )rl   rM   r@   r   r   r   rM      rq   z_UnaryOutcome.time_remainingc                 C   rp   r   )rl   rJ   r@   r   r   r   rJ      rq   z_UnaryOutcome.cancelc                 C   s   | j |S r   )rl   rY   r   callbackr   r   r   rY      r^   z_UnaryOutcome.add_callbackc                 C   rG   rI   r   r@   r   r   r   rK      rB   z_UnaryOutcome.cancelledc                 C   rG   rI   r   r@   r   r   r   rN      rB   z_UnaryOutcome.runningc                 C   rG   rO   r   r@   r   r   r   rP      rB   z_UnaryOutcome.doneNrQ   c                 C   rW   r   )rk   rT   r   r   r   rU      rV   z_UnaryOutcome.resultc                 C   r?   r   r   rT   r   r   r   r:      rB   z_UnaryOutcome.exceptionc                 C   r?   r   r   rT   r   r   r   r;      rB   z_UnaryOutcome.tracebackrZ   c                 C   r[   r   r   r\   r   r   r   r]      r^   z_UnaryOutcome.add_done_callbackr   )r$   r%   r&   r   r)   r'   Callr   r   r   rA   rC   rD   rE   rf   rH   rg   rL   rh   rM   rJ   rY   rK   rN   rP   rU   r:   r;   r
   r]   r   r   r   r   rj      s&   
 
rj   c                   @   s|  e Zd ZU eed< eed< ejed< dededejfddZ										dd
e	de
e de
e de
ej de
e de
ej de	fddZ										dd
e	de
e de
e de
ej de
e de
ej dee	ejf fddZ										dd
e	de
e de
e de
ej de
e de
ej dee	ejf fddZ										dd
e	de
e de
e de
ej de
e de
ej de	fddZd	S )_UnaryUnaryMultiCallable_thunk_method_interceptorr   r-   r"   c                 C      || _ || _|| _d S r   rv   rw   rx   r   r   r-   r"   r   r   r   r        
z!_UnaryUnaryMultiCallable.__init__Nrequestr.   r/   r0   r1   r2   r   c           	      C      | j ||||||d\}}|S Nr.   r/   r0   r1   r2   
_with_call)	r   r}   r.   r/   r0   r1   r2   rm   ignored_callr   r   r   __call__     	
z!_UnaryUnaryMultiCallable.__call__c           	         >   t j|||||  fdd}j| |}| |fS )Nc              
         t |  \}}}}}}z|j||||||d\}}	t||	W S  tjy6 }
 z|
W  Y d }
~
S d }
~
w tyP } zt|t	 d W  Y d }~S d }~ww Nr      
r6   rv   	with_callrj   r'   RpcErrorrc   r7   sysexc_info)new_detailsr}   
new_methodnew_timeoutnew_metadatanew_credentialsnew_wait_for_readynew_compressionrm   rn   	rpc_errorr:   Zclient_call_detailsr   r   r   continuation1  2   

z9_UnaryUnaryMultiCallable._with_call.<locals>.continuation)r,   rw   rx   intercept_unary_unaryrU   )	r   r}   r.   r/   r0   r1   r2   r   rn   r   r   r   r        		z#_UnaryUnaryMultiCallable._with_callc                 C      | j ||||||dS r   r   )r   r}   r.   r/   r0   r1   r2   r   r   r   r   N     	z"_UnaryUnaryMultiCallable.with_callc           	   
      l   t j|||||  fdd}z	j| |W S  ty5 } zt|t d W  Y d }~S d }~ww )Nc                    2   t |  \}}}}}}|j||||||dS r   r6   rv   futurer   r}   r   r   r   r   r   r   r   r   r   r   r      
z5_UnaryUnaryMultiCallable.future.<locals>.continuationr   )r,   rw   rx   r   rc   r7   r   r   	r   r}   r.   r/   r0   r1   r2   r   r:   r   r   r   r   `  "   		z_UnaryUnaryMultiCallable.futureNNNNN)r$   r%   r&   r   r)   rf   r'   UnaryUnaryClientInterceptorr   r   r   rh   r   CallCredentialsrg   Compressionr   r   rt   r   r   r   r   r   r   r   ru         
 



2
ru   c                   @      e Zd ZU eed< eed< ejed< dededejfddZ										dd
e	de
e de
e de
ej de
e de
ej fddZd	S )_UnaryStreamMultiCallablerv   rw   rx   r   r-   r"   c                 C   ry   r   rz   r{   r   r   r   r     r|   z"_UnaryStreamMultiCallable.__init__Nr}   r.   r/   r0   r1   r2   c           	   
      r   )Nc                    0   t |  \}}}}}}|||||||dS r   r6   rv   r   r   r   r   r         z8_UnaryStreamMultiCallable.__call__.<locals>.continuationr   )r,   rw   rx   Zintercept_unary_streamrc   r7   r   r   r   r   r   r   r     r   z"_UnaryStreamMultiCallable.__call__r   )r$   r%   r&   r   r)   rf   r'   UnaryStreamClientInterceptorr   r   r   rh   r   r   rg   r   r   r   r   r   r   r     :   
 

r   c                   @   s|  e Zd ZU eed< eed< ejed< dededejfddZ										dd
e	de
e de
e de
ej de
e de
ej defddZ										dd
e	de
e de
e de
ej de
e de
ej deeejf fddZ										dd
e	de
e de
e de
ej de
e de
ej deeejf fddZ										dd
e	de
e de
e de
ej de
e de
ej defddZd	S )_StreamUnaryMultiCallablerv   rw   rx   r   r-   r"   c                 C   ry   r   rz   r{   r   r   r   r     r|   z"_StreamUnaryMultiCallable.__init__Nrequest_iteratorr.   r/   r0   r1   r2   r   c           	      C   r~   r   r   )	r   r   r.   r/   r0   r1   r2   rm   r   r   r   r   r     r   z"_StreamUnaryMultiCallable.__call__c           	         r   )Nc              
      r   r   r   )r   r   r   r   r   r   r   r   rm   rn   r   r:   r   r   r   r     r   z:_StreamUnaryMultiCallable._with_call.<locals>.continuation)r,   rw   rx   intercept_stream_unaryrU   )	r   r   r.   r/   r0   r1   r2   r   rn   r   r   r   r     r   z$_StreamUnaryMultiCallable._with_callc                 C   r   r   r   )r   r   r.   r/   r0   r1   r2   r   r   r   r     r   z#_StreamUnaryMultiCallable.with_callc           	   
      r   )Nc                    r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <  r   z6_StreamUnaryMultiCallable.future.<locals>.continuationr   )r,   rw   rx   r   rc   r7   r   r   	r   r   r.   r/   r0   r1   r2   r   r:   r   r   r   r   *  r   z _StreamUnaryMultiCallable.futurer   )r$   r%   r&   r   r)   rf   r'   StreamUnaryClientInterceptorr   r   r   rh   r   r   rg   r   r   r   r   rt   r   r   r   r   r   r   r   r     r   r   c                   @   r   )_StreamStreamMultiCallablerv   rw   rx   r   r-   r"   c                 C   ry   r   rz   r{   r   r   r   r   [  r|   z#_StreamStreamMultiCallable.__init__Nr   r.   r/   r0   r1   r2   c           	   
      r   )Nc                    r   r   r   r   r   r   r   r   w  r   z9_StreamStreamMultiCallable.__call__.<locals>.continuationr   )r,   rw   rx   Zintercept_stream_streamrc   r7   r   r   r   r   r   r   r   e  r   z#_StreamStreamMultiCallable.__call__r   )r$   r%   r&   r   r)   rf   r'   StreamStreamClientInterceptorr   r   r   rh   r   r   rg   r   r   r   r   r   r   r   V  r   r   c                	   @   sL  e Zd ZU ejed< eejejej	ej
f ed< dejdeejejej	ej
f fddZ	d#ded	ee fd
dZdefddZ		d$dedee dee dejfddZ		d$dedee dee dejfddZ		d$dedee dee dejfddZ		d$dedee dee dejfddZdd Zdd Zdd  Zd!d" ZdS )%_Channel_channelrx   channelr"   c                 C   ro   r   )r   rx   )r   r   r"   r   r   r   r     s   

z_Channel.__init__Frs   try_to_connectc                 C   s   | j j||d d S )N)r   )r   	subscribe)r   rs   r   r   r   r   r     s   z_Channel.subscribec                 C   s   | j | d S r   )r   unsubscriberr   r   r   r   r     r    z_Channel.unsubscribeNr-   request_serializerresponse_deserializerr   c                    4    fdd}t jtjrt||jS ||S )Nc                       j |  S r   )r   unary_unarymr   r   r   r   r   r         z&_Channel.unary_unary.<locals>.<lambda>)
isinstancerx   r'   r   ru   r   r-   r   r   r   r   r   r   r        z_Channel.unary_unaryc                    r   )Nc                    r   r   )r   unary_streamr   r   r   r   r     r   z'_Channel.unary_stream.<locals>.<lambda>)r   rx   r'   r   r   r   r   r   r   r     r   z_Channel.unary_streamc                    r   )Nc                    r   r   )r   stream_unaryr   r   r   r   r     r   z'_Channel.stream_unary.<locals>.<lambda>)r   rx   r'   r   r   r   r   r   r   r     r   z_Channel.stream_unaryc                    r   )Nc                    r   r   )r   stream_streamr   r   r   r   r     r   z(_Channel.stream_stream.<locals>.<lambda>)r   rx   r'   r   r   r   r   r   r   r     r   z_Channel.stream_streamc                 C      | j   d S r   r   closer@   r   r   r   _close  r   z_Channel._closec                 C   r_   r   r   r@   r   r   r   	__enter__  rB   z_Channel.__enter__c                 C   s   |    dS rI   )r   )r   exc_typeexc_valexc_tbr   r   r   __exit__  s   z_Channel.__exit__c                 C   r   r   r   r@   r   r   r   r     r   z_Channel.close)F)NN) r$   r%   r&   r'   Channelr)   r   r   r   r   r   r   r   r   rg   r   r   rf   r   r	   UnaryUnaryMultiCallabler   UnaryStreamMultiCallabler   StreamUnaryMultiCallabler   StreamStreamMultiCallabler   r   r   r   r   r   r   r   r   r     s   
 






r   r   c                 G   sX   t t|D ]#}t|tjs$t|tjs$t|tjs$t|tjs$tdt	| |} q| S )Nzinterceptor must be grpc.UnaryUnaryClientInterceptor or grpc.UnaryStreamClientInterceptor or grpc.StreamUnaryClientInterceptor or grpc.StreamStreamClientInterceptor or )
reversedlistr   r'   r   r   r   r   	TypeErrorr   )r   r   r"   r   r   r   intercept_channel  s   



r   )3__doc__collectionsr   rd   typingr   r   r   r   r   r   r'   Z_typingr	   r
   r   r   r   objectr   r(   r+   
namedtupleZClientCallDetailsr,   rf   rh   r   rg   r   r6   r   Futurert   r7   rj   r   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sz    



3F6 ; ;d