Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/google/protobuf/service.py
7784 views
# Protocol Buffers - Google's data interchange format1# Copyright 2008 Google Inc. All rights reserved.2# https://developers.google.com/protocol-buffers/3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions are6# met:7#8# * Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# * Redistributions in binary form must reproduce the above11# copyright notice, this list of conditions and the following disclaimer12# in the documentation and/or other materials provided with the13# distribution.14# * Neither the name of Google Inc. nor the names of its15# contributors may be used to endorse or promote products derived from16# this software without specific prior written permission.17#18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2930"""DEPRECATED: Declares the RPC service interfaces.3132This module declares the abstract interfaces underlying proto2 RPC33services. These are intended to be independent of any particular RPC34implementation, so that proto2 services can be used on top of a variety35of implementations. Starting with version 2.3.0, RPC implementations should36not try to build on these, but should instead provide code generator plugins37which generate code specific to the particular RPC implementation. This way38the generated code can be more appropriate for the implementation in use39and can avoid unnecessary layers of indirection.40"""4142__author__ = '[email protected] (Petar Petrov)'434445class RpcException(Exception):46"""Exception raised on failed blocking RPC method call."""47pass484950class Service(object):5152"""Abstract base interface for protocol-buffer-based RPC services.5354Services themselves are abstract classes (implemented either by servers or as55stubs), but they subclass this base interface. The methods of this56interface can be used to call the methods of the service without knowing57its exact type at compile time (analogous to the Message interface).58"""5960def GetDescriptor():61"""Retrieves this service's descriptor."""62raise NotImplementedError6364def CallMethod(self, method_descriptor, rpc_controller,65request, done):66"""Calls a method of the service specified by method_descriptor.6768If "done" is None then the call is blocking and the response69message will be returned directly. Otherwise the call is asynchronous70and "done" will later be called with the response value.7172In the blocking case, RpcException will be raised on error.7374Preconditions:7576* method_descriptor.service == GetDescriptor77* request is of the exact same classes as returned by78GetRequestClass(method).79* After the call has started, the request must not be modified.80* "rpc_controller" is of the correct type for the RPC implementation being81used by this Service. For stubs, the "correct type" depends on the82RpcChannel which the stub is using.8384Postconditions:8586* "done" will be called when the method is complete. This may be87before CallMethod() returns or it may be at some point in the future.88* If the RPC failed, the response value passed to "done" will be None.89Further details about the failure can be found by querying the90RpcController.91"""92raise NotImplementedError9394def GetRequestClass(self, method_descriptor):95"""Returns the class of the request message for the specified method.9697CallMethod() requires that the request is of a particular subclass of98Message. GetRequestClass() gets the default instance of this required99type.100101Example:102method = service.GetDescriptor().FindMethodByName("Foo")103request = stub.GetRequestClass(method)()104request.ParseFromString(input)105service.CallMethod(method, request, callback)106"""107raise NotImplementedError108109def GetResponseClass(self, method_descriptor):110"""Returns the class of the response message for the specified method.111112This method isn't really needed, as the RpcChannel's CallMethod constructs113the response protocol message. It's provided anyway in case it is useful114for the caller to know the response type in advance.115"""116raise NotImplementedError117118119class RpcController(object):120121"""An RpcController mediates a single method call.122123The primary purpose of the controller is to provide a way to manipulate124settings specific to the RPC implementation and to find out about RPC-level125errors. The methods provided by the RpcController interface are intended126to be a "least common denominator" set of features which we expect all127implementations to support. Specific implementations may provide more128advanced features (e.g. deadline propagation).129"""130131# Client-side methods below132133def Reset(self):134"""Resets the RpcController to its initial state.135136After the RpcController has been reset, it may be reused in137a new call. Must not be called while an RPC is in progress.138"""139raise NotImplementedError140141def Failed(self):142"""Returns true if the call failed.143144After a call has finished, returns true if the call failed. The possible145reasons for failure depend on the RPC implementation. Failed() must not146be called before a call has finished. If Failed() returns true, the147contents of the response message are undefined.148"""149raise NotImplementedError150151def ErrorText(self):152"""If Failed is true, returns a human-readable description of the error."""153raise NotImplementedError154155def StartCancel(self):156"""Initiate cancellation.157158Advises the RPC system that the caller desires that the RPC call be159canceled. The RPC system may cancel it immediately, may wait awhile and160then cancel it, or may not even cancel the call at all. If the call is161canceled, the "done" callback will still be called and the RpcController162will indicate that the call failed at that time.163"""164raise NotImplementedError165166# Server-side methods below167168def SetFailed(self, reason):169"""Sets a failure reason.170171Causes Failed() to return true on the client side. "reason" will be172incorporated into the message returned by ErrorText(). If you find173you need to return machine-readable information about failures, you174should incorporate it into your response protocol buffer and should175NOT call SetFailed().176"""177raise NotImplementedError178179def IsCanceled(self):180"""Checks if the client cancelled the RPC.181182If true, indicates that the client canceled the RPC, so the server may183as well give up on replying to it. The server should still call the184final "done" callback.185"""186raise NotImplementedError187188def NotifyOnCancel(self, callback):189"""Sets a callback to invoke on cancel.190191Asks that the given callback be called when the RPC is canceled. The192callback will always be called exactly once. If the RPC completes without193being canceled, the callback will be called after completion. If the RPC194has already been canceled when NotifyOnCancel() is called, the callback195will be called immediately.196197NotifyOnCancel() must be called no more than once per request.198"""199raise NotImplementedError200201202class RpcChannel(object):203204"""Abstract interface for an RPC channel.205206An RpcChannel represents a communication line to a service which can be used207to call that service's methods. The service may be running on another208machine. Normally, you should not use an RpcChannel directly, but instead209construct a stub {@link Service} wrapping it. Example:210211Example:212RpcChannel channel = rpcImpl.Channel("remotehost.example.com:1234")213RpcController controller = rpcImpl.Controller()214MyService service = MyService_Stub(channel)215service.MyMethod(controller, request, callback)216"""217218def CallMethod(self, method_descriptor, rpc_controller,219request, response_class, done):220"""Calls the method identified by the descriptor.221222Call the given method of the remote service. The signature of this223procedure looks the same as Service.CallMethod(), but the requirements224are less strict in one important way: the request object doesn't have to225be of any specific class as long as its descriptor is method.input_type.226"""227raise NotImplementedError228229230