grpcio-fips 1.70.0__4-cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. grpc/__init__.py +2348 -0
  2. grpc/_auth.py +80 -0
  3. grpc/_channel.py +2267 -0
  4. grpc/_common.py +183 -0
  5. grpc/_compression.py +71 -0
  6. grpc/_cython/__init__.py +13 -0
  7. grpc/_cython/_credentials/roots.pem +4337 -0
  8. grpc/_cython/_cygrpc/__init__.py +13 -0
  9. grpc/_cython/cygrpc.cp313-win_amd64.pyd +0 -0
  10. grpc/_grpcio_metadata.py +1 -0
  11. grpc/_interceptor.py +813 -0
  12. grpc/_observability.py +299 -0
  13. grpc/_plugin_wrapping.py +136 -0
  14. grpc/_runtime_protos.py +165 -0
  15. grpc/_server.py +1528 -0
  16. grpc/_simple_stubs.py +588 -0
  17. grpc/_typing.py +95 -0
  18. grpc/_utilities.py +222 -0
  19. grpc/aio/__init__.py +95 -0
  20. grpc/aio/_base_call.py +257 -0
  21. grpc/aio/_base_channel.py +364 -0
  22. grpc/aio/_base_server.py +385 -0
  23. grpc/aio/_call.py +764 -0
  24. grpc/aio/_channel.py +627 -0
  25. grpc/aio/_interceptor.py +1178 -0
  26. grpc/aio/_metadata.py +137 -0
  27. grpc/aio/_server.py +239 -0
  28. grpc/aio/_typing.py +43 -0
  29. grpc/aio/_utils.py +22 -0
  30. grpc/beta/__init__.py +13 -0
  31. grpc/beta/_client_adaptations.py +1015 -0
  32. grpc/beta/_metadata.py +56 -0
  33. grpc/beta/_server_adaptations.py +465 -0
  34. grpc/beta/implementations.py +345 -0
  35. grpc/beta/interfaces.py +163 -0
  36. grpc/beta/utilities.py +153 -0
  37. grpc/experimental/__init__.py +134 -0
  38. grpc/experimental/aio/__init__.py +16 -0
  39. grpc/experimental/gevent.py +27 -0
  40. grpc/experimental/session_cache.py +45 -0
  41. grpc/framework/__init__.py +13 -0
  42. grpc/framework/common/__init__.py +13 -0
  43. grpc/framework/common/cardinality.py +26 -0
  44. grpc/framework/common/style.py +24 -0
  45. grpc/framework/foundation/__init__.py +13 -0
  46. grpc/framework/foundation/abandonment.py +22 -0
  47. grpc/framework/foundation/callable_util.py +98 -0
  48. grpc/framework/foundation/future.py +219 -0
  49. grpc/framework/foundation/logging_pool.py +72 -0
  50. grpc/framework/foundation/stream.py +43 -0
  51. grpc/framework/foundation/stream_util.py +148 -0
  52. grpc/framework/interfaces/__init__.py +13 -0
  53. grpc/framework/interfaces/base/__init__.py +13 -0
  54. grpc/framework/interfaces/base/base.py +328 -0
  55. grpc/framework/interfaces/base/utilities.py +83 -0
  56. grpc/framework/interfaces/face/__init__.py +13 -0
  57. grpc/framework/interfaces/face/face.py +1084 -0
  58. grpc/framework/interfaces/face/utilities.py +245 -0
  59. grpcio_fips-1.70.0.dist-info/METADATA +55 -0
  60. grpcio_fips-1.70.0.dist-info/RECORD +63 -0
  61. grpcio_fips-1.70.0.dist-info/WHEEL +5 -0
  62. grpcio_fips-1.70.0.dist-info/licenses/LICENSE +610 -0
  63. grpcio_fips-1.70.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,345 @@
1
+ # Copyright 2015-2016 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
+ """Entry points into the Beta API of gRPC Python."""
15
+
16
+ # threading is referenced from specification in this module.
17
+ import threading # pylint: disable=unused-import
18
+
19
+ # interfaces, cardinality, and face are referenced from specification in this
20
+ # module.
21
+ import grpc
22
+ from grpc import _auth
23
+ from grpc.beta import _client_adaptations
24
+ from grpc.beta import _metadata
25
+ from grpc.beta import _server_adaptations
26
+ from grpc.beta import interfaces # pylint: disable=unused-import
27
+ from grpc.framework.common import cardinality # pylint: disable=unused-import
28
+ from grpc.framework.interfaces.face import face # pylint: disable=unused-import
29
+
30
+ # pylint: disable=too-many-arguments
31
+
32
+ ChannelCredentials = grpc.ChannelCredentials
33
+ ssl_channel_credentials = grpc.ssl_channel_credentials
34
+ CallCredentials = grpc.CallCredentials
35
+
36
+
37
+ def metadata_call_credentials(metadata_plugin, name=None):
38
+ def plugin(context, callback):
39
+ def wrapped_callback(beta_metadata, error):
40
+ callback(_metadata.unbeta(beta_metadata), error)
41
+
42
+ metadata_plugin(context, wrapped_callback)
43
+
44
+ return grpc.metadata_call_credentials(plugin, name=name)
45
+
46
+
47
+ def google_call_credentials(credentials):
48
+ """Construct CallCredentials from GoogleCredentials.
49
+
50
+ Args:
51
+ credentials: A GoogleCredentials object from the oauth2client library.
52
+
53
+ Returns:
54
+ A CallCredentials object for use in a GRPCCallOptions object.
55
+ """
56
+ return metadata_call_credentials(_auth.GoogleCallCredentials(credentials))
57
+
58
+
59
+ access_token_call_credentials = grpc.access_token_call_credentials
60
+ composite_call_credentials = grpc.composite_call_credentials
61
+ composite_channel_credentials = grpc.composite_channel_credentials
62
+
63
+
64
+ class Channel(object):
65
+ """A channel to a remote host through which RPCs may be conducted.
66
+
67
+ Only the "subscribe" and "unsubscribe" methods are supported for application
68
+ use. This class' instance constructor and all other attributes are
69
+ unsupported.
70
+ """
71
+
72
+ def __init__(self, channel):
73
+ self._channel = channel
74
+
75
+ def subscribe(self, callback, try_to_connect=None):
76
+ """Subscribes to this Channel's connectivity.
77
+
78
+ Args:
79
+ callback: A callable to be invoked and passed an
80
+ interfaces.ChannelConnectivity identifying this Channel's connectivity.
81
+ The callable will be invoked immediately upon subscription and again for
82
+ every change to this Channel's connectivity thereafter until it is
83
+ unsubscribed.
84
+ try_to_connect: A boolean indicating whether or not this Channel should
85
+ attempt to connect if it is not already connected and ready to conduct
86
+ RPCs.
87
+ """
88
+ self._channel.subscribe(callback, try_to_connect=try_to_connect)
89
+
90
+ def unsubscribe(self, callback):
91
+ """Unsubscribes a callback from this Channel's connectivity.
92
+
93
+ Args:
94
+ callback: A callable previously registered with this Channel from having
95
+ been passed to its "subscribe" method.
96
+ """
97
+ self._channel.unsubscribe(callback)
98
+
99
+
100
+ def insecure_channel(host, port):
101
+ """Creates an insecure Channel to a remote host.
102
+
103
+ Args:
104
+ host: The name of the remote host to which to connect.
105
+ port: The port of the remote host to which to connect.
106
+ If None only the 'host' part will be used.
107
+
108
+ Returns:
109
+ A Channel to the remote host through which RPCs may be conducted.
110
+ """
111
+ channel = grpc.insecure_channel(
112
+ host if port is None else "%s:%d" % (host, port)
113
+ )
114
+ return Channel(channel)
115
+
116
+
117
+ def secure_channel(host, port, channel_credentials):
118
+ """Creates a secure Channel to a remote host.
119
+
120
+ Args:
121
+ host: The name of the remote host to which to connect.
122
+ port: The port of the remote host to which to connect.
123
+ If None only the 'host' part will be used.
124
+ channel_credentials: A ChannelCredentials.
125
+
126
+ Returns:
127
+ A secure Channel to the remote host through which RPCs may be conducted.
128
+ """
129
+ channel = grpc.secure_channel(
130
+ host if port is None else "%s:%d" % (host, port), channel_credentials
131
+ )
132
+ return Channel(channel)
133
+
134
+
135
+ class StubOptions(object):
136
+ """A value encapsulating the various options for creation of a Stub.
137
+
138
+ This class and its instances have no supported interface - it exists to define
139
+ the type of its instances and its instances exist to be passed to other
140
+ functions.
141
+ """
142
+
143
+ def __init__(
144
+ self,
145
+ host,
146
+ request_serializers,
147
+ response_deserializers,
148
+ metadata_transformer,
149
+ thread_pool,
150
+ thread_pool_size,
151
+ ):
152
+ self.host = host
153
+ self.request_serializers = request_serializers
154
+ self.response_deserializers = response_deserializers
155
+ self.metadata_transformer = metadata_transformer
156
+ self.thread_pool = thread_pool
157
+ self.thread_pool_size = thread_pool_size
158
+
159
+
160
+ _EMPTY_STUB_OPTIONS = StubOptions(None, None, None, None, None, None)
161
+
162
+
163
+ def stub_options(
164
+ host=None,
165
+ request_serializers=None,
166
+ response_deserializers=None,
167
+ metadata_transformer=None,
168
+ thread_pool=None,
169
+ thread_pool_size=None,
170
+ ):
171
+ """Creates a StubOptions value to be passed at stub creation.
172
+
173
+ All parameters are optional and should always be passed by keyword.
174
+
175
+ Args:
176
+ host: A host string to set on RPC calls.
177
+ request_serializers: A dictionary from service name-method name pair to
178
+ request serialization behavior.
179
+ response_deserializers: A dictionary from service name-method name pair to
180
+ response deserialization behavior.
181
+ metadata_transformer: A callable that given a metadata object produces
182
+ another metadata object to be used in the underlying communication on the
183
+ wire.
184
+ thread_pool: A thread pool to use in stubs.
185
+ thread_pool_size: The size of thread pool to create for use in stubs;
186
+ ignored if thread_pool has been passed.
187
+
188
+ Returns:
189
+ A StubOptions value created from the passed parameters.
190
+ """
191
+ return StubOptions(
192
+ host,
193
+ request_serializers,
194
+ response_deserializers,
195
+ metadata_transformer,
196
+ thread_pool,
197
+ thread_pool_size,
198
+ )
199
+
200
+
201
+ def generic_stub(channel, options=None):
202
+ """Creates a face.GenericStub on which RPCs can be made.
203
+
204
+ Args:
205
+ channel: A Channel for use by the created stub.
206
+ options: A StubOptions customizing the created stub.
207
+
208
+ Returns:
209
+ A face.GenericStub on which RPCs can be made.
210
+ """
211
+ effective_options = _EMPTY_STUB_OPTIONS if options is None else options
212
+ return _client_adaptations.generic_stub(
213
+ channel._channel, # pylint: disable=protected-access
214
+ effective_options.host,
215
+ effective_options.metadata_transformer,
216
+ effective_options.request_serializers,
217
+ effective_options.response_deserializers,
218
+ )
219
+
220
+
221
+ def dynamic_stub(channel, service, cardinalities, options=None):
222
+ """Creates a face.DynamicStub with which RPCs can be invoked.
223
+
224
+ Args:
225
+ channel: A Channel for the returned face.DynamicStub to use.
226
+ service: The package-qualified full name of the service.
227
+ cardinalities: A dictionary from RPC method name to cardinality.Cardinality
228
+ value identifying the cardinality of the RPC method.
229
+ options: An optional StubOptions value further customizing the functionality
230
+ of the returned face.DynamicStub.
231
+
232
+ Returns:
233
+ A face.DynamicStub with which RPCs can be invoked.
234
+ """
235
+ effective_options = _EMPTY_STUB_OPTIONS if options is None else options
236
+ return _client_adaptations.dynamic_stub(
237
+ channel._channel, # pylint: disable=protected-access
238
+ service,
239
+ cardinalities,
240
+ effective_options.host,
241
+ effective_options.metadata_transformer,
242
+ effective_options.request_serializers,
243
+ effective_options.response_deserializers,
244
+ )
245
+
246
+
247
+ ServerCredentials = grpc.ServerCredentials
248
+ ssl_server_credentials = grpc.ssl_server_credentials
249
+
250
+
251
+ class ServerOptions(object):
252
+ """A value encapsulating the various options for creation of a Server.
253
+
254
+ This class and its instances have no supported interface - it exists to define
255
+ the type of its instances and its instances exist to be passed to other
256
+ functions.
257
+ """
258
+
259
+ def __init__(
260
+ self,
261
+ multi_method_implementation,
262
+ request_deserializers,
263
+ response_serializers,
264
+ thread_pool,
265
+ thread_pool_size,
266
+ default_timeout,
267
+ maximum_timeout,
268
+ ):
269
+ self.multi_method_implementation = multi_method_implementation
270
+ self.request_deserializers = request_deserializers
271
+ self.response_serializers = response_serializers
272
+ self.thread_pool = thread_pool
273
+ self.thread_pool_size = thread_pool_size
274
+ self.default_timeout = default_timeout
275
+ self.maximum_timeout = maximum_timeout
276
+
277
+
278
+ _EMPTY_SERVER_OPTIONS = ServerOptions(None, None, None, None, None, None, None)
279
+
280
+
281
+ def server_options(
282
+ multi_method_implementation=None,
283
+ request_deserializers=None,
284
+ response_serializers=None,
285
+ thread_pool=None,
286
+ thread_pool_size=None,
287
+ default_timeout=None,
288
+ maximum_timeout=None,
289
+ ):
290
+ """Creates a ServerOptions value to be passed at server creation.
291
+
292
+ All parameters are optional and should always be passed by keyword.
293
+
294
+ Args:
295
+ multi_method_implementation: A face.MultiMethodImplementation to be called
296
+ to service an RPC if the server has no specific method implementation for
297
+ the name of the RPC for which service was requested.
298
+ request_deserializers: A dictionary from service name-method name pair to
299
+ request deserialization behavior.
300
+ response_serializers: A dictionary from service name-method name pair to
301
+ response serialization behavior.
302
+ thread_pool: A thread pool to use in stubs.
303
+ thread_pool_size: The size of thread pool to create for use in stubs;
304
+ ignored if thread_pool has been passed.
305
+ default_timeout: A duration in seconds to allow for RPC service when
306
+ servicing RPCs that did not include a timeout value when invoked.
307
+ maximum_timeout: A duration in seconds to allow for RPC service when
308
+ servicing RPCs no matter what timeout value was passed when the RPC was
309
+ invoked.
310
+
311
+ Returns:
312
+ A StubOptions value created from the passed parameters.
313
+ """
314
+ return ServerOptions(
315
+ multi_method_implementation,
316
+ request_deserializers,
317
+ response_serializers,
318
+ thread_pool,
319
+ thread_pool_size,
320
+ default_timeout,
321
+ maximum_timeout,
322
+ )
323
+
324
+
325
+ def server(service_implementations, options=None):
326
+ """Creates an interfaces.Server with which RPCs can be serviced.
327
+
328
+ Args:
329
+ service_implementations: A dictionary from service name-method name pair to
330
+ face.MethodImplementation.
331
+ options: An optional ServerOptions value further customizing the
332
+ functionality of the returned Server.
333
+
334
+ Returns:
335
+ An interfaces.Server with which RPCs can be serviced.
336
+ """
337
+ effective_options = _EMPTY_SERVER_OPTIONS if options is None else options
338
+ return _server_adaptations.server(
339
+ service_implementations,
340
+ effective_options.multi_method_implementation,
341
+ effective_options.request_deserializers,
342
+ effective_options.response_serializers,
343
+ effective_options.thread_pool,
344
+ effective_options.thread_pool_size,
345
+ )
@@ -0,0 +1,163 @@
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
+
20
+ ChannelConnectivity = grpc.ChannelConnectivity
21
+ # FATAL_FAILURE was a Beta-API name for SHUTDOWN
22
+ ChannelConnectivity.FATAL_FAILURE = ChannelConnectivity.SHUTDOWN
23
+
24
+ StatusCode = grpc.StatusCode
25
+
26
+
27
+ class GRPCCallOptions(object):
28
+ """A value encapsulating gRPC-specific options passed on RPC invocation.
29
+
30
+ This class and its instances have no supported interface - it exists to
31
+ define the type of its instances and its instances exist to be passed to
32
+ other functions.
33
+ """
34
+
35
+ def __init__(self, disable_compression, subcall_of, credentials):
36
+ self.disable_compression = disable_compression
37
+ self.subcall_of = subcall_of
38
+ self.credentials = credentials
39
+
40
+
41
+ def grpc_call_options(disable_compression=False, credentials=None):
42
+ """Creates a GRPCCallOptions value to be passed at RPC invocation.
43
+
44
+ All parameters are optional and should always be passed by keyword.
45
+
46
+ Args:
47
+ disable_compression: A boolean indicating whether or not compression should
48
+ be disabled for the request object of the RPC. Only valid for
49
+ request-unary RPCs.
50
+ credentials: A CallCredentials object to use for the invoked RPC.
51
+ """
52
+ return GRPCCallOptions(disable_compression, None, credentials)
53
+
54
+
55
+ GRPCAuthMetadataContext = grpc.AuthMetadataContext
56
+ GRPCAuthMetadataPluginCallback = grpc.AuthMetadataPluginCallback
57
+ GRPCAuthMetadataPlugin = grpc.AuthMetadataPlugin
58
+
59
+
60
+ class GRPCServicerContext(abc.ABC):
61
+ """Exposes gRPC-specific options and behaviors to code servicing RPCs."""
62
+
63
+ @abc.abstractmethod
64
+ def peer(self):
65
+ """Identifies the peer that invoked the RPC being serviced.
66
+
67
+ Returns:
68
+ A string identifying the peer that invoked the RPC being serviced.
69
+ """
70
+ raise NotImplementedError()
71
+
72
+ @abc.abstractmethod
73
+ def disable_next_response_compression(self):
74
+ """Disables compression of the next response passed by the application."""
75
+ raise NotImplementedError()
76
+
77
+
78
+ class GRPCInvocationContext(abc.ABC):
79
+ """Exposes gRPC-specific options and behaviors to code invoking RPCs."""
80
+
81
+ @abc.abstractmethod
82
+ def disable_next_request_compression(self):
83
+ """Disables compression of the next request passed by the application."""
84
+ raise NotImplementedError()
85
+
86
+
87
+ class Server(abc.ABC):
88
+ """Services RPCs."""
89
+
90
+ @abc.abstractmethod
91
+ def add_insecure_port(self, address):
92
+ """Reserves a port for insecure RPC service once this Server becomes active.
93
+
94
+ This method may only be called before calling this Server's start method is
95
+ called.
96
+
97
+ Args:
98
+ address: The address for which to open a port.
99
+
100
+ Returns:
101
+ An integer port on which RPCs will be serviced after this link has been
102
+ started. This is typically the same number as the port number contained
103
+ in the passed address, but will likely be different if the port number
104
+ contained in the passed address was zero.
105
+ """
106
+ raise NotImplementedError()
107
+
108
+ @abc.abstractmethod
109
+ def add_secure_port(self, address, server_credentials):
110
+ """Reserves a port for secure RPC service after this Server becomes active.
111
+
112
+ This method may only be called before calling this Server's start method is
113
+ called.
114
+
115
+ Args:
116
+ address: The address for which to open a port.
117
+ server_credentials: A ServerCredentials.
118
+
119
+ Returns:
120
+ An integer port on which RPCs will be serviced after this link has been
121
+ started. This is typically the same number as the port number contained
122
+ in the passed address, but will likely be different if the port number
123
+ contained in the passed address was zero.
124
+ """
125
+ raise NotImplementedError()
126
+
127
+ @abc.abstractmethod
128
+ def start(self):
129
+ """Starts this Server's service of RPCs.
130
+
131
+ This method may only be called while the server is not serving RPCs (i.e. it
132
+ is not idempotent).
133
+ """
134
+ raise NotImplementedError()
135
+
136
+ @abc.abstractmethod
137
+ def stop(self, grace):
138
+ """Stops this Server's service of RPCs.
139
+
140
+ All calls to this method immediately stop service of new RPCs. When existing
141
+ RPCs are aborted is controlled by the grace period parameter passed to this
142
+ method.
143
+
144
+ This method may be called at any time and is idempotent. Passing a smaller
145
+ grace value than has been passed in a previous call will have the effect of
146
+ stopping the Server sooner. Passing a larger grace value than has been
147
+ passed in a previous call will not have the effect of stopping the server
148
+ later.
149
+
150
+ Args:
151
+ grace: A duration of time in seconds to allow existing RPCs to complete
152
+ before being aborted by this Server's stopping. May be zero for
153
+ immediate abortion of all in-progress RPCs.
154
+
155
+ Returns:
156
+ A threading.Event that will be set when this Server has completely
157
+ stopped. The returned event may not be set until after the full grace
158
+ period (if some ongoing RPC continues for the full length of the period)
159
+ of it may be set much sooner (such as if this Server had no RPCs underway
160
+ at the time it was stopped or if all RPCs that it had underway completed
161
+ very early in the grace period).
162
+ """
163
+ raise NotImplementedError()
grpc/beta/utilities.py ADDED
@@ -0,0 +1,153 @@
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
+ """Utilities for the gRPC Python Beta API."""
15
+
16
+ import threading
17
+ import time
18
+
19
+ # implementations is referenced from specification in this module.
20
+ from grpc.beta import implementations # pylint: disable=unused-import
21
+ from grpc.beta import interfaces
22
+ from grpc.framework.foundation import callable_util
23
+ from grpc.framework.foundation import future
24
+
25
+ _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE = (
26
+ 'Exception calling connectivity future "done" callback!'
27
+ )
28
+
29
+
30
+ class _ChannelReadyFuture(future.Future):
31
+ def __init__(self, channel):
32
+ self._condition = threading.Condition()
33
+ self._channel = channel
34
+
35
+ self._matured = False
36
+ self._cancelled = False
37
+ self._done_callbacks = []
38
+
39
+ def _block(self, timeout):
40
+ until = None if timeout is None else time.time() + timeout
41
+ with self._condition:
42
+ while True:
43
+ if self._cancelled:
44
+ raise future.CancelledError()
45
+ elif self._matured:
46
+ return
47
+ else:
48
+ if until is None:
49
+ self._condition.wait()
50
+ else:
51
+ remaining = until - time.time()
52
+ if remaining < 0:
53
+ raise future.TimeoutError()
54
+ else:
55
+ self._condition.wait(timeout=remaining)
56
+
57
+ def _update(self, connectivity):
58
+ with self._condition:
59
+ if (
60
+ not self._cancelled
61
+ and connectivity is interfaces.ChannelConnectivity.READY
62
+ ):
63
+ self._matured = True
64
+ self._channel.unsubscribe(self._update)
65
+ self._condition.notify_all()
66
+ done_callbacks = tuple(self._done_callbacks)
67
+ self._done_callbacks = None
68
+ else:
69
+ return
70
+
71
+ for done_callback in done_callbacks:
72
+ callable_util.call_logging_exceptions(
73
+ done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self
74
+ )
75
+
76
+ def cancel(self):
77
+ with self._condition:
78
+ if not self._matured:
79
+ self._cancelled = True
80
+ self._channel.unsubscribe(self._update)
81
+ self._condition.notify_all()
82
+ done_callbacks = tuple(self._done_callbacks)
83
+ self._done_callbacks = None
84
+ else:
85
+ return False
86
+
87
+ for done_callback in done_callbacks:
88
+ callable_util.call_logging_exceptions(
89
+ done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self
90
+ )
91
+
92
+ return True
93
+
94
+ def cancelled(self):
95
+ with self._condition:
96
+ return self._cancelled
97
+
98
+ def running(self):
99
+ with self._condition:
100
+ return not self._cancelled and not self._matured
101
+
102
+ def done(self):
103
+ with self._condition:
104
+ return self._cancelled or self._matured
105
+
106
+ def result(self, timeout=None):
107
+ self._block(timeout)
108
+ return None
109
+
110
+ def exception(self, timeout=None):
111
+ self._block(timeout)
112
+ return None
113
+
114
+ def traceback(self, timeout=None):
115
+ self._block(timeout)
116
+ return None
117
+
118
+ def add_done_callback(self, fn):
119
+ with self._condition:
120
+ if not self._cancelled and not self._matured:
121
+ self._done_callbacks.append(fn)
122
+ return
123
+
124
+ fn(self)
125
+
126
+ def start(self):
127
+ with self._condition:
128
+ self._channel.subscribe(self._update, try_to_connect=True)
129
+
130
+ def __del__(self):
131
+ with self._condition:
132
+ if not self._cancelled and not self._matured:
133
+ self._channel.unsubscribe(self._update)
134
+
135
+
136
+ def channel_ready_future(channel):
137
+ """Creates a future.Future tracking when an implementations.Channel is ready.
138
+
139
+ Cancelling the returned future.Future does not tell the given
140
+ implementations.Channel to abandon attempts it may have been making to
141
+ connect; cancelling merely deactivates the return future.Future's
142
+ subscription to the given implementations.Channel's connectivity.
143
+
144
+ Args:
145
+ channel: An implementations.Channel.
146
+
147
+ Returns:
148
+ A future.Future that matures when the given Channel has connectivity
149
+ interfaces.ChannelConnectivity.READY.
150
+ """
151
+ ready_future = _ChannelReadyFuture(channel)
152
+ ready_future.start()
153
+ return ready_future