
    Age                        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e      Zdeeej(                        dee   fdZ G d d ej,                  dd      ej.                        Zdej.                  dej.                  de	eeeej6                  eej:                  f   fdZ G d dej>                  ej@                  ejB                        Z" G d dejB                  ej@                        Z# G d dejH                        Z% G d dejL                        Z' G d dejP                        Z) G d d ejT                        Z+ G d! d"ejX                        Z-d#ejX                  deee
ej\                  ej^                  ej`                  ejb                  f         dejX                  fd$Z2y)%z+Implementation of gRPC Python interceptors.    N)AnyCallableOptionalSequenceTupleUnion   )DeserializingFunction)DoneCallbackType)MetadataType)RequestIterableType)SerializingFunctionc                       e Zd ZU eej
                     ed<   deej
                     fdZde	de
de	fdZde	de
dej                  dej                  fdZde	dej                  dej                  fd	Zy
)_ServicePipelineinterceptorsc                 $    t        |      | _        y N)tupler   )selfr   s     F/var/www/openai/venv/lib/python3.12/site-packages/grpc/_interceptor.py__init__z_ServicePipeline.__init__!   s    !,/    thunkindexreturnc                       fdS )Nc                 *    j                  |       S r   _intercept_at)contextr   r   r   s    r   <lambda>z0_ServicePipeline._continuation.<locals>.<lambda>%   s    t11%Hr    )r   r   r   s   ```r   _continuationz_ServicePipeline._continuation$   s	    HHr   r    c                     |t        | j                        k  r6| j                  |   }| j                  ||dz         }|j                  ||      S  ||      S )Nr	   )lenr   r#   intercept_service)r   r   r   r    interceptors        r   r   z_ServicePipeline._intercept_at'   sZ     3t(())++E2K&&ueai8E00@@>!r   c                 (    | j                  |d|      S )Nr   r   )r   r   r    s      r   executez_ServicePipeline.execute1   s     !!%G44r   N)__name__
__module____qualname__r   grpcServerInterceptor__annotations__r   r   r   intr#   HandlerCallDetailsRpcMethodHandlerr   r)   r"   r   r   r   r      s    ..//0Xd.D.D%E 0I8 IC IH I""&)"484K4K"			"55(,(?(?5			5r   r   r   r   c                      | rt        |       S d S r   )r   )r   s    r   service_pipeliner4   7   s     .:L)CtCr   c                       e Zd Zy)_ClientCallDetailsN)r*   r+   r,   r"   r   r   r6   r6   =   s     	r   r6   )methodtimeoutmetadatacredentialswait_for_readycompressioncall_detailsdefault_detailsc                    	 | j                   }	 | j                  }	 | j                  }	 | j                  }	 | j
                  }	 | j                  }||||||fS # t        $ r |j                   }Y `w xY w# t        $ r |j                  }Y nw xY w# t        $ r |j                  }Y |w xY w# t        $ r |j                  }Y w xY w# t        $ r |j
                  }Y w xY w# t        $ r |j                  }Y w xY wr   )r7   AttributeErrorr8   r9   r:   r;   r<   )r=   r>   r7   r8   r9   r:   r;   r<   s           r   _unwrap_client_call_detailsrA   N   s-   ($$*&&,((
$$ 	
'' 	
$$ 	 7Hk>;NNQ  ( ''(
  *!))*
  ,"++,  
'' 	
  
** 	
  
'' 	
sg   A A2 B B( C C A/.A/2B
	B
B%$B%(C ?C CCC65C6c                       e Zd ZU eed<   ej                  ed<   dedej                  f fdZdee	   fdZ
dee	   fdZdeej                     fd	Zdee   fd
ZdefdZdefdZdefdZdee   fdZdefdZdefdZddee   fdZ	 ddee   dee   fdZ	 ddee   deej                     fdZdefdZdeddfdZd Zd Z d Z! xZ"S )_FailureOutcome
_exception
_traceback	exception	tracebackc                 F    t         t        |           || _        || _        y r   )superrC   r   rD   rE   )r   rF   rG   	__class__s      r   r   z_FailureOutcome.__init__   s    ot-/##r   r   c                      y r   r"   r   s    r   initial_metadataz _FailureOutcome.initial_metadata       r   c                      y r   r"   rL   s    r   trailing_metadataz!_FailureOutcome.trailing_metadata   rN   r   c                 6    t         j                  j                  S r   )r-   
StatusCodeINTERNALrL   s    r   codez_FailureOutcome.code   s    '''r   c                      y)Nz+Exception raised while intercepting the RPCr"   rL   s    r   detailsz_FailureOutcome.details   s    <r   c                      yNFr"   rL   s    r   cancelz_FailureOutcome.cancel       r   c                      yrX   r"   rL   s    r   	cancelledz_FailureOutcome.cancelled   rZ   r   c                      yrX   r"   rL   s    r   	is_activez_FailureOutcome.is_active   rZ   r   c                      y r   r"   rL   s    r   time_remainingz_FailureOutcome.time_remaining   rN   r   c                      yrX   r"   rL   s    r   runningz_FailureOutcome.running   rZ   r   c                      yNTr"   rL   s    r   donez_FailureOutcome.done   rN   r   Nignored_timeoutc                     | j                   r   rD   r   rf   s     r   resultz_FailureOutcome.result       oor   c                     | j                   S r   rh   ri   s     r   rF   z_FailureOutcome.exception        r   c                     | j                   S r   )rE   ri   s     r   rG   z_FailureOutcome.traceback   rm   r   c                      yrX   r"   )r   unused_callbacks     r   add_callbackz_FailureOutcome.add_callback   rZ   r   fnc                      ||        y r   r"   r   rr   s     r   add_done_callbackz!_FailureOutcome.add_done_callback   	    
4r   c                     | S r   r"   rL   s    r   __iter__z_FailureOutcome.__iter__       r   c                     | j                   r   rh   rL   s    r   __next__z_FailureOutcome.__next__   rk   r   c                 "    | j                         S r   )r{   rL   s    r   nextz_FailureOutcome.next   s    }}r   r   )#r*   r+   r,   	Exceptionr/   typesTracebackTyper   r   r   rM   rP   r-   rR   rT   strrV   boolrY   r\   r^   floatr`   rb   re   rj   rF   rG   rq   r   ru   rx   r{   r}   __classcell__)rJ   s   @r   rC   rC      sN    ###$) $8K8K $
(<"8 8L#9 (ht/ (=# = 4 4   d huo  26'	)	 26'	%%%	&
t $4  r   rC   c                   \   e Zd ZU eed<   ej                  ed<   dedej                  fdZdee	   fdZ
dee	   fdZdeej                     fd	Zdee   fd
ZdefdZdee   fdZdefdZdefdZdefdZdefdZdefdZddee   fdZddee   fdZddee   fdZdeddfdZy)_UnaryOutcome	_response_callresponsecallc                      || _         || _        y r   )r   r   )r   r   r   s      r   r   z_UnaryOutcome.__init__   s    !
r   r   c                 6    | j                   j                         S r   )r   rM   rL   s    r   rM   z_UnaryOutcome.initial_metadata   s    zz**,,r   c                 6    | j                   j                         S r   )r   rP   rL   s    r   rP   z_UnaryOutcome.trailing_metadata   s    zz++--r   c                 6    | j                   j                         S r   )r   rT   rL   s    r   rT   z_UnaryOutcome.code   s    zz  r   c                 6    | j                   j                         S r   )r   rV   rL   s    r   rV   z_UnaryOutcome.details   s    zz!!##r   c                 6    | j                   j                         S r   )r   r^   rL   s    r   r^   z_UnaryOutcome.is_active   s    zz##%%r   c                 6    | j                   j                         S r   )r   r`   rL   s    r   r`   z_UnaryOutcome.time_remaining   s    zz((**r   c                 6    | j                   j                         S r   )r   rY   rL   s    r   rY   z_UnaryOutcome.cancel   s    zz  ""r   c                 8    | j                   j                  |      S r   )r   rq   r   callbacks     r   rq   z_UnaryOutcome.add_callback   s    zz&&x00r   c                      yrX   r"   rL   s    r   r\   z_UnaryOutcome.cancelled   rZ   r   c                      yrX   r"   rL   s    r   rb   z_UnaryOutcome.running   rZ   r   c                      yrd   r"   rL   s    r   re   z_UnaryOutcome.done   rN   r   Nrf   c                     | j                   S r   )r   ri   s     r   rj   z_UnaryOutcome.result   s    ~~r   c                      y r   r"   ri   s     r   rF   z_UnaryOutcome.exception   rN   r   c                      y r   r"   ri   s     r   rG   z_UnaryOutcome.traceback   rN   r   rr   c                      ||        y r   r"   rt   s     r   ru   z_UnaryOutcome.add_done_callback   rv   r   r   )r*   r+   r,   r   r/   r-   Callr   r   r   rM   rP   rR   rT   r   rV   r   r^   r   r`   rY   rq   r\   rb   re   rj   rF   rG   r   ru   r"   r   r   r   r      s   N99 DII -(<"8 -.8L#9 .!ht/ !$# $&4 &+ +# #1 14  d huo % % $4  r   r   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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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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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Zy)_UnaryUnaryMultiCallable_thunk_method_interceptorr   r7   r'   c                 .    || _         || _        || _        y r   r   r   r   r   r   r7   r'   s       r   r   z!_UnaryUnaryMultiCallable.__init__       'r   Nrequestr8   r9   r:   r;   r<   r   c                 :    | j                  ||||||      \  }}|S Nr8   r9   r:   r;   r<   
_with_call)	r   r   r8   r9   r:   r;   r<   r   ignored_calls	            r   __call__z!_UnaryUnaryMultiCallable.__call__  s5     "&#)# "1 "
, r   c                     	 t         j                  |||||      		 fd} j                  j                  |	|      }|j	                         |fS )Nc                 >   t        |       \  }}}}}}	 j                  |      j                  ||||||      \  }}	t        ||	      S # t        j
                  $ r}
|
cY d }
~
S d }
~
wt        $ r+}t        |t        j                         d         cY d }~S d }~ww xY wNr      
rA   r   	with_callr   r-   RpcErrorr~   rC   sysexc_info)new_detailsr   
new_methodnew_timeoutnew_metadatanew_credentialsnew_wait_for_readynew_compressionr   r   	rpc_errorrF   client_call_detailsr   s               r   continuationz9_UnaryUnaryMultiCallable._with_call.<locals>.continuation1  s     ,K9LM"E!%Z!8!B!B') /#5 / "C "$ %Xt44== !   E&y#,,.2CDDE/   4A BA%B%B1 BBB)r6   r   r   intercept_unary_unaryrj   )
r   r   r8   r9   r:   r;   r<   r   r   r   s
   `        @r   r   z#_UnaryUnaryMultiCallable._with_call  s_     1LL
	E0   66-w
 {{}d""r   c                 0    | j                  ||||||      S r   r   )r   r   r8   r9   r:   r;   r<   s          r   r   z"_UnaryUnaryMultiCallable.with_callN  s,     #)#  
 	
r   c                     	 t         j                  |||||      		 fd}	  j                  j                  |	|      S # t        $ r+}t        |t        j                         d         cY d }~S d }~ww xY w)Nc                 v    t        |       \  }}}}}}	j                  |      j                  ||||||      S r   rA   r   future
r   r   r   r   r   r   r   r   r   r   s
           r   r   z5_UnaryUnaryMultiCallable.future.<locals>.continuationr  sZ     ,K9LM";;z*11#%+1+ 2  r   r   )r6   r   r   r   r~   rC   r   r   
r   r   r8   r9   r:   r;   r<   r   rF   r   s
   `        @r   r   z_UnaryUnaryMultiCallable.future`  s~     1LL
	$	A$$::17   	A"9cllnQ.?@@	A   A 	A5
 A0*A50A5NNNNN)r*   r+   r,   r   r/   r   r-   UnaryUnaryClientInterceptorr   r   r   r   r   CallCredentialsr   Compressionr   r   r   r   r   r   r"   r   r   r   r      sW   L222(( ( 55	( $(+/6:)-26 % <(	
 d223 ! d../ 
, $(+/6:)-26-#-# %-# <(	-#
 d223-# !-# d../-# 
sDII~	-#d $(+/6:)-26

 %
 <(	

 d223
 !
 d../
 
sDII~	
* $(+/6:)-26)A)A %)A <(	)A
 d223)A !)A d../)A 
)Ar   r   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Z	 	 	 	 	 dd	e	d
e
e   de
e   de
ej                     de
e   de
ej                     fdZy)_UnaryStreamMultiCallabler   r   r   r   r7   r'   c                 .    || _         || _        || _        y r   r   r   s       r   r   z"_UnaryStreamMultiCallable.__init__  r   r   Nr   r8   r9   r:   r;   r<   c                     	 t         j                  |||||      		 fd}	  j                  j                  |	|      S # t        $ r+}t        |t        j                         d         cY d }~S d }~ww xY w)Nc                 d    t        |       \  }}}}}} 	j                  |      ||||||      S r   rA   r   r   s
           r   r   z8_UnaryStreamMultiCallable.__call__.<locals>.continuation  sQ     ,K9LM"*4;;z*#%+1+ r   r   )r6   r   r   intercept_unary_streamr~   rC   r   r   r   s
   `        @r   r   z"_UnaryStreamMultiCallable.__call__  s~     1LL
	$	A$$;;17   	A"9cllnQ.?@@	Ar   r   )r*   r+   r,   r   r/   r   r-   UnaryStreamClientInterceptorr   r   r   r   r   r   r   r   r   r"   r   r   r   r     s    L333(( ( 66	( $(+/6:)-26)A)A %)A <(	)A
 d223)A !)A d../)Ar   r   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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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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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Zy)_StreamUnaryMultiCallabler   r   r   r   r7   r'   c                 .    || _         || _        || _        y r   r   r   s       r   r   z"_StreamUnaryMultiCallable.__init__  r   r   Nrequest_iteratorr8   r9   r:   r;   r<   r   c                 :    | j                  ||||||      \  }}|S r   r   )	r   r   r8   r9   r:   r;   r<   r   r   s	            r   r   z"_StreamUnaryMultiCallable.__call__  s5     "&#)# "1 "
, r   c                     	 t         j                  |||||      		 fd} j                  j                  |	|      }|j	                         |fS )Nc                 >   t        |       \  }}}}}}	 j                  |      j                  ||||||      \  }}	t        ||	      S # t        j
                  $ r}
|
cY d }
~
S d }
~
wt        $ r+}t        |t        j                         d         cY d }~S d }~ww xY wr   r   )r   r   r   r   r   r   r   r   r   r   r   rF   r   r   s               r   r   z:_StreamUnaryMultiCallable._with_call.<locals>.continuation  s     ,K9LM"E!%Z!8!B!B$') /#5 / "C "$ %Xt44== !   E&y#,,.2CDDEr   )r6   r   r   intercept_stream_unaryrj   )
r   r   r8   r9   r:   r;   r<   r   r   r   s
   `        @r   r   z$_StreamUnaryMultiCallable._with_call  s`     1LL
	E0   77-/?
 {{}d""r   c                 0    | j                  ||||||      S r   r   )r   r   r8   r9   r:   r;   r<   s          r   r   z#_StreamUnaryMultiCallable.with_call  s,     #)#  
 	
r   c                     	 t         j                  |||||      		 fd}	  j                  j                  |	|      S # t        $ r+}t        |t        j                         d         cY d }~S d }~ww xY w)Nc                 v    t        |       \  }}}}}}	j                  |      j                  ||||||      S r   r   
r   r   r   r   r   r   r   r   r   r   s
           r   r   z6_StreamUnaryMultiCallable.future.<locals>.continuation<  sZ     ,K9LM";;z*11 #%+1+ 2  r   r   )r6   r   r   r   r~   rC   r   r   
r   r   r8   r9   r:   r;   r<   r   rF   r   s
   `        @r   r   z _StreamUnaryMultiCallable.future*  s     1LL
	$	A$$;;13C   	A"9cllnQ.?@@	Ar   r   )r*   r+   r,   r   r/   r   r-   StreamUnaryClientInterceptorr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r   r   r   r     sW   L333(( ( 66	( $(+/6:)-26- % <(	
 d223 ! d../ 
, $(+/6:)-26-#--# %-# <(	-#
 d223-# !-# d../-# 
sDII~	-#d $(+/6:)-26
-
 %
 <(	

 d223
 !
 d../
 
sDII~	
* $(+/6:)-26)A-)A %)A <(	)A
 d223)A !)A d../)A 
)Ar   r   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Z	 	 	 	 	 dd	e	d
e
e   de
e   de
ej                     de
e   de
ej                     fdZy)_StreamStreamMultiCallabler   r   r   r   r7   r'   c                 .    || _         || _        || _        y r   r   r   s       r   r   z#_StreamStreamMultiCallable.__init__[  r   r   Nr   r8   r9   r:   r;   r<   c                     	 t         j                  |||||      		 fd}	  j                  j                  |	|      S # t        $ r+}t        |t        j                         d         cY d }~S d }~ww xY w)Nc                 d    t        |       \  }}}}}} 	j                  |      ||||||      S r   r   r   s
           r   r   z9_StreamStreamMultiCallable.__call__.<locals>.continuationw  sQ     ,K9LM"*4;;z* #%+1+ r   r   )r6   r   r   intercept_stream_streamr~   rC   r   r   r   s
   `        @r   r   z#_StreamStreamMultiCallable.__call__e  s     1LL
	$	A$$<<13C   	A"9cllnQ.?@@	Ar   r   )r*   r+   r,   r   r/   r   r-   StreamStreamClientInterceptorr   r   r   r   r   r   r   r   r   r"   r   r   r   r   V  s    L444(( ( 77	( $(+/6:)-26)A-)A %)A <(	)A
 d223)A !)A d../)Ar   r   c                   |   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Z	 ddedee   fdZdefd	Z	 	 	 ddedee   dee   dee   dej(                  f
dZ	 	 	 ddedee   dee   dee   dej,                  f
dZ	 	 	 ddedee   dee   dee   dej0                  f
dZ	 	 	 ddedee   dee   dee   dej4                  f
dZd Zd Zd Zd Zy
)_Channel_channelr   channelr'   c                      || _         || _        y r   )r   r   )r   r   r'   s      r   r   z_Channel.__init__  s      'r   r   try_to_connectc                 >    | j                   j                  ||       y )N)r   )r   	subscribe)r   r   r   s      r   r   z_Channel.subscribe  s     	Hr   c                 :    | j                   j                  |       y r   )r   unsubscriber   s     r   r   z_Channel.unsubscribe  s    !!(+r   Nr7   request_serializerresponse_deserializer_registered_methodr   c                       fd}t         j                  t        j                        rt	        || j                        S  ||      S )Nc                 @    j                   j                  |       S r   )r   unary_unarymr   r   r   r   s    r   r!   z&_Channel.unary_unary.<locals>.<lambda>  s     $--33!	
r   )
isinstancer   r-   r   r   r   r7   r   r   r   r   s   ` ``` r   r   z_Channel.unary_unary  sA    
 d'')I)IJ+E64;L;LMM= r   c                       fd}t         j                  t        j                        rt	        || j                        S  ||      S )Nc                 @    j                   j                  |       S r   )r   unary_streamr   s    r   r!   z'_Channel.unary_stream.<locals>.<lambda>       $--44!	
r   )r   r   r-   r   r   r   s   ` ``` r   r  z_Channel.unary_stream  A    
 d'')J)JK,UFD<M<MNN= r   c                       fd}t         j                  t        j                        rt	        || j                        S  ||      S )Nc                 @    j                   j                  |       S r   )r   stream_unaryr   s    r   r!   z'_Channel.stream_unary.<locals>.<lambda>  r  r   )r   r   r-   r   r   r   s   ` ``` r   r  z_Channel.stream_unary  r  r   c                       fd}t         j                  t        j                        rt	        || j                        S  ||      S )Nc                 @    j                   j                  |       S r   )r   stream_streamr   s    r   r!   z(_Channel.stream_stream.<locals>.<lambda>  s     $--55!	
r   )r   r   r-   r   r   r   s   ` ``` r   r  z_Channel.stream_stream  sA    
 d'')K)KL-eVT=N=NOO= r   c                 8    | j                   j                          y r   r   closerL   s    r   _closez_Channel._close      r   c                     | S r   r"   rL   s    r   	__enter__z_Channel.__enter__  ry   r   c                 $    | j                          yrX   )r  )r   exc_typeexc_valexc_tbs       r   __exit__z_Channel.__exit__	  s    r   c                 8    | j                   j                          y r   r  rL   s    r   r  z_Channel.close  r  r   )F)NNF) r*   r+   r,   r-   Channelr/   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   UnaryUnaryMultiCallabler   UnaryStreamMultiCallabler  StreamUnaryMultiCallabler  StreamStreamMultiCallabler  r  r  r  r  r"   r   r   r   r     s*   ll(())**))	+ (( ,,--..--/
( DII I2:4.I
,H , =AAE-2!! %%89!  ((=>	!
 %TN! 
	%	%!0 =AAE-2!! %%89!  ((=>	!
 %TN! 
	&	&!0 =AAE-2!! %%89!  ((=>	!
 %TN! 
	&	&!0 =AAE-2!! %%89!  ((=>	!
 %TN! 
	'	'!(r   r   r   c                 6   t        t        |            D ]  }t        |t        j                        sYt        |t        j
                        s?t        |t        j                        s%t        |t        j                        st        d      t        | |      }  | 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'   s      r   intercept_channelr"    s      \ 23;(H(HI{D,M,MN{D,M,MN{D,N,NO9  7K0 4 Nr   )3__doc__collectionsr   r   typingr   r   r   r   r   r   r-   _typingr
   r   r   r   r   objectr   r.   r4   
namedtupleClientCallDetailsr6   r   r   r   r   r   rA   r   Futurer   rC   r   r  r   r  r   r  r   r  r   r  r   r   r   r   r   r"  r"   r   r   <module>r+     s   2  
  B B  * % ! ( (5v 52D8D$:$:;<DD	K	

 		"0O((0O++0O d22D$:J:JJ0OfCMM4;;		CL3DIIt{{ 3lLAt;; LA^8A = = 8AvLA = = LA^8A!?!? 8Av}t|| }@\\001122113	
	 
\\r   