Public Member Functions | Private Member Functions | Private Attributes | List of all members
grpc._server._Context Class Reference
Inheritance diagram for grpc._server._Context:
Inheritance graph
[legend]

Public Member Functions

def __init__ (self, rpc_event, state, request_deserializer)
 
def abort (self, code, details)
 
def abort_with_status (self, status)
 
def add_callback (self, callback)
 
def auth_context (self)
 
def cancel (self)
 
def code (self)
 
def details (self)
 
def disable_next_message_compression (self)
 
def invocation_metadata (self)
 
def is_active (self)
 
def peer (self)
 
def peer_identities (self)
 
def peer_identity_key (self)
 
def send_initial_metadata (self, initial_metadata)
 
def set_code (self, code)
 
def set_compression (self, compression)
 
def set_details (self, details)
 
def set_trailing_metadata (self, trailing_metadata)
 
def time_remaining (self)
 
def trailing_metadata (self)
 

Private Member Functions

def _finalize_state (self)
 

Private Attributes

 _request_deserializer
 
 _rpc_event
 
 _state
 

Detailed Description

Definition at line 236 of file grpc/_server.py.

Constructor & Destructor Documentation

◆ __init__()

def grpc._server._Context.__init__ (   self,
  rpc_event,
  state,
  request_deserializer 
)

Definition at line 238 of file grpc/_server.py.

Member Function Documentation

◆ _finalize_state()

def grpc._server._Context._finalize_state (   self)
private

Definition at line 341 of file grpc/_server.py.

◆ abort()

def grpc._server._Context.abort (   self,
  code,
  details 
)
Raises an exception to terminate the RPC with a non-OK status.

The code and details passed as arguments will supercede any existing
ones.

Args:
  code: A StatusCode object to be sent to the client.
    It must not be StatusCode.OK.
  details: A UTF-8-encodable string to be sent to the client upon
    termination of the RPC.

Raises:
  Exception: An exception is always raised to signal the abortion the
    RPC to the gRPC runtime.

Reimplemented from grpc.ServicerContext.

Definition at line 310 of file grpc/_server.py.

◆ abort_with_status()

def grpc._server._Context.abort_with_status (   self,
  status 
)
Raises an exception to terminate the RPC with a non-OK status.

The status passed as argument will supercede any existing status code,
status message and trailing metadata.

This is an EXPERIMENTAL API.

Args:
  status: A grpc.Status object. The status code in it must not be
    StatusCode.OK.

Raises:
  Exception: An exception is always raised to signal the abortion the
    RPC to the gRPC runtime.

Reimplemented from grpc.ServicerContext.

Definition at line 323 of file grpc/_server.py.

◆ add_callback()

def grpc._server._Context.add_callback (   self,
  callback 
)
Registers a callback to be called on RPC termination.

Args:
  callback: A no-parameter callable to be called on RPC termination.

Returns:
  True if the callback was added and will be called later; False if
    the callback was not added and will not be called (because the RPC
    already terminated or some other reason).

Reimplemented from grpc.RpcContext.

Definition at line 253 of file grpc/_server.py.

◆ auth_context()

def grpc._server._Context.auth_context (   self)
Gets the auth context for the call.

Returns:
  A map of strings to an iterable of bytes for each auth property.

Reimplemented from grpc.ServicerContext.

Definition at line 278 of file grpc/_server.py.

◆ cancel()

def grpc._server._Context.cancel (   self)
Cancels the RPC.

Idempotent and has no effect if the RPC has already terminated.

Reimplemented from grpc.RpcContext.

Definition at line 250 of file grpc/_server.py.

◆ code()

def grpc._server._Context.code (   self)
Accesses the value to be used as status code upon RPC completion.

This is an EXPERIMENTAL API.

Returns:
  The StatusCode value for the RPC.

Reimplemented from grpc.ServicerContext.

Definition at line 331 of file grpc/_server.py.

◆ details()

def grpc._server._Context.details (   self)
Accesses the value to be used as detail string upon RPC completion.

This is an EXPERIMENTAL API.

Returns:
  The details string of the RPC.

Reimplemented from grpc.ServicerContext.

Definition at line 338 of file grpc/_server.py.

◆ disable_next_message_compression()

def grpc._server._Context.disable_next_message_compression (   self)
Disables compression for the next response message.

This is an EXPERIMENTAL method.

This method will override any compression configuration set during
server creation or set on the call.

Reimplemented from grpc.ServicerContext.

Definition at line 261 of file grpc/_server.py.

◆ invocation_metadata()

def grpc._server._Context.invocation_metadata (   self)
Accesses the metadata from the sent by the client.

Returns:
  The invocation :term:`metadata`.

Reimplemented from grpc.ServicerContext.

Definition at line 265 of file grpc/_server.py.

◆ is_active()

def grpc._server._Context.is_active (   self)
Describes whether the RPC is active or has terminated.

Returns:
  bool:
  True if RPC is active, False otherwise.

Reimplemented from grpc.RpcContext.

Definition at line 243 of file grpc/_server.py.

◆ peer()

def grpc._server._Context.peer (   self)
Identifies 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.

Reimplemented from grpc.ServicerContext.

Definition at line 268 of file grpc/_server.py.

◆ peer_identities()

def grpc._server._Context.peer_identities (   self)
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.

Reimplemented from grpc.ServicerContext.

Definition at line 271 of file grpc/_server.py.

◆ peer_identity_key()

def grpc._server._Context.peer_identity_key (   self)
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.

Reimplemented from grpc.ServicerContext.

Definition at line 274 of file grpc/_server.py.

◆ send_initial_metadata()

def grpc._server._Context.send_initial_metadata (   self,
  initial_metadata 
)
Sends the initial metadata value to the client.

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

Args:
  initial_metadata: The initial :term:`metadata`.

Reimplemented from grpc.ServicerContext.

Definition at line 288 of file grpc/_server.py.

◆ set_code()

def grpc._server._Context.set_code (   self,
  code 
)
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.

Reimplemented from grpc.ServicerContext.

Definition at line 327 of file grpc/_server.py.

◆ set_compression()

def grpc._server._Context.set_compression (   self,
  compression 
)
Set the compression algorithm to be used for the entire call.

This is an EXPERIMENTAL method.

Args:
  compression: An element of grpc.compression, e.g.
    grpc.compression.Gzip.

Reimplemented from grpc.ServicerContext.

Definition at line 284 of file grpc/_server.py.

◆ set_details()

def grpc._server._Context.set_details (   self,
  details 
)
Sets the value to be used as detail string upon RPC completion.

This method need not be called by method implementations if they have
no details to transmit.

Args:
  details: A UTF-8-encodable string to be sent to the client upon
    termination of the RPC.

Reimplemented from grpc.ServicerContext.

Definition at line 334 of file grpc/_server.py.

◆ set_trailing_metadata()

def grpc._server._Context.set_trailing_metadata (   self,
  trailing_metadata 
)
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 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`.

Reimplemented from grpc.ServicerContext.

Definition at line 303 of file grpc/_server.py.

◆ time_remaining()

def grpc._server._Context.time_remaining (   self)
Describes the length of allowed time remaining for the RPC.

Returns:
  A nonnegative float indicating the length of allowed time in seconds
  remaining for the RPC to complete before it is considered to have
  timed out, or None if no deadline was specified for the RPC.

Reimplemented from grpc.RpcContext.

Definition at line 247 of file grpc/_server.py.

◆ trailing_metadata()

def grpc._server._Context.trailing_metadata (   self)
Access value to be used as trailing metadata upon RPC completion.

This is an EXPERIMENTAL API.

Returns:
  The trailing :term:`metadata` for the RPC.

Reimplemented from grpc.ServicerContext.

Definition at line 307 of file grpc/_server.py.

Member Data Documentation

◆ _request_deserializer

grpc._server._Context._request_deserializer
private

Definition at line 241 of file grpc/_server.py.

◆ _rpc_event

grpc._server._Context._rpc_event
private

Definition at line 239 of file grpc/_server.py.

◆ _state

grpc._server._Context._state
private

Definition at line 240 of file grpc/_server.py.


The documentation for this class was generated from the following file:


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:32