
    Ag=                       d Z ddlZddlZddlZddlZddl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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$Z ejJ                  e&      Z'djQ                  ejR                        Z*dZ+ ejX                  d      duZ-ej\                  j^                  ej\                  j`                  ej\                  jb                  ej\                  jd                  ej\                  jf                  ej\                  jh                  fZ5ej\                  j^                  ej\                  j`                  ej\                  jb                  ej\                  jd                  ej\                  jh                  fZ6ej\                  j^                  ej\                  jd                  ej\                  jf                  ej\                  jh                  fZ7ej\                  j^                  ej\                  jd                  ej\                  jh                  fZ8dZ9dZ:dZ;dee<   dee<   fdZ=deej|                     dee?   de?fdZ@ G d deA      ZBdeBdej|                  de?ddfd ZCd!ej                  deBd"ee   dee    fd#ZEdeBd"ee   de#fd$ZFd%edeBd&eej                  ej                  f   d'e"d(ee#   ddfd)ZId*e?d+eBde?fd,ZJ G d- d.ej                  ej                  ej                        ZN G d/ d0ej                  ej                        ZP G d1 d2ePej                  ej                        ZQ G d3 d4ePej                  ej                        ZRd5e
dee<   d'e"deee<   eeS   eej                     f   fd6ZTdeBd&ej                  d7eUd8ee<   dee!ee!ej                  f   f   f
d9ZVd:ee   d;eWdeeej                        fd<ZYd:ee   d;eWdeeeej                     ee#   f      fd=ZZd>ee<   dee<   fd?Z[ G d@ dAej                        Z] G dB dCej                        Z_ G dD dEej                        Z` G dF dGej                        Zb G dH dIej                        Zd G dJ dKeW      Ze G dL dMeA      ZfdefddfdNZgdeffdOZh G dP dQeA      Zideideeej                  gdf      fdRZkdeidSej                  dTeeej                  gdf      ddfdUZldeidVeeej                  gdf      ddfdWZmdeidXej                  dYeUddfdZZodeid[eej                  gdf   d\eUddfd]Zpdeid[eej                  gdf   ddfd^Zqd_ee   d`eej                     dee   fdaZsdbee   deee   ee   f   fdcZt G dd deej                        Zny)fz.Invocation-side implementation of gRPC Python.    N)
AnyCallableDictIteratorListOptionalSequenceSetTupleUnion)_common)_compression)_grpcio_metadata)_observability)cygrpc)ChannelArgumentType)DeserializingFunction)IntegratedCallFactory)MetadataType)NullaryCallbackType)ResponseType)SerializingFunction)UserTagzgrpc-python/{}!GRPC_SINGLE_THREADED_UNARY_STREAMz0Exception calling channel subscription callback!z?<{} of RPC that terminated with:
	status = {}
	details = "{}"
>zZ<{} of RPC that terminated with:
	status = {}
	details = "{}"
	debug_error_string = "{}"
>timeoutreturnc                 8    | d S t        j                          | z   S N)timer   s    B/var/www/openai/venv/lib/python3.12/site-packages/grpc/_channel.py	_deadliner"   m   s    ?4=		g(==    unknown_cygrpc_codedetailsc                 &    dj                  | |      S )Nz,Server sent unknown code {} and details "{}")format)r$   r%   s     r!   _unknown_code_detailsr(   q   s     :@@W r#   c                      e Zd ZU ej                  ed<   eej                     ed<   e	e
   ed<   eed<   e	e
   ed<   e	ej                     ed<   e	e   ed<   e	e   ed<   eed	<   ee   ed
<   e	e   ed<   e	e   ed<   e	e   ed<   e	e   ed<   e	e   ed<   deej                     de	e
   de	e
   de	ej                     de	e   f
dZd Zy)	_RPCState	conditiondueinitial_metadataresponsetrailing_metadatacoder%   debug_error_string	cancelled	callbacks
fork_epochrpc_start_timerpc_end_timemethodtargetc                 0   t        j                         | _        t        |      | _        || _        d | _        || _        || _        || _	        d | _
        d | _        d | _        d | _        d | _        d| _        g | _        t#        j$                         | _        y NF)	threading	Conditionr+   setr,   r-   r.   r/   r0   r%   r1   r5   r6   r7   r8   r2   r3   r   get_fork_epochr4   )selfr,   r-   r/   r0   r%   s         r!   __init__z_RPCState.__init__   s     #,,. s8 0!2	"& #   //1r#   c                 6    t        j                         | _        y r   )r;   r<   r+   r?   s    r!   reset_postfork_childz_RPCState.reset_postfork_child   s    ",,.r#   N)__name__
__module____qualname__r;   r<   __annotations__r
   r   OperationTyper   r   r   grpc
StatusCodestrboolr   r   intfloatr	   r@   rC    r#   r!   r*   r*   y   s    """	V!!	""|,,M--
4??
##c] %O'((UO#5/!SMSM&2f**+&2 #<0&2 $L1	&2
 t'&2 #&2P/r#   r*   stater0   c                 n    | j                   )|| _         || _        | j                  d| _        d| _        y y NrO   )r0   r%   r-   r/   )rP   r0   r%   s      r!   _abortrS      s;    zz
!!)%'E""$ r#   eventresponse_deserializerc                 8   g }| j                   D ]  }|j                         }|j                  j                  |       |t        j
                  j                  k(  r|j                         |_        b|t        j
                  j                  k(  r[|j                         }|t        j                  ||      }|(d}t        |t        j                  j                  |       ||_        |t        j
                  j"                  k(  s|j%                         |_        |j&                  t        j(                  j+                  |j'                               }	|	?t        j                  j,                  |_        t/        |	|j1                               |_        n1|	|_        |j1                         |_        |j3                         |_        t7        j8                         |_        t=        j>                  |       |jA                  |jB                         d |_!        
 |S )Nz!Exception deserializing response!)"batch_operationstyper,   remover   rH   receive_initial_metadatar-   receive_messagemessager   deserializerS   rI   rJ   INTERNALr.   receive_status_on_clientr/   r0   !CYGRPC_STATUS_CODE_TO_STATUS_CODEgetUNKNOWNr(   r%   error_stringr1   r   perf_counterr6   r   maybe_record_rpc_latencyextendr3   )
rT   rP   rU   r3   batch_operationoperation_typeserialized_responser.   r%   r0   s
             r!   _handle_eventrj      s   
 I 11(--/		(V11JJJ%4%E%E%GE"v33CCC"1"9"9";"."..')> #AG5$//":":GD%-ENv33LLL&5&G&G&IE#zz!@@DD#((* <!%!8!8EJ$9o557%EM "&EJ$3$;$;$=EM/>/K/K/ME,!%!2!2!4E33E:U__-"EOE 2F r#   c                       fd}|S )Nc           	         j                   5  t        |       }j                   j                          j                   }d d d        D ]
  }	  |         xr! j                  t        j                         k\  S # 1 sw Y   =xY w# t        $ r=}t        j                  dt        |j                        t        |             Y d }~d }~ww xY w)NzException in callback %s: %s)r+   rj   
notify_allr,   	Exceptionloggingerrorreprfuncr4   r   r>   )rT   r3   donecallbackerU   rP   s        r!   handle_eventz$_event_handler.<locals>.handle_event   s    __%eU4IJIOO&&(yy=D  "H
 " C((F,A,A,CCC _   2D4Ga s#   5A?B?B	C3CCrO   )rP   rU   rv   s   `` r!   _event_handlerrw      s    D  r#   request_iteratorcallrequest_serializerevent_handlerc                       fd}t        j                  |      }|j                  d       |j                          y)z'Consume a request supplied by the user.c            	      ,   	 d} 	 t        j                          t        
      }	 | st        j                          	 t        j                  |      }j                   5  j"                  mj$                  s`|Vt        j                  j&                  }d}j                  t        j                  |   |       t        ||       	 d d d        y j(                  j+                  t         j,                  j.                         t        j0                  |t2              f}j5                  |	      }|s=j(                  j7                  t         j,                  j.                         	 d d d        y fd}t        j8                  j                   j8                  |t;        j<                  t         j>                               j"                  	 d d d        y 	 d d d        y 	 d d d        # t        $ r Y | st        j                          nt
        $ r t        j                          d} t        j                  j                  }d}t        j                  |       j                  t        j                  |   |       t        ||       Y | st        j                          y y w xY w# | st        j                          w w xY w# 1 sw Y   xY wj                   5  j"                  j(                  j+                  t         j,                  j@                         t        jB                  t2              f}j5                  |	      }|s3j(                  j7                  t         j,                  j@                         d d d        y # 1 sw Y   y xY w)NTFzException iterating requests!Exception serializing request!c                  p     j                   d uxs& t        j                  j                   j                  vS r   )r0   r   rH   send_messager,   )rP   s   r!   _donezJ_consume_request_iterator.<locals>.consume_request_iterator.<locals>._done=  s4     %

$ 6 !1#)#7#7#D#D',yy$1r#   )spin_cb)"r   enter_user_request_generatornextStopIteration"return_from_user_request_generatorrn   rI   rJ   rb   _LOGGER	exceptioncancelr   !STATUS_CODE_TO_CYGRPC_STATUS_CODErS   	serializer+   r0   r2   r^   r,   addrH   r   SendMessageOperation_EMPTY_FLAGSoperaterY   wait	functoolspartialblock_if_fork_in_progresssend_close_from_clientSendCloseFromClientOperation)*return_from_user_request_generator_invokedrequestr0   r%   serialized_request
operations	operatingr   ry   r{   rx   rz   rP   s           r!   consume_request_iteratorz;_consume_request_iterator.<locals>.consume_request_iterator  s    9>6@335/0 B==?!(!2!27<N!O::%eoo)1#77"B#EEdK# udG4 ! 		f&:&:&G&GH"77 2L&

 %)LL]$K	(!II,,V-A-A-N-NO"+ !.  !OO00!$-$5$5 & @ @%% !::1"M !P Q !J 2K !/  !  B==?  
99;=A:..9!!'*==dCW udG,A==? B
 B==? B !R __zz!		f22IIJ77E
 !LL]C	 II$$,,CC __s^   G/ A*KBK1A KK/	J)8J, A?J)J, (J))J, ,KK B!N

Nr8   TNr   ForkManagedThread	setDaemonstart)rx   rP   ry   rz   r{   r   consumption_threads   `````  r!   _consume_request_iteratorr     sB    M M^  11'   &r#   
class_name	rpc_statec                    |j                   5  |j                  dj                  |       cddd       S |j                  t        j                  j
                  u r4t        j                  | |j                  |j                        cddd       S t        j                  | |j                  |j                  |j                        cddd       S # 1 sw Y   yxY w)z Calculates error string for RPC.Nz<{} object>)
r+   r0   r'   rI   rJ   OK_OK_RENDEZVOUS_REPR_FORMATr%   _NON_OK_RENDEZVOUS_REPR_FORMATr1   )r   r   s     r!   _rpc_state_stringr   b  s    			>>! ''
3 
	 ^^t111-44INNI,=,=	 
	 288!!,,	 
		s   CAC5CCc                      e Zd ZU dZeed<   de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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efdZdefdZ	 ddee   d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de!ejD                  gdf   dee   ddfdZ#y)_InactiveRpcErrorzAn RPC error not tied to the execution of a particular RPC.

    The RPC represented by the state object must not be in-progress or
    cancelled.

    Attributes:
      _state: An instance of _RPCState.
    _staterP   c           
         |j                   5  t        dt        j                  |j                        t        j                  |j
                        |j                  t        j                  |j                              | _        t        j                  |j                        | j                  _	        t        j                  |j                        | j                  _
        d d d        y # 1 sw Y   y xY wrR   )r+   r*   copydeepcopyr-   r/   r0   r%   r   r.   r1   r?   rP   s     r!   r@   z_InactiveRpcError.__init__  s    __#e445e556

emm,DK $(99U^^#<DKK -1YYu7O7O-PDKK* __s   CC((C1r   c                 .    | j                   j                  S r   r   r-   rB   s    r!   r-   z"_InactiveRpcError.initial_metadata  s    {{+++r#   c                 .    | j                   j                  S r   r   r/   rB   s    r!   r/   z#_InactiveRpcError.trailing_metadata  s    {{,,,r#   c                 .    | j                   j                  S r   r   r0   rB   s    r!   r0   z_InactiveRpcError.code  s    {{r#   c                 T    t        j                  | j                  j                        S r   )r   decoder   r%   rB   s    r!   r%   z_InactiveRpcError.details  s    ~~dkk1122r#   c                 T    t        j                  | j                  j                        S r   )r   r   r   r1   rB   s    r!   r1   z$_InactiveRpcError.debug_error_string  s    ~~dkk<<==r#   c                 V    t        | j                  j                  | j                        S r   r   	__class__rD   r   rB   s    r!   _reprz_InactiveRpcError._repr       !8!8$++FFr#   c                 "    | j                         S r   r   rB   s    r!   __repr__z_InactiveRpcError.__repr__      zz|r#   c                 "    | j                         S r   r   rB   s    r!   __str__z_InactiveRpcError.__str__  r   r#   c                      y)zSee grpc.Future.cancel.FrO   rB   s    r!   r   z_InactiveRpcError.cancel      r#   c                      y)zSee grpc.Future.cancelled.FrO   rB   s    r!   r2   z_InactiveRpcError.cancelled  r   r#   c                      y)zSee grpc.Future.running.FrO   rB   s    r!   runningz_InactiveRpcError.running  r   r#   c                      y)zSee grpc.Future.done.TrO   rB   s    r!   rs   z_InactiveRpcError.done  s    r#   Nr   c                     | )zSee grpc.Future.result.rO   r?   r   s     r!   resultz_InactiveRpcError.result  s	     
r#   c                     | S )zSee grpc.Future.exception.rO   r   s     r!   r   z_InactiveRpcError.exception  s	     r#   c                 h    	 | # t         j                  $ r t        j                         d   cY S w xY w)zSee grpc.Future.traceback.   )rI   RpcErrorsysexc_infor   s     r!   	tracebackz_InactiveRpcError.traceback  s0    	%J}} 	%<<>!$$	%s    *11fnc                      ||        y)z"See grpc.Future.add_done_callback.NrO   )r?   r   r   s      r!   add_done_callbackz#_InactiveRpcError.add_done_callback  s     	4r#   r   )$rD   rE   rF   __doc__r*   rG   r@   r   r   r-   r/   rI   rJ   r0   rK   r%   r1   r   r   r   rL   r   r2   r   rs   rN   r   r   rn   r   typesTracebackTyper   r   Futurer   rO   r#   r!   r   r   t  sn    
Qi 
Q,(<"8 ,-8L#9 - ht/  3# 3>HSM >Gs G#   4  d 
 *.	 *.	)	 *.%%	%%%	&% $(dkk]D() % 
	r#   r   c            	       j    e Zd ZU dZeed<   eej                  ej                  f   ed<   e
e   ed<   e
e   ed<   dedeej                  ej                  f   de
e   d	e
e   f fd
ZdefdZde
e   fdZdefdZdedefdZd Zd Zd Zd Zde
e   fdZdefdZdefdZdefdZddZ xZS )_Rendezvousa  An RPC iterator.

    Attributes:
      _state: An instance of _RPCState.
      _call: An instance of SegregatedCall or IntegratedCall.
        In either case, the _call object is expected to have operate, cancel,
        and next_event methods.
      _response_deserializer: A callable taking bytes and return a Python
        object.
      _deadline: A float representing the deadline of the RPC in seconds. Or
        possibly None, to represent an RPC with no deadline at all.
    r   _call_response_deserializerr"   rP   ry   rU   deadlinec                 b    t         t        |           || _        || _        || _        || _        y r   )superr   r@   r   r   r   r"   )r?   rP   ry   rU   r   r   s        r!   r@   z_Rendezvous.__init__  s/     	k4)+
&;#!r#   r   c                     | j                   j                  5  | j                   j                  du cddd       S # 1 sw Y   yxY w)zSee grpc.RpcContext.is_activeNr   r+   r0   rB   s    r!   	is_activez_Rendezvous.is_active  s-    [["";;##t+ #""	   9Ac                     | j                   j                  5  | j                  
	 ddd       yt        | j                  t	        j                         z
  d      cddd       S # 1 sw Y   yxY w)z"See grpc.RpcContext.time_remainingNr   )r   r+   r"   maxr   rB   s    r!   time_remainingz_Rendezvous.time_remaining  sK    [[""~~% #" 4>>DIIK7;	 #""s   A"*A""A+c                    | j                   j                  5  | j                   j                  t        j                  j
                  }d}| j                  j                  t        j                  |   |       d| j                   _
        t        | j                   ||       | j                   j                  j                          	 ddd       y	 ddd       y# 1 sw Y   yxY w)zSee grpc.RpcContext.cancelNz!Locally cancelled by application!TF)r   r+   r0   rI   rJ   	CANCELLEDr   r   r   r   r2   rS   rm   )r?   r0   r%   s      r!   r   z_Rendezvous.cancel  s    [[""{{'00=

!!==dCW )-%t{{D'2%%002 #"  #""s   B-CCC rt   c                     | j                   j                  5  | j                   j                  
	 ddd       y| j                   j                  j                  |       	 ddd       y# 1 sw Y   yxY w)z See grpc.RpcContext.add_callbackNFT)r   r+   r3   appendr?   rt   s     r!   add_callbackz_Rendezvous.add_callback  sS    [[""{{$$, #" %%,,X6 #""s   A'&A''A0c                     | S r   rO   rB   s    r!   __iter__z_Rendezvous.__iter__      r#   c                 "    | j                         S r   _nextrB   s    r!   r   z_Rendezvous.next  r   r#   c                 "    | j                         S r   r   rB   s    r!   __next__z_Rendezvous.__next__  r   r#   c                     t               r   NotImplementedErrorrB   s    r!   r   z_Rendezvous._next!      !##r#   c                     t               r   r   rB   s    r!   r1   z_Rendezvous.debug_error_string$  r   r#   c                 V    t        | j                  j                  | j                        S r   r   rB   s    r!   r   z_Rendezvous._repr'  r   r#   c                 "    | j                         S r   r   rB   s    r!   r   z_Rendezvous.__repr__*  r   r#   c                 "    | j                         S r   r   rB   s    r!   r   z_Rendezvous.__str__-  r   r#   c                    | j                   j                  5  | j                   j                  t        j                  j
                  | j                   _        d| j                   _        d| j                   _        | j                  j                  t        j                  | j                   j                     | j                   j                         | j                   j                  j                          d d d        y # 1 sw Y   y xY w)Nz"Cancelled upon garbage collection!T)r   r+   r0   rI   rJ   r   r%   r2   r   r   r   r   rm   rB   s    r!   __del__z_Rendezvous.__del__0  s    [[""{{'#'??#<#< &J#(,%

!!==dkk>N>NOKK'' %%002 #""s   CC;;Dr   N)rD   rE   rF   r   r*   rG   r   r   SegregatedCallIntegratedCallr   r   rN   r@   rL   r   r   r   r   r   r   r   r   r   rK   r1   r   r   r   r  __classcell__r   s   @r!   r   r     s    &&(=(==>>$%:;;"" F))6+@+@@A"  ((=>	"
 5/",4 ,
< <  %8 T $$HSM $Gs G#  
3r#   r   c                      e Zd ZU dZeed<   defdZdefdZdefdZ	defdZ
dd	ee   d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ej,                  gdf   ddfdZdee   fdZdee   fdZdeej6                     fdZdee   fdZdeej@                     fdZ!defdZ"defdZ#dee   fdZ$y)_SingleThreadedRendezvousaN  An RPC iterator operating entirely on a single thread.

    The __next__ method of _SingleThreadedRendezvous does not depend on the
    existence of any other thread, including the "channel spin thread".
    However, this means that its interface is entirely synchronous. So this
    class cannot completely fulfill the grpc.Future interface. The result,
    exception, and traceback methods will never block and will instead raise
    an exception if calling the method would result in blocking.

    This means that these methods are safe to call from add_done_callback
    handlers.
    r   r   c                 2    | j                   j                  d uS r   r   rB   s    r!   _is_completez&_SingleThreadedRendezvous._is_completeO      {{t++r#   c                     | j                   j                  5  | j                   j                  cd d d        S # 1 sw Y   y xY wr   r   r+   r2   rB   s    r!   r2   z#_SingleThreadedRendezvous.cancelledR  (    [["";;(( #""	   7A c                     | j                   j                  5  | j                   j                  d u cd d d        S # 1 sw Y   y xY wr   r   rB   s    r!   r   z!_SingleThreadedRendezvous.runningV  -    [["";;##t+ #""r   c                     | j                   j                  5  | j                   j                  d ucd d d        S # 1 sw Y   y xY wr   r   rB   s    r!   rs   z_SingleThreadedRendezvous.doneZ  -    [["";;##4/ #""r   Nr   c                    ~| j                   j                  5  | j                         st        j                  j                  d      | j                   j                  t        j                  j                  u r| j                   j                  cddd       S | j                   j                  rt        j                         | # 1 sw Y   yxY w)a9  Returns the result of the computation or raises its exception.

        This method will never block. Instead, it will raise an exception
        if calling this method would otherwise result in blocking.

        Since this method will never block, any `timeout` argument passed will
        be ignored.
        zJ_SingleThreadedRendezvous only supports result() when the RPC is complete.N)r   r+   r
  rI   experimental
UsageErrorr0   rJ   r   r.   r2   FutureCancelledErrorr   s     r!   r   z _SingleThreadedRendezvous.result^  s     [[""$$&''22(  {{4??#5#55{{++ #" &&//11
 #"s   A5C,CCc                    ~| j                   j                  5  | j                         st        j                  j                  d      | j                   j                  t        j                  j                  u r
	 ddd       y| j                   j                  rt        j                         | cddd       S # 1 sw Y   yxY w)a*  Return the exception raised by the computation.

        This method will never block. Instead, it will raise an exception
        if calling this method would otherwise result in blocking.

        Since this method will never block, any `timeout` argument passed will
        be ignored.
        zM_SingleThreadedRendezvous only supports exception() when the RPC is complete.N)r   r+   r
  rI   r  r  r0   rJ   r   r2   r  r   s     r!   r   z#_SingleThreadedRendezvous.exceptionu  s     [[""$$&''22,  {{4??#5#55 #" &&//11 #""s   A!B7+B77C c                    ~| j                   j                  5  | j                         st        j                  j                  d      | j                   j                  t        j                  j                  u r
	 ddd       y| j                   j                  rt        j                         	 | # t        j                  $ r# t        j                         d   cY cddd       S w xY w# 1 sw Y   yxY w)a;  Access the traceback of the exception raised by the computation.

        This method will never block. Instead, it will raise an exception
        if calling this method would otherwise result in blocking.

        Since this method will never block, any `timeout` argument passed will
        be ignored.
        zM_SingleThreadedRendezvous only supports traceback() when the RPC is complete.Nr   )r   r+   r
  rI   r  r  r0   rJ   r   r2   r  r   r   r   r   s     r!   r   z#_SingleThreadedRendezvous.traceback  s     [[""$$&''22,  {{4??#5#55 #" &&//11-J}} -<<>!,, #"- #"s0   A!C(*C(-B//*C%C($C%%C((C1r   c                    | j                   j                  5  | j                   j                  C| j                   j                  j	                  t        j                  ||              	 d d d        y 	 d d d         ||        y # 1 sw Y   xY wr   r   r+   r0   r3   r   r   r   r?   r   s     r!   r   z+_SingleThreadedRendezvous.add_done_callback  i    [[""{{'%%,,Y->->r4-HI #"' #
 	4 #"   ABBc                     | j                   j                  5  | j                   j                  '| j                          | j                   j                  '| j                   j                  cddd       S # 1 sw Y   yxY w)See grpc.Call.initial_metadataN)r   r+   r-   _consume_next_eventrB   s    r!   r-   z*_SingleThreadedRendezvous.initial_metadata  sX    [["" ++..6((* ++..6;;// #""s   =A4A44A=c                     | j                   j                  5  | j                   j                  t        j                  j                  d      | j                   j                  cddd       S # 1 sw Y   yxY w)See grpc.Call.trailing_metadataNz4Cannot get trailing metadata until RPC is completed.)r   r+   r/   rI   r  r  rB   s    r!   r/   z+_SingleThreadedRendezvous.trailing_metadata  sV    [[""{{,,4''22J  ;;00 #""   AA,,A5c                     | j                   j                  5  | j                   j                  t        j                  j                  d      | j                   j                  cddd       S # 1 sw Y   yxY w)See grpc.Call.codeNz'Cannot get code until RPC is completed.)r   r+   r0   rI   r  r  rB   s    r!   r0   z_SingleThreadedRendezvous.code  sV    [[""{{'''22=  ;;## #""r$  c                    | j                   j                  5  | j                   j                  t        j                  j                  d      t        j                  | j                   j                        cddd       S # 1 sw Y   yxY w)See grpc.Call.detailsNz*Cannot get details until RPC is completed.)r   r+   r%   rI   r  r  r   r   rB   s    r!   r%   z!_SingleThreadedRendezvous.details  s_    [[""{{""*''22@  >>$++"5"56 #""   AA??Bc                     | j                   j                         }| j                  j                  5  t	        || j                  | j
                        }|D ]	  } |         	 d d d        |S # 1 sw Y   |S xY wr   )r   
next_eventr   r+   rj   r   )r?   rT   r3   rt   s       r!   r!  z-_SingleThreadedRendezvous._consume_next_event  sh    

%%'[[""%t{{D$?$?I & 
 &	 #  # s   0A,,A6c                    	 | j                          | j                  j                  5  | j                  j                  2| j                  j                  }d | j                  _        |cd d d        S t        j
                  j                  | j                  j                  vrR| j                  j                  t        j                  j                  u r
t               | j                  j                  | d d d        # 1 sw Y   
xY wr   )r!  r   r+   r.   r   rH   r[   r,   r0   rI   rJ   r   r   )r?   r.   s     r!   _next_responsez(_SingleThreadedRendezvous._next_response  s    $$&&&;;''3#{{33H+/DKK(#	 '& ((88O{{''4??+=+==+o-))5"
 ' &&s   ?C<1BC<<Dc                    | j                   j                  5  | j                   j                  | j                   j                  j	                  t
        j                  j                         | j                  j                  t        j                  t              fd       }|sz| j                   j                  j                  t
        j                  j                         n<| j                   j                  t        j                  j                  u r
t!               | d d d        | j#                         S # 1 sw Y   | j#                         S xY wr   )r   r+   r0   r,   r   r   rH   r[   r   r   ReceiveMessageOperationr   rY   rI   rJ   r   r   r-  )r?   r   s     r!   r   z_SingleThreadedRendezvous._next  s    [[""{{' ##F$8$8$H$HI JJ..33LACT	 !KKOO**6+?+?+O+OP!!T__%7%77#o%
- #. ""$$/ #. ""$$s   DD33Ec                    | j                   j                  5  | j                   j                  t        j                  j                  d      t        j                  | j                   j                        cd d d        S # 1 sw Y   y xY w)Nz5Cannot get debug error string until RPC is completed.)r   r+   r1   rI   r  r  r   r   rB   s    r!   r1   z,_SingleThreadedRendezvous.debug_error_string
  s_    [[""{{--5''22K  >>$++"@"@A #""r)  r   )%rD   rE   rF   r   r*   rG   rL   r
  r2   r   rs   r   rN   r   r   rn   r   r   r   r   r   rI   r   r   r   r-   r/   rJ   r0   rK   r%   r   	BaseEventr!  r-  r   r1   rO   r#   r!   r  r  =  sF    ,d ,)4 ), ,0d 0huo  .% HY<O 0 *.--	%%%	&-8Hdkk]D-@$A d 0(<"8 018L#9 1$ht/ $7# 7
Xf.>.>%? 
# # %s %4BHSM Br#   r  c                   `   e Zd ZU dZeed<   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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   defdZddee   dee   fdZ	 ddee   deej6                     fdZdee
j<                  gdf   ddfdZdefdZ y)_MultiThreadedRendezvousa  An RPC iterator that depends on a channel spin thread.

    This iterator relies upon a per-channel thread running in the background,
    dequeueing events from the completion queue, and notifying threads waiting
    on the threading.Condition object in the _RPCState object.

    This extra thread allows _MultiThreadedRendezvous to fulfill the grpc.Future interface
    and to mediate a bidirection streaming RPC.
    r   r   c                       j                   j                  5   fd}t        j                   j                   j                  j                  |        j                   j                  cddd       S # 1 sw Y   yxY w)r   c                  4     j                   j                  d uS r   r   rB   s   r!   r   z8_MultiThreadedRendezvous.initial_metadata.<locals>._done&  s    {{334??r#   N)r   r+   r   r   r-   r?   r   s   ` r!   r-   z)_MultiThreadedRendezvous.initial_metadata"  sO    [[""@ LL..33U;;;// #""   AA11A:c                       j                   j                  5   fd}t        j                   j                   j                  j                  |        j                   j                  cddd       S # 1 sw Y   yxY w)r#  c                  4     j                   j                  d uS r   r   rB   s   r!   r   z9_MultiThreadedRendezvous.trailing_metadata.<locals>._done0  s    {{44D@@r#   N)r   r+   r   r   r/   r6  s   ` r!   r/   z*_MultiThreadedRendezvous.trailing_metadata,  sO    [[""A LL..33U;;;00 #""r7  c                       j                   j                  5   fd}t        j                   j                   j                  j                  |        j                   j                  cddd       S # 1 sw Y   yxY w)r&  c                  4     j                   j                  d uS r   r   rB   s   r!   r   z,_MultiThreadedRendezvous.code.<locals>._done:  s    {{''t33r#   N)r   r+   r   r   r0   r6  s   ` r!   r0   z_MultiThreadedRendezvous.code6  sN    [[""4 LL..33U;;;## #""r7  c                       j                   j                  5   fd}t        j                   j                   j                  j                  |       t        j                   j                   j
                        cddd       S # 1 sw Y   yxY w)r(  c                  4     j                   j                  d uS r   )r   r%   rB   s   r!   r   z/_MultiThreadedRendezvous.details.<locals>._doneD  s    {{**$66r#   N)r   r+   r   r   r   r%   r6  s   ` r!   r%   z _MultiThreadedRendezvous.details@  sW    [[""7 LL..33U;>>$++"5"56 #""   A"BBc                       j                   j                  5   fd}t        j                   j                   j                  j                  |       t        j                   j                   j
                        cd d d        S # 1 sw Y   y xY w)Nc                  4     j                   j                  d uS r   )r   r1   rB   s   r!   r   z:_MultiThreadedRendezvous.debug_error_string.<locals>._doneM  s    {{55TAAr#   )r   r+   r   r   r   r1   r6  s   ` r!   r1   z+_MultiThreadedRendezvous.debug_error_stringJ  sX    [[""B LL..33U;>>$++"@"@A #""r>  c                     | j                   j                  5  | j                   j                  cd d d        S # 1 sw Y   y xY wr   r  rB   s    r!   r2   z"_MultiThreadedRendezvous.cancelledS  r  r  c                     | j                   j                  5  | j                   j                  d u cd d d        S # 1 sw Y   y xY wr   r   rB   s    r!   r   z _MultiThreadedRendezvous.runningW  r  r   c                     | j                   j                  5  | j                   j                  d ucd d d        S # 1 sw Y   y xY wr   r   rB   s    r!   rs   z_MultiThreadedRendezvous.done[  r  r   c                 2    | j                   j                  d uS r   r   rB   s    r!   r
  z%_MultiThreadedRendezvous._is_complete_  r  r#   Nr   c                    | j                   j                  5  t        j                  | j                   j                  j                  | j                  |      }|rt        j                         | j                   j                  t
        j                  j                  u r| j                   j                  cddd       S | j                   j                  rt        j                         | # 1 sw Y   yxY w)zReturns the result of the computation or raises its exception.

        See grpc.Future.result for the full API contract.
        r    N)r   r+   r   r   r
  rI   FutureTimeoutErrorr0   rJ   r   r.   r2   r  r?   r   	timed_outs      r!   r   z_MultiThreadedRendezvous.resultb  s    
 [[""%%**D,=,=wI --//;;##t'9'99;;// #" [[**3355J #"s   BC)=,C))C2c                    | j                   j                  5  t        j                  | j                   j                  j                  | j                  |      }|rt        j                         | j                   j                  t
        j                  j                  u r
	 ddd       y| j                   j                  rt        j                         | cddd       S # 1 sw Y   yxY w)zvReturn the exception raised by the computation.

        See grpc.Future.exception for the full API contract.
        r    N)r   r+   r   r   r
  rI   rF  r0   rJ   r   r2   r  rG  s      r!   r   z"_MultiThreadedRendezvous.exceptionu  s    
 [[""%%**D,=,=wI --//;;##t'9'99 #" [[**3355 #""s   BC(+CC&c                 4   | j                   j                  5  t        j                  | j                   j                  j                  | j                  |      }|rt        j                         | j                   j                  t
        j                  j                  u r
	 ddd       y| j                   j                  rt        j                         	 | # t
        j                  $ r# t        j                         d   cY cddd       S w xY w# 1 sw Y   yxY w)zAccess the traceback of the exception raised by the computation.

        See grpc.future.traceback for the full API contract.
        r    Nr   )r   r+   r   r   r
  rI   rF  r0   rJ   r   r2   r  r   r   r   rG  s      r!   r   z"_MultiThreadedRendezvous.traceback  s     [[""%%**D,=,=wI --//;;##t'9'99 #" [[**33551"
== 1"||~a00 #"1 #"s0   BD(*DC*D?D
DDDr   c                    | j                   j                  5  | j                   j                  C| j                   j                  j	                  t        j                  ||              	 d d d        y 	 d d d         ||        y # 1 sw Y   xY wr   r  r  s     r!   r   z*_MultiThreadedRendezvous.add_done_callback  r  r  c                      j                   j                  5   j                   j                  t         j                    j                        } j                   j
                  j                  t        j                  j                          j                  j                  t        j                  t              f|      }|sz j                   j
                  j                  t        j                  j                         n< j                   j                  t        j                   j"                  u r
t%                 fd}t'        j(                   j                   j                  j(                  |        j                   j*                  2 j                   j*                  }d  j                   _        |cd d d        S t        j                  j                   j                   j
                  vrR j                   j                  t        j                   j"                  u r
t%                j                   j                   d d d        y # 1 sw Y   y xY w)Nc                       j                   j                  d uxsJ t        j                  j                   j                   j
                  vxr  j                   j                  d uS r   )r   r.   r   rH   r[   r,   r0   rB   s   r!   _response_readyz7_MultiThreadedRendezvous._next.<locals>._response_ready  sR    {{++47 ((88O 5((4r#   )r   r+   r0   rw   r   r,   r   r   rH   r[   r   r   r/  r   rY   rI   rJ   r   r   r   r   r.   )r?   r{   r   rN  r.   s   `    r!   r   z_MultiThreadedRendezvous._next  s   [[""{{' .KK!<!<! ##F$8$8$H$HI JJ..33LAC!	 !KKOO**6+?+?+O+OP!!T__%7%77#o%
 LL..33_E{{##/;;//'+$7 #"8 %%55T[[__L;;##t'9'99'/)[[%%1JA #""s   FI=BIIr   )!rD   rE   rF   r   r*   rG   r   r   r-   r/   rI   rJ   r0   rK   r%   r1   rL   r2   r   rs   r
  rN   r   r   rn   r   r   r   r   r   r   r   r   rO   r#   r!   r3  r3    s#    0(<"8 018L#9 1$ht/ $7# 7BHSM B)4 ), ,0d 0,d ,huo  & %  HY<O  ( *.11	%%%	&10Hdkk]D-@$A d !s !r#   r3  r   c                     t        |      }t        j                  | |      }|7t        dddt        j
                  j                  d      }t        |      }|d |fS ||d fS )NrO   r~   )r"   r   r   r*   rI   rJ   r^   r   )r   r   rz   r   r   rP   rp   s          r!   _start_unary_requestrP    sr    
 !H **74FG!OO$$,
 "%(u$$+T11r#   	with_callr   c                     | j                   t        j                  j                  u r*|rt	        | |d |      }| j
                  |fS | j
                  S t        |       r   )r0   rI   rJ   r   r3  r.   r   )rP   ry   rQ  r   
rendezvouss        r!   _end_unary_response_blockingrT    sQ     zzT__'''1%tXNJ>>:-->>!&&r#   metadatainitial_metadata_flagsc                     t        j                  | |      t        j                  t              t        j                  t              ft        j
                  t              ffS r   )r   SendInitialMetadataOperationr/  r   ReceiveStatusOnClientOperationReceiveInitialMetadataOperationrU  rV  s     r!   #_stream_unary_invocation_operationsr\    sX    
 //0 **<811,?	
 
	/	/	=?	 	r#   c                 :    t        d t        | |      D              S )Nc              3   $   K   | ]  }|d f 
 y wr   rO   ).0r   s     r!   	<genexpr>z?_stream_unary_invocation_operations_and_tags.<locals>.<genexpr>  s$      

J 	

   )tupler\  r[  s     r!   ,_stream_unary_invocation_operations_and_tagsrc     s+      
 >,
  r#   user_deadlinec                 d    t        j                         }|| y || |S | || S t        ||       S r   )r   get_deadline_from_contextmin)rd  parent_deadlines     r!   _determine_deadlineri    sM    668O=#8		$)>		"'>?M22r#   c                      e Zd ZU ej                  ed<   eed<   eed<   eed<   ee	   ed<   ee
   ed<   eed<   ee   ed<   g d	Zd
ej                  dedededee	   dee
   dee   fdZdedee   dee   dee   deej&                     deee   eeej.                        ee   eej0                     f   fdZ	 	 	 	 	 ddedee   dee   deej4                     dee   deej&                     deeej6                  f   fdZ	 	 	 	 	 ddedee   dee   deej4                     dee   deej&                     defdZ	 	 	 	 	 ddedee   dee   deej4                     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j4                     dee   deej&                     de fdZ!y)_UnaryUnaryMultiCallable_channel_managed_call_method_target_request_serializerr   _context_registered_call_handlerl  rm  rn  ro  rp  r   rq  channelmanaged_callr7   r8   rz   rU   c                     || _         || _        || _        || _        || _        || _        t        j                         | _        || _	        y r   
rl  rm  rn  ro  rp  r   r   build_census_contextrq  rr  r?   rt  ru  r7   r8   rz   rU   rr  s           r!   r@   z!_UnaryUnaryMultiCallable.__init__/  I      )#5 &;#335'>$r#   r   r   rU  wait_for_readycompressionr   c                    t        ||| j                        \  }}}t               j                  |      }	t	        j
                  ||      }
|d d d |fS t        t        d d d d       }t        j                  |
|	      t        j                  |t              t        j                  t              t        j                  t              t        j                  t              t        j                  t              f}|||d fS r   )rP  rp  _InitialMetadataFlagswith_wait_for_readyr   augment_metadatar*   _UNARY_UNARY_INITIAL_DUEr   rX  r   r   r   rZ  r/  rY  )r?   r   r   rU  r{  r|  r   r   rS  rV  augmented_metadatarP   r   s                r!   _preparez!_UnaryUnaryMultiCallable._prepareB  s     4HWd664
0$j "7!8!L!L"
 *::k
 %tZ//6dD$OE33&(> ++,>M33LA66|D..|<55lC	J *h44r#   Ncredentialsc                 <   | j                  |||||      \  }}}	}
||
t        j                         |_        t	        j
                  | j                        |_        t	        j
                  | j                        |_	        | j                  j                  t        j                  j                  | j                  d t        |	      ||d n|j                   |d ff| j"                  | j$                  	      }|j'                         }t)        ||| j*                         ||fS r   )r  r   rd   r5   r   r   rn  r7   ro  r8   rl  segregated_callr   PropagationConstantsGRPC_PROPAGATE_DEFAULTSri  _credentialsrq  rr  r+  rj   r   )r?   r   r   rU  r  r{  r|  rP   r   r   rS  ry   rT   s                r!   	_blockingz"_UnaryUnaryMultiCallable._blockingh  s    37--Wh3
/z8Z =#'#4#4#6E ">>$,,7EL">>$,,7EL==00++CC#H-#+1I1I # ,,D  OO%E%(C(CD$;r#   c                 P    | j                  ||||||      \  }}t        ||dd       S r:   r  rT  	r?   r   r   rU  r  r{  r|  rP   ry   s	            r!   __call__z!_UnaryUnaryMultiCallable.__call__  s;     NNWh^[
	
 ,E4EEr#   c                 P    | j                  ||||||      \  }}t        ||dd       S NTr  r  s	            r!   rQ  z"_UnaryUnaryMultiCallable.with_call  s;     NNWh^[
	
 ,E4tDDr#   c                    | j                  |||||      \  }}}	}
||
t        || j                        }t        j                         |_        t        j                  | j                        |_	        t        j                  | j                        |_        | j                  t        j                  j                  | j                  d |	||d n|j                   |f|| j"                  | j$                  
      }t'        ||| j                  |	      S r   )r  rw   r   r   rd   r5   r   r   rn  r7   ro  r8   rm  r   r  r  r  rq  rr  r3  )r?   r   r   rU  r  r{  r|  rP   r   r   rS  r{   ry   s                r!   futurez_UnaryUnaryMultiCallable.future  s     37--Wh3
/z8Z =*5$2M2MNM#'#4#4#6E ">>$,,7EL">>$,,7EL%%++CC#+1I1I,,D ,tT88( r#   NNNNN)"rD   rE   rF   r   ChannelrG   r   bytesr   r   r   r   rM   	__slots__r@   rN   r   rL   rI   Compressionr   r*   r	   	Operationr   r  CallCredentialsr  r  r  CallrQ  r3  r  rO   r#   r!   rk  rk    sY   nn((NN!"566$%:;;M%c]*I?? ,? 	?
 ? %%89?  ((=>? "*#?&$5$5 %$5 <(	$5
 !$5 d../$5 
&**+,	!
$5R $(+/6:)-26$$ %$ <(	$
 d223$ !$ d../$ 
y&///	0$R $(+/6:)-26FF %F <(	F
 d223F !F d../F 
F( $(+/6:)-26EE %E <(	E
 d223E !E d../E 
sDII~	E( $(+/6:)-26!! %! <(	!
 d223! !! d../! 
"!r#   rk  c                   2   e Zd ZU ej                  ed<   eed<   eed<   ee   ed<   ee	   ed<   e
ed<   ee   ed<   g dZd	ej                  d
ededede	de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fdZy)'_SingleThreadedUnaryStreamMultiCallablerl  rn  ro  rp  r   rq  rr  )rl  rn  ro  rp  r   rq  rt  r7   r8   rz   rU   c                     || _         || _        || _        || _        || _        t        j                         | _        || _        y r   )	rl  rn  ro  rp  r   r   rx  rq  rr  )r?   rt  r7   r8   rz   rU   rr  s          r!   r@   z0_SingleThreadedUnaryStreamMultiCallable.__init__  sA      #5 &;#335'>$r#   Nr   r   rU  r  r{  r|  r   c                 4   t        |      }t        j                  || j                        }|2t	        dddt
        j                  j                  d      }	t        |	      t	        t        d d d d       }	|d n|j                  }
t               j                  |      }t        j                  ||      }t        j                   ||      t        j"                  |t$              t        j&                  t$              ft        j(                  t$              ft        j*                  t$              ff}t-        d |D              }t/        j0                         |	_        t        j4                  | j6                        |	_        t        j4                  | j:                        |	_        | j>                  jA                  t        jB                  jD                  | j6                  d tG        |      ||
|| jH                  | jJ                  	      }tM        |	|| jN                  |      S )NrO   r~   c              3   $   K   | ]  }|d f 
 y wr   rO   )r_  opss     r!   r`  zC_SingleThreadedUnaryStreamMultiCallable.__call__.<locals>.<genexpr>$  s     #F:CS$K:ra  )(r"   r   r   rp  r*   rI   rJ   r^   r   _UNARY_STREAM_INITIAL_DUEr  r~  r  r   r  r   rX  r   r   r   rY  rZ  rb  r   rd   r5   r   rn  r7   ro  r8   rl  r  r  r  ri  rq  rr  r  r   )r?   r   r   rU  r  r{  r|  r   r   rP   call_credentialsrV  r  r   operations_and_tagsry   s                   r!   r  z0_SingleThreadedUnaryStreamMultiCallable.__call__  s    W%$..T--
 %((0E $E**3T4tL'D[-E-E 	 "7!8!L!L"
 *::k

 33&(> ++,>M33LA 22<@B33LAC


 $#F:#FF#002~~dll3~~dll3}},,''??LL)MM((

 )444h
 	
r#   r  )rD   rE   rF   r   r  rG   r  r   r   r   r   rM   r  r@   rN   r   rI   r  rL   r  r  r  rO   r#   r!   r  r    s   nnNN!"566$%:;;M%c]*I?? ? 	?
 0?  5? "*#?( $(+/6:)-26=
=
 %=
 <(	=

 d223=
 !=
 d../=
 
#=
r#   r  c                   @   e Zd ZU ej                  ed<   eed<   eed<   eed<   ee	   ed<   ee
   ed<   eed<   ee   ed<   g d	Zd
ej                  dededede	de
de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fdZy)_UnaryStreamMultiCallablerl  rm  rn  ro  rp  r   rq  rr  rs  rt  ru  r7   r8   rz   rU   c                     || _         || _        || _        || _        || _        || _        t        j                         | _        || _	        y r   rw  ry  s           r!   r@   z"_UnaryStreamMultiCallable.__init__M  rz  r#   Nr   r   rU  r  r{  r|  r   c                    t        ||| j                        \  }}}	t               j                  |      }
||	t	        j
                  ||      }t        t        d d d d       }t        j                  ||
      t        j                  |t              t        j                  t              t        j                  t              ft        j                  t              ff}t        j                          |_        t%        j&                  | j(                        |_        t%        j&                  | j,                        |_        | j1                  t        j2                  j4                  | j(                  d t7        |      ||d n|j8                  |t;        || j<                        | j>                  | j@                  
      }tC        ||| j<                  |      S r   )"rP  rp  r~  r  r   r  r*   r  r   rX  r   r   r   rY  rZ  r   rd   r5   r   r   rn  r7   ro  r8   rm  r  r  ri  r  rw   r   rq  rr  r3  )r?   r   r   rU  r  r{  r|  r   r   rS  rV  r  rP   r   ry   s                  r!   r  z"_UnaryStreamMultiCallable.__call__`  s    4HWd664
0$j "7!8!L!L"
 %!-!>!>+" 7tT4PE 77*,B //*L 77E99,G	 77EGJ $(#4#4#6E ">>$,,7EL">>$,,7EL%%++CC#H-#+1I1Iud&A&AB,,D ,tT88( r#   r  )rD   rE   rF   r   r  rG   r   r  r   r   r   r   rM   r  r@   rN   r   rI   r  rL   r  r3  r  rO   r#   r!   r  r  8  s   nn((NN!"566$%:;;M%c]*I?? ,? 	?
 ? 0?  5? "*#?, $(+/6:)-2644 %4 <(	4
 d2234 !4 d../4 
"4r#   r  c                      e Zd ZU ej                  ed<   eed<   eed<   eed<   ee	   ed<   ee
   ed<   eed<   ee   ed<   g d	Zd
ej                  dedededee	   dee
   dee   fdZdedee   dee   deej&                     dee   deej*                     deeej0                  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	 	 	 	 	 ddedee   dee   deej&                     dee   deej*                     deeej6                  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)_StreamUnaryMultiCallablerl  rm  rn  ro  rp  r   rq  rr  rs  rt  ru  r7   r8   rz   rU   c                     || _         || _        || _        || _        || _        || _        t        j                         | _        || _	        y r   rw  ry  s           r!   r@   z"_StreamUnaryMultiCallable.__init__  rz  r#   rx   r   rU  r  r{  r|  r   c                    t        |      }t        t        d d d d       }t               j	                  |      }	t        j                  ||      }
t        j                         |_	        t        j                  | j                        |_        t        j                  | j                        |_        | j                   j#                  t$        j&                  j(                  | j                  d t+        |      |
|d n|j,                  t/        |
|	      | j0                  | j2                  	      }t5        |||| j6                  d        	 |j9                         }|j:                  5  t=        ||| j>                         |j:                  jA                          |jB                  s	 d d d        ||fS 	 d d d        q# 1 sw Y   
xY wr   )"r"   r*   _STREAM_UNARY_INITIAL_DUEr~  r  r   r  r   rd   r5   r   r   rn  r7   ro  r8   rl  r  r   r  r  ri  r  rc  rq  rr  r   rp  r+  r+   rj   r   rm   r,   )r?   rx   r   rU  r  r{  r|  r   rP   rV  r  ry   rT   s                r!   r  z#_StreamUnaryMultiCallable._blocking  sx    W%3T4tL!6!8!L!L"
 *::k
  $002~~dll3~~dll3}},,''??LL)'D[-E-E8"$: MM((
 	"eT4+C+CT	
 OO%EeUD,G,GH**,yy	 !
 d{ ! !  s   ?F44F=Nc                 P    | j                  ||||||      \  }}t        ||dd       S r:   r  	r?   rx   r   rU  r  r{  r|  rP   ry   s	            r!   r  z"_StreamUnaryMultiCallable.__call__  s@     NN
	
 ,E4EEr#   c                 P    | j                  ||||||      \  }}t        ||dd       S r  r  r  s	            r!   rQ  z#_StreamUnaryMultiCallable.with_call  s@     NN
	
 ,E4tDDr#   c                    t        |      }t        t        d d d d       }t        || j                        }	t               j                  |      }
t        j                  ||      }t        j                         |_        t        j                  | j                        |_        t        j                  | j                         |_        | j%                  t&        j(                  j*                  | j                  d |||d n|j,                  t/        ||
      |	| j0                  | j2                  
      }t5        |||| j6                  |	       t9        ||| j                  |      S r   )r"   r*   r  rw   r   r~  r  r   r  r   rd   r5   r   r   rn  r7   ro  r8   rm  r   r  r  r  r\  rq  rr  r   rp  r3  )r?   rx   r   rU  r  r{  r|  r   rP   r{   rV  r  ry   s                r!   r  z _StreamUnaryMultiCallable.future  s<    W%3T4tL&ud.I.IJ!6!8!L!L"
 *::k
  $002~~dll3~~dll3!!''??LL'D[-E-E/0 MM((
 	"$$	
 (444h
 	
r#   r  )rD   rE   rF   r   r  rG   r   r  r   r   r   r   rM   r  r@   r   rN   r   rI   r  rL   r  r   r*   r  r  r  r  rQ  r3  r  rO   r#   r!   r  r    s   nn((NN!"566$%:;;M%c]*I?? ,? 	?
 ? %%89?  ((=>? "*#?&+"+ %+ <(	+
 d223+ !+ d../+ 
y&///	0+` $(+/6:)-26F"F %F <(	F
 d223F !F d../F 
F2 $(+/6:)-26E"E %E <(	E
 d223E !E d../E 
sDII~	E2 $(+/6:)-26,
",
 %,
 <(	,

 d223,
 !,
 d../,
 
",
r#   r  c                   L   e Zd ZU ej                  ed<   eed<   eed<   eed<   ee	   ed<   ee
   ed<   eed<   ee   ed<   g d	Zd
ej                  dedededee	   dee
   de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fdZy)_StreamStreamMultiCallablerl  rm  rn  ro  rp  r   rq  rr  rs  rt  ru  r7   r8   rz   rU   c                     || _         || _        || _        || _        || _        || _        t        j                         | _        || _	        y r   rw  ry  s           r!   r@   z#_StreamStreamMultiCallable.__init__\  rz  r#   Nrx   r   rU  r  r{  r|  r   c                 L   t        |      }t        t        d d d d       }t               j	                  |      }	t        j                  ||      }
t        j                  |
|	      t        j                  t              ft        j                  t              ff}t        || j                        }t        j                         |_        t#        j$                  | j&                        |_        t#        j$                  | j*                        |_        | j/                  t        j0                  j2                  | j&                  d t5        |      |
|d n|j6                  ||| j8                  | j:                  
      }t=        |||| j>                  |       tA        ||| j                  |      S r   )!r"   r*   _STREAM_STREAM_INITIAL_DUEr~  r  r   r  r   rX  rY  r   rZ  rw   r   r   rd   r5   r   r   rn  r7   ro  r8   rm  r  r  ri  r  rq  rr  r   rp  r3  )r?   rx   r   rU  r  r{  r|  r   rP   rV  r  r   r{   ry   s                 r!   r  z#_StreamStreamMultiCallable.__call__o  sy    W%4dD$M!6!8!L!L"
 *::k

 33&(> 55lC	 33LAC

 'ud.I.IJ#002~~dll3~~dll3!!''??LL)'D[-E-EMM((
 	"$$	
 (444h
 	
r#   r  )rD   rE   rF   r   r  rG   r   r  r   r   r   r   rM   r  r@   r   rN   r   rI   r  rL   r  r3  r  rO   r#   r!   r  r  G  s$   nn((NN!"566$%:;;M%c]*I?? ,? 	?
 ? %%89?  ((=>? "*#?, $(+/6:)-263
"3
 %3
 <(	3

 d2233
 !3
 d../3
 
"3
r#   r  c                   B     e Zd ZdZefdef fdZdee   defdZ	 xZ
S )r~  z'Stores immutable initial metadata flagsvaluec                 f    |t         j                  j                  z  }t        t        |   | |      S r   )r   InitialMetadataFlags	used_maskr   r~  __new__)clsr  r   s     r!   r  z_InitialMetadataFlags.__new__  s.    ,,666*C8eDDr#   r{  r   c                 0   ||rG| j                  | t        j                  j                  z  t        j                  j                  z        S |sH| j                  | t        j                  j                   z  t        j                  j                  z        S | S r   )r   r   r  r{  wait_for_ready_explicitly_set)r?   r{  s     r!   r  z)_InitialMetadataFlags.with_wait_for_ready  s    %~~11@@A11OOP 
 $~~F77FFFF11OOP  r#   )rD   rE   rF   r   r   rM   r  r   rL   r  r  r  s   @r!   r~  r~    s.    1". EC E(4. S r#   r~  c                   n    e Zd ZU ej                  ed<   eed<   eed<   dej                  fdZddZ	d Z
y)	_ChannelCallStatert  managed_callsr;   c                 `    t        j                         | _        || _        d| _        d| _         y )Nr   F)r;   Locklockrt  r  r?   rt  s     r!   r@   z_ChannelCallState.__init__  s&    NN$	r#   Nc                     d| _         y )Nr   )r  rB   s    r!   rC   z&_ChannelCallState.reset_postfork_child  s
    r#   c                     	 | j                   j                  t        j                  j                  d       y # t
        t        f$ r Y y w xY w)NzChannel deallocated!)rt  closer   rJ   r2   	TypeErrorAttributeErrorrB   s    r!   r  z_ChannelCallState.__del__  sD    	LL!!++-C >* 		s   47 A	A	r  )rD   rE   rF   r   r  rG   rM   rL   r@   rC   r  rO   r#   r!   r  r    s1    ^^O r#   r  c                 ~      fd}t        j                  |      }|j                  d       |j                          y )Nc                  |   	 t        j                         j                  j                         } | j                  t         j
                  j                  k(  rX| j                  |       }|rDj                  5  xj                  dz  c_	        j                  dk(  r
	 d d d        y 	 d d d        # 1 sw Y   
xY w)N   r   )
r   r   rt  next_call_eventcompletion_typeCompletionTypequeue_timeouttagr  r  )rT   call_completedrP   s     r!   channel_spinz._run_channel_spin_thread.<locals>.channel_spin  s    ,,U3MM113E$$(=(=(K(KK"YYu-NZZ''1,'**a/  Z/     Zs   9&B22B;r   Tr   )rP   r  channel_spin_threads   `  r!   _run_channel_spin_threadr    s5     !22,G!!$'r#   c                 6    dt         dt        dt        t           dt        t           dt        t
           dt        t        j                     dt        t        t        j                        dt        d	t        d
t        t            dt        j                  f fd}|S )Nflagsr7   hostr   rU  r  r   r{   contextrr  r   c
                 *   t        fd|D              }
j                  5  j                  j                  | ||||||
||		      }j                  dk(  rd_        t               nxj                  dz  c_        |cddd       S # 1 sw Y   yxY w)a  Creates a cygrpc.IntegratedCall.

        Args:
          flags: An integer bitfield of call flags.
          method: The RPC method.
          host: A host string for the created call.
          deadline: A float to be the deadline of the created call or None if
            the call is to have an infinite deadline.
          metadata: The metadata for the call or None.
          credentials: A cygrpc.CallCredentials or None.
          operations: A sequence of sequences of cygrpc.Operations to be
            started on the call.
          event_handler: A behavior to call to handle the events resultant from
            the operations on the call.
          context: Context object for distributed tracing.
          _registered_call_handle: An int representing the call handle of the
            method, or None if the method is not registered.
        Returns:
          A cygrpc.IntegratedCall with which to conduct an RPC.
        c              3   &   K   | ]  }|f 
 y wr   rO   )r_  	operationr{   s     r!   r`  zC_channel_managed_call_management.<locals>.create.<locals>.<genexpr>  s%      $

 (	  (s   r   r  N)rb  r  rt  integrated_callr  r  )r  r7   r  r   rU  r  r   r{   r  rr  r  ry   rP   s          `    r!   createz0_channel_managed_call_management.<locals>.create  s    @ $ $

 ($
 
 ZZ==00#'
D ""a'&'#(/##q(## ZZs   AB		B)rM   r  r   rK   rN   r   r   r  r	   r  r   r   r  )rP   r  s   ` r!    _channel_managed_call_managementr    s    888 sm8 5/	8
 <(8 f4458 Xf&6&6788 8 8 "*#8 
		8t Mr#   c                      e Zd ZU ej                  ed<   ej                  ed<   eed<   ej                  ed<   eed<   e
eeeej                  gdf   eej                     f         ed<   eed<   dej                  fd	Zdd
Zy)_ChannelConnectivityStater  rt  pollingconnectivitytry_to_connectNcallbacks_and_connectivities
deliveringc                     t        j                         | _        || _        d| _        d | _        d| _        g | _        d| _        y r:   )	r;   RLockr  rt  r  r  r  r  r  r  s     r!   r@   z"_ChannelConnectivityState.__init__6  s=    OO%	 #,.)r#   c                 J    d| _         d | _        d| _        g | _        d| _        y r:   )r  r  r  r  r  rB   s    r!   rC   z._ChannelConnectivityState.reset_postfork_child?  s(     #,.)r#   r  )rD   rE   rF   r;   r  rG   rI   r  rL   ChannelConnectivityr   r	   r   r   r   r@   rC   rO   r#   r!   r  r  %  s    
//\\M***"&$223T9:1124	
#      r#   r  c                     g }| j                   D ]6  }|\  }}|| j                  us|j                  |       | j                  |d<   8 |S )Nr  )r  r  r   )rP   callbacks_needing_updatecallback_and_connectivityrt   callback_connectivitys        r!   _deliveriesr  G  sa      "%*%G%G! &	
! (:(::$++H5+0+=+=%a( &H $#r#   initial_connectivityinitial_callbacksc                 B   |}|}	 |D ]   }t        j                  |        	  ||       " | j                  5  t        |       }|r| j                  }nd| _	        	 d d d        y 	 d d d        g# t        $ r t        j	                  t
               Y w xY w# 1 sw Y   2xY wr:   )
r   r   rn   r   r   0_CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGEr  r  r  r  )rP   r  r  r  r3   rt   s         r!   _deliverr  V  s    
 (L!I
!H,,U3& " ZZ#E*I$11#(  Z   
  !!D Zs   A-#B-"BBBr3   c                     t        j                  t        | | j                  |f      }|j	                  d       |j                          d| _        y N)r8   argsT)r   r   r  r  r   r   r  )rP   r3   delivering_threads      r!   _spawn_deliveryr  o  sP     00
 %Er#   rt  initial_try_to_connectc                 p   |}|j                  |      }| j                  5  t        j                  |   | _        t        d | j                  D              }| j                  D ]  }| j                  |d<    |rt        | |       d d d        	 |j                  |t        j                         dz         }t        j                  |        | j                  5  | j                  s$| j                  sd| _        d | _        	 d d d        y | j                  }d| _        d d d        |j                  s|rc|j                  |      }| j                  5  t        j                  |   | _        | j                  st!        |       }|rt        | |       d d d        # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   $xY w)Nc              3   &   K   | ]	  \  }}|  y wr   rO   )r_  rt   _s      r!   r`  z%_poll_connectivity.<locals>.<genexpr>  s      
(J1H(Js   r  g?F)check_connectivity_stater  r   1CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITYr  rb  r  r  watch_connectivity_stater   r   r   r  r  successr  r  )rP   rt  r  r  r  r3   r  rT   s           r!   _poll_connectivityr    s   
 ,N33NCL	EE 	
  
(-(J(J
 
	 */)K)K%+0+=+=%a( *LE9- 
 00$))++
 	((/ZZ66,, %%)" Z #11N#(E   ==N";;NKLMM$ "
 '' +E 2I 'y9 #  
$ Z s*   A#F(F F >F,F F),F5rt   r  c           	         | j                   5  | j                  s| j                  swt        j                  t
        | | j                  t        |      f      }|j                  d       |j                          d| _        | j                  j                  |d g       n| j                  s_| j                  St        | |f       | xj                  t        |      z  c_        | j                  j                  || j                  g       n;| xj                  t        |      z  c_        | j                  j                  |d g       d d d        y # 1 sw Y   y xY wr  )r  r  r  r   r   r  rt  rL   r   r   r   r  r  r  r  )rP   rt   r  polling_threads       r!   
_subscriber    s   
 
11%--#55)U]]D,@AN $$T*  " EM..55x6FG!!e&8&8&DEH;/  D$88 ..555--.   D$88 ..55x6FG% 
s   D6EEc                     | j                   5  t        | j                        D ]*  \  }\  }}||k(  s| j                  j                  |        n d d d        y # 1 sw Y   y xY wr   )r  	enumerater  pop)rP   rt   indexsubscribed_callbackunused_connectivitys        r!   _unsubscriber    s]     
AJ..B
=E=')< ..2266u=B
 
s   $AAA"base_optionsr|  c                     t        j                  |      }t        |       |z   t        j                  j
                  t        ffz   S r   )r   create_channel_optionrb  r   ChannelArgKeyprimary_user_agent_string_USER_AGENT)r  r|  compression_options      r!   _augment_optionsr    sM     &;;KHl
	 $$>>
	
	r#   optionsc                     g }g }| D ]O  }|d   t         j                  j                  j                  k(  r|j	                  |       ?|j	                  |       Q ||fS )z;Separates core channel options from Python channel options.r   )rI   r  ChannelOptionsSingleThreadedUnaryStreamr   )r  core_optionspython_optionspairs       r!   _separate_channel_optionsr    se     LNG  //IIJ !!$'%  <''r#   c                      e Zd ZU dZeed<   ej                  ed<   eed<   e	ed<   e
ed<   ee
ef   ed<   de
d	ee   d
eej"                     deej$                     fdZde
defdZdee   ddfdZ	 d%deej.                  gdf   dee   ddfdZdeej.                  gdf   ddfdZ	 	 	 d&de
dee   dee   dee   dej8                  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jD                  f
dZ#d'dZ$d'dZ%d'd Z&d! Z'd" Z(d'd#Z)d$ Z*y)(r  z7A cygrpc.Channel-backed implementation of grpc.Channel._single_threaded_unary_streamrl  _call_state_connectivity_statero  _registered_call_handlesr8   r  r  r|  c                    t        |      \  }}t        | _        | j                  |       t	        j
                  t        j                  |      t        ||      |      | _	        || _
        t        | j                        | _        t        | j                        | _        t	        j                  |        t        j                   rt	        j"                          yy)aP  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.
        N)r  %_DEFAULT_SINGLE_THREADED_UNARY_STREAMr  _process_python_optionsr   r  r   encoder  rl  ro  r  r   r  r!  fork_register_channelg_gevent_activatedgevent_increment_channel_count)r?   r8   r  r  r|  r  r  s          r!   r@   zChannel.__init__  s      (A'I$1 	* 	$$^4NN6"\;7

 ,T]];#<T]]#K $$T*$$113 %r#   r7   r   c                 ^    | j                   j                  t        j                  |            S )ah  
        Get the registered call handle for a method.

        This is a semi-private method. It is intended for use only by gRPC generated code.

        This method is not thread-safe.

        Args:
          method: Required, the method name for the RPC.

        Returns:
          The registered call handle pointer in the form of a Python Long.
        )rl  get_registered_call_handler   r&  )r?   r7   s     r!   _get_registered_call_handlez#Channel._get_registered_call_handle&  s"     }}77v8NOOr#   r  Nc                 v    |D ]4  }|d   t         j                  j                  j                  k(  s.d| _        6 y)zASets channel attributes according to python-only channel options.r   TN)rI   r  r  r  r  )r?   r  r  s      r!   r%  zChannel._process_python_options6  s:     #DQ$$33MMN 6:2 #r#   rt   r  c                 2    t        | j                  ||       y r   )r  r!  )r?   rt   r  s      r!   	subscribezChannel.subscribeA  s    
 	4++X~Fr#   c                 0    t        | j                  |       y r   )r  r!  r   s     r!   unsubscribezChannel.unsubscribeH  s     	T--x8r#   rz   rU   _registered_methodc           	          d }|r| j                  |      }t        | j                  t        | j                        t        j                  |      t        j                  | j                        |||      S r   )r,  rk  rl  r  r   r   r&  ro  r?   r7   rz   rU   r2  rr  s         r!   unary_unaryzChannel.unary_unaryN  se     #'&*&F&Fv&N#'MM,T-=-=>NN6"NN4<<(!#
 	
r#   c           	         d }|r| j                  |      }| j                  rJt        | j                  t	        j
                  |      t	        j
                  | j                        |||      S t        | j                  t        | j                        t	        j
                  |      t	        j
                  | j                        |||      S r   )
r,  r  r  rl  r   r&  ro  r  r  r   r4  s         r!   unary_streamzChannel.unary_streamc  s     #'&*&F&Fv&N#
 --:v&t||,"%'  -01A1ABv&t||,"%' r#   c           	          d }|r| j                  |      }t        | j                  t        | j                        t        j                  |      t        j                  | j                        |||      S r   )r,  r  rl  r  r   r   r&  ro  r4  s         r!   stream_unaryzChannel.stream_unary  se     #'&*&F&Fv&N#(MM,T-=-=>NN6"NN4<<(!#
 	
r#   c           	          d }|r| j                  |      }t        | j                  t        | j                        t        j                  |      t        j                  | j                        |||      S r   )r,  r  rl  r  r   r   r&  ro  r4  s         r!   stream_streamzChannel.stream_stream  se     #'&*&F&Fv&N#)MM,T-=-=>NN6"NN4<<(!#
 	
r#   c                     | j                   }|r%|j                  5  |j                  d d = d d d        y y # 1 sw Y   y xY wr   )r!  r  r  r   s     r!   _unsubscribe_allzChannel._unsubscribe_all  s7    ((66q9  s   5>c                     | j                          | j                  j                  t        j                  j
                  d       t        j                  |        t        j                  rt        j                          y y )NzChannel closed!)	r=  rl  r  r   rJ   r2   fork_unregister_channelr(  gevent_decrement_channel_countrB   s    r!   _closezChannel._close  sW    F--779JK&&t,$$113 %r#   c                     | j                          | j                  j                  t        j                  j
                  d       y )NzChannel closed due to fork)r=  rl  close_on_forkr   rJ   r2   rB   s    r!   _close_on_forkzChannel._close_on_fork  s2    ##'')E	
r#   c                     | S r   rO   rB   s    r!   	__enter__zChannel.__enter__  r   r#   c                 $    | j                          yr:   rA  )r?   exc_typeexc_valexc_tbs       r!   __exit__zChannel.__exit__  s    r#   c                 $    | j                          y r   rH  rB   s    r!   r  zChannel.close  s    r#   c                 4    	 | j                          y #  Y y xY wr   )r=  rB   s    r!   r  zChannel.__del__  s    	!!#	 s    r   )NNFr  )+rD   rE   rF   r   rL   rG   r   r  r  r  rK   r   rM   r	   r   r   rI   ChannelCredentialsr  r@   r,  r%  r   r  r/  r1  r   r   UnaryUnaryMultiCallabler5  UnaryStreamMultiCallabler7  StreamUnaryMultiCallabler9  StreamStreamMultiCallabler;  r=  rA  rD  rF  rL  r  r  rO   r#   r!   r  r    s   A#''nn""22L"38n,44 -.4 d556	4
 d../4BP# P# P 	:&':;	:		: *.GD445t;<G !G 
	G9 $":":!;T!AB9	9 =AAE-2

 %%89
  ((=>	

 %TN
 
	%	%
0 =AAE-2   %%89   ((=>	 
 %TN  
	&	& L =AAE-2

 %%89
  ((=>	

 %TN
 
	&	&
0 =AAE-2

 %%89
  ((=>	

 %TN
 
	'	'
(:4
r#   r  )ur   r   r   ro   osr   r;   r   r   typingr   r   r   r   r   r   r	   r
   r   r   rI   r   r   r   r   grpc._cythonr   grpc._typingr   r   r   r   r   r   r   r   grpc.experimental	getLoggerrD   r   r'   __version__r  r   getenvr$  rH   send_initial_metadatar   r   rZ   r[   r_   r  r  r  r  r  r   r   rN   r"   rJ   rK   r(   objectr*   rS   r1  rj   rw   r  r  r   r   r   r  r   r   
RpcContextr   r  r3  r  rP  rL   rT  rM   r  r\  rc  ri  rP  rk  rQ  r  r  rR  r  rS  r  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rO   r#   r!   <module>r_     sb   5    	 
         !   , . . % , % ,   
'

H
%%%&6&B&BC
 BII12$> &
 ..
%%
//
11
((
11  ..
%%
//
11
11  ..
11
((
11	  ..
11
11  7 1
 K 
 >x >8E? >!$//2=Ec]:/ :/z%) %4?? %S %T %))) $$9:) 

	)X-56K-L0\\\ %%v'<'<<
=\ ,	\
 G$\ 
\~# )  $[tyy$++ [|h3$-- h3VSBDKKSBlvDKKvr22e_2 ,2 8E?HUOXdmm-DDE	2*''


' ' uo	'
 <|TYY6778' |$>Ahv''()|$>AeHV--.0AABC	3x 	38E? 	3wt;; wta
d.K.K a
H\ = = \~m
 = = m
`[
!?!? [
|C . . $5  $  &<,= <~   D$$$	(D,,-t3
45$$22  $*B*B)CT)I JK 
	2$$":":!;T!ABC 
$.:$.:\\.: !.: 
	.:bH$H001478H H 
	H4
$
001478
 

./$**+ !""()*(
8'((3F*GGH("`dll `r#   