Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/grpc/beta/interfaces.py
7783 views
1
# Copyright 2015 gRPC authors.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
# http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
"""Constants and interfaces of the Beta API of gRPC Python."""
15
16
import abc
17
18
import grpc
19
import six
20
21
ChannelConnectivity = grpc.ChannelConnectivity
22
# FATAL_FAILURE was a Beta-API name for SHUTDOWN
23
ChannelConnectivity.FATAL_FAILURE = ChannelConnectivity.SHUTDOWN
24
25
StatusCode = grpc.StatusCode
26
27
28
class GRPCCallOptions(object):
29
"""A value encapsulating gRPC-specific options passed on RPC invocation.
30
31
This class and its instances have no supported interface - it exists to
32
define the type of its instances and its instances exist to be passed to
33
other functions.
34
"""
35
36
def __init__(self, disable_compression, subcall_of, credentials):
37
self.disable_compression = disable_compression
38
self.subcall_of = subcall_of
39
self.credentials = credentials
40
41
42
def grpc_call_options(disable_compression=False, credentials=None):
43
"""Creates a GRPCCallOptions value to be passed at RPC invocation.
44
45
All parameters are optional and should always be passed by keyword.
46
47
Args:
48
disable_compression: A boolean indicating whether or not compression should
49
be disabled for the request object of the RPC. Only valid for
50
request-unary RPCs.
51
credentials: A CallCredentials object to use for the invoked RPC.
52
"""
53
return GRPCCallOptions(disable_compression, None, credentials)
54
55
56
GRPCAuthMetadataContext = grpc.AuthMetadataContext
57
GRPCAuthMetadataPluginCallback = grpc.AuthMetadataPluginCallback
58
GRPCAuthMetadataPlugin = grpc.AuthMetadataPlugin
59
60
61
class GRPCServicerContext(six.with_metaclass(abc.ABCMeta)):
62
"""Exposes gRPC-specific options and behaviors to code servicing RPCs."""
63
64
@abc.abstractmethod
65
def peer(self):
66
"""Identifies the peer that invoked the RPC being serviced.
67
68
Returns:
69
A string identifying the peer that invoked the RPC being serviced.
70
"""
71
raise NotImplementedError()
72
73
@abc.abstractmethod
74
def disable_next_response_compression(self):
75
"""Disables compression of the next response passed by the application."""
76
raise NotImplementedError()
77
78
79
class GRPCInvocationContext(six.with_metaclass(abc.ABCMeta)):
80
"""Exposes gRPC-specific options and behaviors to code invoking RPCs."""
81
82
@abc.abstractmethod
83
def disable_next_request_compression(self):
84
"""Disables compression of the next request passed by the application."""
85
raise NotImplementedError()
86
87
88
class Server(six.with_metaclass(abc.ABCMeta)):
89
"""Services RPCs."""
90
91
@abc.abstractmethod
92
def add_insecure_port(self, address):
93
"""Reserves a port for insecure RPC service once this Server becomes active.
94
95
This method may only be called before calling this Server's start method is
96
called.
97
98
Args:
99
address: The address for which to open a port.
100
101
Returns:
102
An integer port on which RPCs will be serviced after this link has been
103
started. This is typically the same number as the port number contained
104
in the passed address, but will likely be different if the port number
105
contained in the passed address was zero.
106
"""
107
raise NotImplementedError()
108
109
@abc.abstractmethod
110
def add_secure_port(self, address, server_credentials):
111
"""Reserves a port for secure RPC service after this Server becomes active.
112
113
This method may only be called before calling this Server's start method is
114
called.
115
116
Args:
117
address: The address for which to open a port.
118
server_credentials: A ServerCredentials.
119
120
Returns:
121
An integer port on which RPCs will be serviced after this link has been
122
started. This is typically the same number as the port number contained
123
in the passed address, but will likely be different if the port number
124
contained in the passed address was zero.
125
"""
126
raise NotImplementedError()
127
128
@abc.abstractmethod
129
def start(self):
130
"""Starts this Server's service of RPCs.
131
132
This method may only be called while the server is not serving RPCs (i.e. it
133
is not idempotent).
134
"""
135
raise NotImplementedError()
136
137
@abc.abstractmethod
138
def stop(self, grace):
139
"""Stops this Server's service of RPCs.
140
141
All calls to this method immediately stop service of new RPCs. When existing
142
RPCs are aborted is controlled by the grace period parameter passed to this
143
method.
144
145
This method may be called at any time and is idempotent. Passing a smaller
146
grace value than has been passed in a previous call will have the effect of
147
stopping the Server sooner. Passing a larger grace value than has been
148
passed in a previous call will not have the effect of stopping the server
149
later.
150
151
Args:
152
grace: A duration of time in seconds to allow existing RPCs to complete
153
before being aborted by this Server's stopping. May be zero for
154
immediate abortion of all in-progress RPCs.
155
156
Returns:
157
A threading.Event that will be set when this Server has completely
158
stopped. The returned event may not be set until after the full grace
159
period (if some ongoing RPC continues for the full length of the period)
160
of it may be set much sooner (such as if this Server had no RPCs underway
161
at the time it was stopped or if all RPCs that it had underway completed
162
very early in the grace period).
163
"""
164
raise NotImplementedError()
165
166