
    Ag                     b   d 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	 ddl
Z
ddl
mZ ddlmZ  ej                  e      ZdZ G d d ej$                  d	d
      e
j&                        Z G d de
j(                        Z G d de
j,                        Zde
j0                  defdZdededefdZy)z#Internal utilities for gRPC Python.    N)CallableDictOptionalSequence)_common)DoneCallbackTypez6Exception calling connectivity future "done" callback!c                       e Zd Zy)RpcMethodHandlerN)__name__
__module____qualname__     D/var/www/openai/venv/lib/python3.12/site-packages/grpc/_utilities.pyr
   r
   !   s      	r   r
   _RpcMethodHandler)request_streamingresponse_streamingrequest_deserializerresponse_serializerunary_unaryunary_streamstream_unarystream_streamc                       e Zd ZU eed<   eeej                  f   ed<   dedeeej                  f   fdZdefdZ	dej                  deej                     fd	Zy
)DictionaryGenericHandler_name_method_handlersservicemethod_handlersc                     || _         |j                         D ci c]  \  }}t        j                  ||      | c}}| _        y c c}}w N)r   itemsr   fully_qualified_methodr   )selfr   r   methodmethod_handlers        r   __init__z!DictionaryGenericHandler.__init__8   sR     
 +:*?*?*A!
*A& **7F;^K*A!
 !
s   !Areturnc                     | j                   S r!   )r   r$   s    r   service_namez%DictionaryGenericHandler.service_nameA   s    zzr   handler_call_detailsc                 P    |j                   }| j                  j                  |      S r!   )r%   r   get)r$   r,   details_methods      r   r   z DictionaryGenericHandler.serviceD   s+     .44$$((
 	
r   N)r   r   r   str__annotations__r   grpcr
   r'   r+   HandlerCallDetailsr   r   r   r   r   r   r   4   st    J3 5 5566

-1#t7L7L2L-M
c 
$($;$;
	$''	(
r   r   c                   ^   e Zd ZU ej                  ed<   ej                  ed<   eed<   eed<   e	e
   ed<   dej                  fdZdee   d	d
fdZdeej                     d	d
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	d
fdZddee   d	d
fdZddee   d	d
fdZdefdZd Zd Zy
)_ChannelReadyFuture
_condition_channel_matured
_cancelled_done_callbackschannelc                 n    t        j                         | _        || _        d| _        d| _        g | _        y )NF)	threading	Conditionr6   r7   r8   r9   r:   )r$   r;   s     r   r'   z_ChannelReadyFuture.__init__T   s/    #--/!r   timeoutr(   Nc                    |d nt        j                          |z   }| j                  5  	 | j                  rt        j                         | j
                  r
	 d d d        y || j                  j                          nL|t        j                          z
  }|dk  rt        j                         | j                  j                  |       # 1 sw Y   y xY w)Nr   )r?   )timer6   r9   r2   FutureCancelledErrorr8   waitFutureTimeoutError)r$   r?   until	remainings       r   _blockz_ChannelReadyFuture._block\   s    TYY[7-B__??3355]] _ },,.$)DIIK$7	$q="&"9"9";; OO000C  _s   /C
 A*C

Cconnectivityc                    | j                   5  | j                  s|t        j                  j                  u rcd| _        | j                  j                  | j                         | j                   j                          t        | j                        }d | _        n
	 d d d        y 	 d d d        D ]  }	  ||         y # 1 sw Y   xY w# t        $ r t        j                  t               Y ?w xY w)NT)r6   r9   r2   ChannelConnectivityREADYr8   r7   unsubscribe_update
notify_alltupler:   	Exception_LOGGER	exception$_DONE_CALLBACK_EXCEPTION_LOG_MESSAGE)r$   rH   done_callbacksdone_callbacks       r   rM   z_ChannelReadyFuture._updaten   s    __OO D$<$<$B$BB $))$,,7**,!&t';';!<'+$ _ %  ,MHd# , _   H!!"FGHs   BB=2C	=C	"C.-C.c                    | j                   5  | j                  scd| _        | j                  j	                  | j
                         | j                   j                          t        | j                        }d | _        n
	 d d d        y	 d d d        D ]  }	  ||         y# 1 sw Y   xY w# t        $ r t        j                  t               Y ?w xY w)NTF)r6   r8   r9   r7   rL   rM   rN   rO   r:   rP   rQ   rR   rS   )r$   rT   rU   s      r   cancelz_ChannelReadyFuture.cancel   s    __=="&))$,,7**,!&t';';!<'+$ _ %  ,MHd# , ! _  H!!"FGHs   A1B!B-!B*-"CCc                 ^    | j                   5  | j                  cd d d        S # 1 sw Y   y xY wr!   )r6   r9   r*   s    r   	cancelledz_ChannelReadyFuture.cancelled   s    __?? __s   #,c                 ~    | j                   5  | j                   xr | j                   cd d d        S # 1 sw Y   y xY wr!   r6   r9   r8   r*   s    r   runningz_ChannelReadyFuture.running   s)    __&<t}}+< __s   3<c                 z    | j                   5  | j                  xs | j                  cd d d        S # 1 sw Y   y xY wr!   r[   r*   s    r   donez_ChannelReadyFuture.done   s#    __??3dmm __s   1:c                 &    | j                  |       y r!   rG   r$   r?   s     r   resultz_ChannelReadyFuture.result       Gr   c                 &    | j                  |       y r!   r`   ra   s     r   rR   z_ChannelReadyFuture.exception   rc   r   c                 &    | j                  |       y r!   r`   ra   s     r   	tracebackz_ChannelReadyFuture.traceback   rc   r   fnc                     | j                   5  | j                  s1| j                  s%| j                  j	                  |       	 d d d        y d d d         ||        y # 1 sw Y   xY wr!   )r6   r9   r8   r:   append)r$   rg   s     r   add_done_callbackz%_ChannelReadyFuture.add_done_callback   sG    __??4==$$++B/ __
 	4 _s   5AA%c                     | j                   5  | j                  j                  | j                  d       d d d        y # 1 sw Y   y xY w)NT)try_to_connect)r6   r7   	subscriberM   r*   s    r   startz_ChannelReadyFuture.start   s.    __MM##DLL#F __s	   (>Ac                     | j                   5  | j                  s1| j                  s%| j                  j	                  | j
                         d d d        y # 1 sw Y   y xY wr!   )r6   r9   r8   r7   rL   rM   r*   s    r   __del__z_ChannelReadyFuture.__del__   s6    __??4==))$,,7 __s   >AAr!   )r   r   r   r=   r>   r1   r2   Channelboolr   r   r'   r   floatrG   rJ   rM   rW   rY   r\   r^   rb   rR   rf   r   rj   rn   rp   r   r   r   r5   r5   M   s   ###llNh''" "Dhuo D$ D$HHT-E-E$F H4 H( &#4 #= =4d 4huo  % D % D $4 G8r   r5   r;   r(   c                 <    t        |       }|j                          |S r!   )r5   rn   )r;   ready_futures     r   channel_ready_futurerv      s    &w/Lr   version1version2c                 2   | j                  d      }|j                  d      }	 t        d      D ]@  }t        ||         t        ||         k  r yt        ||         t        ||         kD  s@ y 	 t	        |      t	        |      k  S # t        $ r Y yw xY w)a  
    Compares two versions in the format '1.60.1' or '1.60.1.dev0'.

    This method will be used in all stubs generated by grpcio-tools to check whether
    the stub version is compatible with the runtime grpcio.

    Args:
        version1: The first version string.
        version2: The second version string.

    Returns:
        True if version1 is lower, False otherwise.
    .   TF)splitrangeint
ValueErrorlen)rw   rx   version1_listversion2_listis        r   first_version_is_lowerr      s     NN3'MNN3'MqA=#$s=+;'<<]1%&]1-=)>>	  }M 222  s#   ,B
 B
 /B
 1B
 
	BB)__doc__collectionsloggingr=   rA   typingr   r   r   r   r2   r   grpc._typingr   	getLoggerr   rQ   rS   
namedtupler
   ServiceRpcHandlerr   Futurer5   rq   rv   r0   rr   r   r   r   r   <module>r      s    *     5 5   )
'

H
% = %
	K		
 		&
t55 
2l8$++ l8^$,, 3F 3S 3C 3D 3r   