Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/grpc/beta/interfaces.py
7783 views
# Copyright 2015 gRPC authors.1#2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# See the License for the specific language governing permissions and12# limitations under the License.13"""Constants and interfaces of the Beta API of gRPC Python."""1415import abc1617import grpc18import six1920ChannelConnectivity = grpc.ChannelConnectivity21# FATAL_FAILURE was a Beta-API name for SHUTDOWN22ChannelConnectivity.FATAL_FAILURE = ChannelConnectivity.SHUTDOWN2324StatusCode = grpc.StatusCode252627class GRPCCallOptions(object):28"""A value encapsulating gRPC-specific options passed on RPC invocation.2930This class and its instances have no supported interface - it exists to31define the type of its instances and its instances exist to be passed to32other functions.33"""3435def __init__(self, disable_compression, subcall_of, credentials):36self.disable_compression = disable_compression37self.subcall_of = subcall_of38self.credentials = credentials394041def grpc_call_options(disable_compression=False, credentials=None):42"""Creates a GRPCCallOptions value to be passed at RPC invocation.4344All parameters are optional and should always be passed by keyword.4546Args:47disable_compression: A boolean indicating whether or not compression should48be disabled for the request object of the RPC. Only valid for49request-unary RPCs.50credentials: A CallCredentials object to use for the invoked RPC.51"""52return GRPCCallOptions(disable_compression, None, credentials)535455GRPCAuthMetadataContext = grpc.AuthMetadataContext56GRPCAuthMetadataPluginCallback = grpc.AuthMetadataPluginCallback57GRPCAuthMetadataPlugin = grpc.AuthMetadataPlugin585960class GRPCServicerContext(six.with_metaclass(abc.ABCMeta)):61"""Exposes gRPC-specific options and behaviors to code servicing RPCs."""6263@abc.abstractmethod64def peer(self):65"""Identifies the peer that invoked the RPC being serviced.6667Returns:68A string identifying the peer that invoked the RPC being serviced.69"""70raise NotImplementedError()7172@abc.abstractmethod73def disable_next_response_compression(self):74"""Disables compression of the next response passed by the application."""75raise NotImplementedError()767778class GRPCInvocationContext(six.with_metaclass(abc.ABCMeta)):79"""Exposes gRPC-specific options and behaviors to code invoking RPCs."""8081@abc.abstractmethod82def disable_next_request_compression(self):83"""Disables compression of the next request passed by the application."""84raise NotImplementedError()858687class Server(six.with_metaclass(abc.ABCMeta)):88"""Services RPCs."""8990@abc.abstractmethod91def add_insecure_port(self, address):92"""Reserves a port for insecure RPC service once this Server becomes active.9394This method may only be called before calling this Server's start method is95called.9697Args:98address: The address for which to open a port.99100Returns:101An integer port on which RPCs will be serviced after this link has been102started. This is typically the same number as the port number contained103in the passed address, but will likely be different if the port number104contained in the passed address was zero.105"""106raise NotImplementedError()107108@abc.abstractmethod109def add_secure_port(self, address, server_credentials):110"""Reserves a port for secure RPC service after this Server becomes active.111112This method may only be called before calling this Server's start method is113called.114115Args:116address: The address for which to open a port.117server_credentials: A ServerCredentials.118119Returns:120An integer port on which RPCs will be serviced after this link has been121started. This is typically the same number as the port number contained122in the passed address, but will likely be different if the port number123contained in the passed address was zero.124"""125raise NotImplementedError()126127@abc.abstractmethod128def start(self):129"""Starts this Server's service of RPCs.130131This method may only be called while the server is not serving RPCs (i.e. it132is not idempotent).133"""134raise NotImplementedError()135136@abc.abstractmethod137def stop(self, grace):138"""Stops this Server's service of RPCs.139140All calls to this method immediately stop service of new RPCs. When existing141RPCs are aborted is controlled by the grace period parameter passed to this142method.143144This method may be called at any time and is idempotent. Passing a smaller145grace value than has been passed in a previous call will have the effect of146stopping the Server sooner. Passing a larger grace value than has been147passed in a previous call will not have the effect of stopping the server148later.149150Args:151grace: A duration of time in seconds to allow existing RPCs to complete152before being aborted by this Server's stopping. May be zero for153immediate abortion of all in-progress RPCs.154155Returns:156A threading.Event that will be set when this Server has completely157stopped. The returned event may not be set until after the full grace158period (if some ongoing RPC continues for the full length of the period)159of it may be set much sooner (such as if this Server had no RPCs underway160at the time it was stopped or if all RPCs that it had underway completed161very early in the grace period).162"""163raise NotImplementedError()164165166