
    &`i3                     t    d dl mZmZmZmZmZ d dlZd dlmZ  ed           G d d                      Z	dS )    )AnyDictListOptionalTupleN)	PublicAPIbeta)	stabilityc                      e Zd ZdZdej        j        j        fdZde	e
ef         fdZdej        fdZde
fdZdeee
e
f                  fdZde
fd	Zdee         fd
Zdee
         fdZdeee
e
f                  fdZdej        fdZdej        fdZde
fdZdeee
e
f                  fdZdeee
e
f                  fdZdej        j        j        fdZdS )RayServegRPCContexta  Context manager to set and get gRPC context.

    This class implements most of the methods from ServicerContext
    (see: https://grpc.github.io/grpc/python/grpc.html#grpc.ServicerContext). It's
    serializable and can be passed with the request to be used on the deployment.
    grpc_contextc                    |                                 | _        |                                | _        |                                | _        d |                                D             | _        |                                | _	        |
                                | _        |                                | _        d |                                D             | _        d | _        d S )Nc                     g | ]	\  }}||f
S  r   .0keyvalues      g/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/grpc_util.py
<listcomp>z0RayServegRPCContext.__init__.<locals>.<listcomp>   s-     %
 %
 %
'S%S%L%
 %
 %
    c                     g | ]	\  }}||f
S r   r   r   s      r   r   z0RayServegRPCContext.__init__.<locals>.<listcomp>   s-     #
 #
 #
'S%S%L#
 #
 #
r   )auth_context_auth_contextcode_codedetails_detailsinvocation_metadata_invocation_metadatapeer_peerpeer_identities_peer_identitiespeer_identity_key_peer_identity_keytrailing_metadata_trailing_metadata_compressionselfr   s     r   __init__zRayServegRPCContext.__init__   s    )6688!&&((
$,,..%
 %
+7+K+K+M+M%
 %
 %
! "&&((
 , < < > >"."@"@"B"B#
 #
+7+I+I+K+K#
 #
 #
 !r   returnc                     | j         S )zGets the auth context for the call.

        Returns:
          A map of strings to an iterable of bytes for each auth property.
        )r   r+   s    r   r   z RayServegRPCContext.auth_context    s     !!r   c                     | j         S )zAccesses the value to be used as status code upon RPC completion.

        Returns:
          The StatusCode value for the RPC.
        r   r/   s    r   r   zRayServegRPCContext.code(   s     zr   c                     | j         S )zAccesses the value to be used as detail string upon RPC completion.

        Returns:
          The details string of the RPC.
        r   r/   s    r   r   zRayServegRPCContext.details0   s     }r   c                     | j         S )zoAccesses the metadata sent by the client.

        Returns:
          The invocation :term:`metadata`.
        )r    r/   s    r   r   z'RayServegRPCContext.invocation_metadata8   s     ((r   c                     | j         S )zIdentifies the peer that invoked the RPC being serviced.

        Returns:
          A string identifying the peer that invoked the RPC being serviced.
          The string format is determined by gRPC runtime.
        )r"   r/   s    r   r!   zRayServegRPCContext.peer@   s     zr   c                     | j         S )a2  Gets one or more peer identity(s).

        Equivalent to
        servicer_context.auth_context().get(servicer_context.peer_identity_key())

        Returns:
          An iterable of the identities, or None if the call is not
          authenticated. Each identity is returned as a raw bytes type.
        )r$   r/   s    r   r#   z#RayServegRPCContext.peer_identitiesI   s     $$r   c                     | j         S )a8  The auth property used to identify the peer.

        For example, "x509_common_name" or "x509_subject_alternative_name" are
        used to identify an SSL peer.

        Returns:
          The auth property (string) that indicates the
          peer identity, or None if the call is not authenticated.
        )r&   r/   s    r   r%   z%RayServegRPCContext.peer_identity_keyU   s     &&r   c                     | j         S )Nr(   r/   s    r   r'   z%RayServegRPCContext.trailing_metadataa   s    &&r   r   c                     || _         dS )a$  Sets the value to be used as status code upon RPC completion.

        This method need not be called by method implementations if they wish
        the gRPC runtime to determine the status code of the RPC.

        Args:
          code: A StatusCode object to be sent to the client.
        Nr1   )r+   r   s     r   set_codezRayServegRPCContext.set_coded   s     


r   compressionc                     || _         dS )zSet the compression algorithm to be used for the entire call.

        Args:
          compression: An element of grpc.compression, e.g.
            grpc.compression.Gzip.
        N)r)   )r+   r<   s     r   set_compressionz#RayServegRPCContext.set_compressiono   s     (r   r   c                     || _         dS )a4  Sets the value to be used as detail string upon RPC completion.

        Calling this method is only needed if method implementations have
        details to transmit.

        Args:
          details: A UTF-8-encodable string to be sent to the client upon
                   termination of the RPC.
        Nr3   )r+   r   s     r   set_detailszRayServegRPCContext.set_detailsx   s      r   c                 :    | j         D ]\  }}|dk    r||fgc S g S )N
request_idr9   )r+   r   r   s      r   _request_id_metadataz(RayServegRPCContext._request_id_metadata   sA     1 	& 	&JCl""e~%%% #	r   r'   c                 >    |                                  |z   | _        dS )a  Sets the trailing metadata for the RPC.

        Sets the trailing metadata to be sent upon completion of the RPC.

        If this method is invoked multiple times throughout the lifetime of an
        RPC, the value supplied in the final invocation + request id will be the value
        sent over the wire.

        This method need not be called by implementations if they have no
        metadata to add to what the gRPC runtime will transmit.

        Args:
          trailing_metadata: The trailing :term:`metadata`.
        N)rC   r(   )r+   r'   s     r   set_trailing_metadataz)RayServegRPCContext.set_trailing_metadata   s$     #'";";"="=@Q"Qr   c                    | j         r|                    | j                    | j        r|                    | j                   | j        r|                    | j                   | j        r|                    | j                   dS dS )z>Serve's internal method to set attributes on the gRPC context.N)r   r;   r)   r>   r   r@   r(   rE   r*   s     r   _set_on_grpc_contextz(RayServegRPCContext._set_on_grpc_context   s    : 	.!!$*--- 	<(():;;;= 	4$$T]333" 	H..t/FGGGGG	H 	Hr   N) __name__
__module____qualname____doc__grpc_cythoncygrpc_ServicerContextr,   r   strr   r   
StatusCoder   r   r   r   r   r!   r   bytesr#   r%   r'   r;   Compressionr>   r@   rC   rE   rG   r   r   r   r   r      s        !T\%8%I ! ! ! !"d38n " " " "do        )T%S/%: ) ) ) )c    
%% 
% 
% 
% 
%
'8C= 
' 
' 
' 
''4c3h#8 ' ' ' '	T_ 	 	 	 	(4+; ( ( ( (
 3 
  
  
  
 d5c?&;    RtE#s(O7L R R R R"H1D1U H H H H H Hr   r   )
typingr   r   r   r   r   rL   ray.util.annotationsr   r   r   r   r   <module>rV      s    3 3 3 3 3 3 3 3 3 3 3 3 3 3  * * * * * * V`H `H `H `H `H `H `H `H `H `Hr   