grpcio-fips 1.44.0__4-cp38-cp38-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 (64) hide show
  1. grpc/__init__.py +2190 -0
  2. grpc/_auth.py +58 -0
  3. grpc/_channel.py +1581 -0
  4. grpc/_common.py +168 -0
  5. grpc/_compression.py +55 -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/ayx-crypto-library.dll +0 -0
  10. grpc/_cython/cygrpc.cp38-win_amd64.pyd +0 -0
  11. grpc/_cython/libcrypto-3-x64.dll +0 -0
  12. grpc/_cython/libssl-3-x64.dll +0 -0
  13. grpc/_grpcio_metadata.py +1 -0
  14. grpc/_interceptor.py +562 -0
  15. grpc/_plugin_wrapping.py +113 -0
  16. grpc/_runtime_protos.py +155 -0
  17. grpc/_server.py +1003 -0
  18. grpc/_simple_stubs.py +486 -0
  19. grpc/_utilities.py +168 -0
  20. grpc/aio/__init__.py +95 -0
  21. grpc/aio/_base_call.py +248 -0
  22. grpc/aio/_base_channel.py +352 -0
  23. grpc/aio/_base_server.py +373 -0
  24. grpc/aio/_call.py +648 -0
  25. grpc/aio/_channel.py +484 -0
  26. grpc/aio/_interceptor.py +1004 -0
  27. grpc/aio/_metadata.py +120 -0
  28. grpc/aio/_server.py +210 -0
  29. grpc/aio/_typing.py +35 -0
  30. grpc/aio/_utils.py +22 -0
  31. grpc/beta/__init__.py +13 -0
  32. grpc/beta/_client_adaptations.py +706 -0
  33. grpc/beta/_metadata.py +52 -0
  34. grpc/beta/_server_adaptations.py +385 -0
  35. grpc/beta/implementations.py +311 -0
  36. grpc/beta/interfaces.py +164 -0
  37. grpc/beta/utilities.py +149 -0
  38. grpc/experimental/__init__.py +128 -0
  39. grpc/experimental/aio/__init__.py +16 -0
  40. grpc/experimental/gevent.py +27 -0
  41. grpc/experimental/session_cache.py +45 -0
  42. grpc/framework/__init__.py +13 -0
  43. grpc/framework/common/__init__.py +13 -0
  44. grpc/framework/common/cardinality.py +26 -0
  45. grpc/framework/common/style.py +24 -0
  46. grpc/framework/foundation/__init__.py +13 -0
  47. grpc/framework/foundation/abandonment.py +22 -0
  48. grpc/framework/foundation/callable_util.py +96 -0
  49. grpc/framework/foundation/future.py +221 -0
  50. grpc/framework/foundation/logging_pool.py +71 -0
  51. grpc/framework/foundation/stream.py +45 -0
  52. grpc/framework/foundation/stream_util.py +148 -0
  53. grpc/framework/interfaces/__init__.py +13 -0
  54. grpc/framework/interfaces/base/__init__.py +13 -0
  55. grpc/framework/interfaces/base/base.py +327 -0
  56. grpc/framework/interfaces/base/utilities.py +71 -0
  57. grpc/framework/interfaces/face/__init__.py +13 -0
  58. grpc/framework/interfaces/face/face.py +1050 -0
  59. grpc/framework/interfaces/face/utilities.py +168 -0
  60. grpcio_fips-1.44.0.dist-info/LICENSE +242 -0
  61. grpcio_fips-1.44.0.dist-info/METADATA +143 -0
  62. grpcio_fips-1.44.0.dist-info/RECORD +64 -0
  63. grpcio_fips-1.44.0.dist-info/WHEEL +5 -0
  64. grpcio_fips-1.44.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,71 @@
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
+ """A thread pool that logs exceptions raised by tasks executed within it."""
15
+
16
+ from concurrent import futures
17
+ import logging
18
+
19
+ _LOGGER = logging.getLogger(__name__)
20
+
21
+
22
+ def _wrap(behavior):
23
+ """Wraps an arbitrary callable behavior in exception-logging."""
24
+
25
+ def _wrapping(*args, **kwargs):
26
+ try:
27
+ return behavior(*args, **kwargs)
28
+ except Exception:
29
+ _LOGGER.exception(
30
+ 'Unexpected exception from %s executed in logging pool!',
31
+ behavior)
32
+ raise
33
+
34
+ return _wrapping
35
+
36
+
37
+ class _LoggingPool(object):
38
+ """An exception-logging futures.ThreadPoolExecutor-compatible thread pool."""
39
+
40
+ def __init__(self, backing_pool):
41
+ self._backing_pool = backing_pool
42
+
43
+ def __enter__(self):
44
+ return self
45
+
46
+ def __exit__(self, exc_type, exc_val, exc_tb):
47
+ self._backing_pool.shutdown(wait=True)
48
+
49
+ def submit(self, fn, *args, **kwargs):
50
+ return self._backing_pool.submit(_wrap(fn), *args, **kwargs)
51
+
52
+ def map(self, func, *iterables, **kwargs):
53
+ return self._backing_pool.map(_wrap(func),
54
+ *iterables,
55
+ timeout=kwargs.get('timeout', None))
56
+
57
+ def shutdown(self, wait=True):
58
+ self._backing_pool.shutdown(wait=wait)
59
+
60
+
61
+ def pool(max_workers):
62
+ """Creates a thread pool that logs exceptions raised by the tasks within it.
63
+
64
+ Args:
65
+ max_workers: The maximum number of worker threads to allow the pool.
66
+
67
+ Returns:
68
+ A futures.ThreadPoolExecutor-compatible thread pool that logs exceptions
69
+ raised by the tasks executed within it.
70
+ """
71
+ return _LoggingPool(futures.ThreadPoolExecutor(max_workers))
@@ -0,0 +1,45 @@
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
+ """Interfaces related to streams of values or objects."""
15
+
16
+ import abc
17
+
18
+ import six
19
+
20
+
21
+ class Consumer(six.with_metaclass(abc.ABCMeta)):
22
+ """Interface for consumers of finite streams of values or objects."""
23
+
24
+ @abc.abstractmethod
25
+ def consume(self, value):
26
+ """Accepts a value.
27
+
28
+ Args:
29
+ value: Any value accepted by this Consumer.
30
+ """
31
+ raise NotImplementedError()
32
+
33
+ @abc.abstractmethod
34
+ def terminate(self):
35
+ """Indicates to this Consumer that no more values will be supplied."""
36
+ raise NotImplementedError()
37
+
38
+ @abc.abstractmethod
39
+ def consume_and_terminate(self, value):
40
+ """Supplies a value and signals that no more values will be supplied.
41
+
42
+ Args:
43
+ value: Any value accepted by this Consumer.
44
+ """
45
+ raise NotImplementedError()
@@ -0,0 +1,148 @@
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
+ """Helpful utilities related to the stream module."""
15
+
16
+ import logging
17
+ import threading
18
+
19
+ from grpc.framework.foundation import stream
20
+
21
+ _NO_VALUE = object()
22
+ _LOGGER = logging.getLogger(__name__)
23
+
24
+
25
+ class TransformingConsumer(stream.Consumer):
26
+ """A stream.Consumer that passes a transformation of its input to another."""
27
+
28
+ def __init__(self, transformation, downstream):
29
+ self._transformation = transformation
30
+ self._downstream = downstream
31
+
32
+ def consume(self, value):
33
+ self._downstream.consume(self._transformation(value))
34
+
35
+ def terminate(self):
36
+ self._downstream.terminate()
37
+
38
+ def consume_and_terminate(self, value):
39
+ self._downstream.consume_and_terminate(self._transformation(value))
40
+
41
+
42
+ class IterableConsumer(stream.Consumer):
43
+ """A Consumer that when iterated over emits the values it has consumed."""
44
+
45
+ def __init__(self):
46
+ self._condition = threading.Condition()
47
+ self._values = []
48
+ self._active = True
49
+
50
+ def consume(self, value):
51
+ with self._condition:
52
+ if self._active:
53
+ self._values.append(value)
54
+ self._condition.notify()
55
+
56
+ def terminate(self):
57
+ with self._condition:
58
+ self._active = False
59
+ self._condition.notify()
60
+
61
+ def consume_and_terminate(self, value):
62
+ with self._condition:
63
+ if self._active:
64
+ self._values.append(value)
65
+ self._active = False
66
+ self._condition.notify()
67
+
68
+ def __iter__(self):
69
+ return self
70
+
71
+ def __next__(self):
72
+ return self.next()
73
+
74
+ def next(self):
75
+ with self._condition:
76
+ while self._active and not self._values:
77
+ self._condition.wait()
78
+ if self._values:
79
+ return self._values.pop(0)
80
+ else:
81
+ raise StopIteration()
82
+
83
+
84
+ class ThreadSwitchingConsumer(stream.Consumer):
85
+ """A Consumer decorator that affords serialization and asynchrony."""
86
+
87
+ def __init__(self, sink, pool):
88
+ self._lock = threading.Lock()
89
+ self._sink = sink
90
+ self._pool = pool
91
+ # True if self._spin has been submitted to the pool to be called once and
92
+ # that call has not yet returned, False otherwise.
93
+ self._spinning = False
94
+ self._values = []
95
+ self._active = True
96
+
97
+ def _spin(self, sink, value, terminate):
98
+ while True:
99
+ try:
100
+ if value is _NO_VALUE:
101
+ sink.terminate()
102
+ elif terminate:
103
+ sink.consume_and_terminate(value)
104
+ else:
105
+ sink.consume(value)
106
+ except Exception as e: # pylint:disable=broad-except
107
+ _LOGGER.exception(e)
108
+
109
+ with self._lock:
110
+ if terminate:
111
+ self._spinning = False
112
+ return
113
+ elif self._values:
114
+ value = self._values.pop(0)
115
+ terminate = not self._values and not self._active
116
+ elif not self._active:
117
+ value = _NO_VALUE
118
+ terminate = True
119
+ else:
120
+ self._spinning = False
121
+ return
122
+
123
+ def consume(self, value):
124
+ with self._lock:
125
+ if self._active:
126
+ if self._spinning:
127
+ self._values.append(value)
128
+ else:
129
+ self._pool.submit(self._spin, self._sink, value, False)
130
+ self._spinning = True
131
+
132
+ def terminate(self):
133
+ with self._lock:
134
+ if self._active:
135
+ self._active = False
136
+ if not self._spinning:
137
+ self._pool.submit(self._spin, self._sink, _NO_VALUE, True)
138
+ self._spinning = True
139
+
140
+ def consume_and_terminate(self, value):
141
+ with self._lock:
142
+ if self._active:
143
+ self._active = False
144
+ if self._spinning:
145
+ self._values.append(value)
146
+ else:
147
+ self._pool.submit(self._spin, self._sink, value, True)
148
+ self._spinning = True
@@ -0,0 +1,13 @@
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.
@@ -0,0 +1,13 @@
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.
@@ -0,0 +1,327 @@
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
+ """The base interface of RPC Framework.
15
+
16
+ Implementations of this interface support the conduct of "operations":
17
+ exchanges between two distinct ends of an arbitrary number of data payloads
18
+ and metadata such as a name for the operation, initial and terminal metadata
19
+ in each direction, and flow control. These operations may be used for transfers
20
+ of data, remote procedure calls, status indication, or anything else
21
+ applications choose.
22
+ """
23
+
24
+ # threading is referenced from specification in this module.
25
+ import abc
26
+ import enum
27
+ import threading # pylint: disable=unused-import
28
+
29
+ import six
30
+
31
+ # pylint: disable=too-many-arguments
32
+
33
+
34
+ class NoSuchMethodError(Exception):
35
+ """Indicates that an unrecognized operation has been called.
36
+
37
+ Attributes:
38
+ code: A code value to communicate to the other side of the operation
39
+ along with indication of operation termination. May be None.
40
+ details: A details value to communicate to the other side of the
41
+ operation along with indication of operation termination. May be None.
42
+ """
43
+
44
+ def __init__(self, code, details):
45
+ """Constructor.
46
+
47
+ Args:
48
+ code: A code value to communicate to the other side of the operation
49
+ along with indication of operation termination. May be None.
50
+ details: A details value to communicate to the other side of the
51
+ operation along with indication of operation termination. May be None.
52
+ """
53
+ super(NoSuchMethodError, self).__init__()
54
+ self.code = code
55
+ self.details = details
56
+
57
+
58
+ class Outcome(object):
59
+ """The outcome of an operation.
60
+
61
+ Attributes:
62
+ kind: A Kind value coarsely identifying how the operation terminated.
63
+ code: An application-specific code value or None if no such value was
64
+ provided.
65
+ details: An application-specific details value or None if no such value was
66
+ provided.
67
+ """
68
+
69
+ @enum.unique
70
+ class Kind(enum.Enum):
71
+ """Ways in which an operation can terminate."""
72
+
73
+ COMPLETED = 'completed'
74
+ CANCELLED = 'cancelled'
75
+ EXPIRED = 'expired'
76
+ LOCAL_SHUTDOWN = 'local shutdown'
77
+ REMOTE_SHUTDOWN = 'remote shutdown'
78
+ RECEPTION_FAILURE = 'reception failure'
79
+ TRANSMISSION_FAILURE = 'transmission failure'
80
+ LOCAL_FAILURE = 'local failure'
81
+ REMOTE_FAILURE = 'remote failure'
82
+
83
+
84
+ class Completion(six.with_metaclass(abc.ABCMeta)):
85
+ """An aggregate of the values exchanged upon operation completion.
86
+
87
+ Attributes:
88
+ terminal_metadata: A terminal metadata value for the operaton.
89
+ code: A code value for the operation.
90
+ message: A message value for the operation.
91
+ """
92
+
93
+
94
+ class OperationContext(six.with_metaclass(abc.ABCMeta)):
95
+ """Provides operation-related information and action."""
96
+
97
+ @abc.abstractmethod
98
+ def outcome(self):
99
+ """Indicates the operation's outcome (or that the operation is ongoing).
100
+
101
+ Returns:
102
+ None if the operation is still active or the Outcome value for the
103
+ operation if it has terminated.
104
+ """
105
+ raise NotImplementedError()
106
+
107
+ @abc.abstractmethod
108
+ def add_termination_callback(self, callback):
109
+ """Adds a function to be called upon operation termination.
110
+
111
+ Args:
112
+ callback: A callable to be passed an Outcome value on operation
113
+ termination.
114
+
115
+ Returns:
116
+ None if the operation has not yet terminated and the passed callback will
117
+ later be called when it does terminate, or if the operation has already
118
+ terminated an Outcome value describing the operation termination and the
119
+ passed callback will not be called as a result of this method call.
120
+ """
121
+ raise NotImplementedError()
122
+
123
+ @abc.abstractmethod
124
+ def time_remaining(self):
125
+ """Describes the length of allowed time remaining for the operation.
126
+
127
+ Returns:
128
+ A nonnegative float indicating the length of allowed time in seconds
129
+ remaining for the operation to complete before it is considered to have
130
+ timed out. Zero is returned if the operation has terminated.
131
+ """
132
+ raise NotImplementedError()
133
+
134
+ @abc.abstractmethod
135
+ def cancel(self):
136
+ """Cancels the operation if the operation has not yet terminated."""
137
+ raise NotImplementedError()
138
+
139
+ @abc.abstractmethod
140
+ def fail(self, exception):
141
+ """Indicates that the operation has failed.
142
+
143
+ Args:
144
+ exception: An exception germane to the operation failure. May be None.
145
+ """
146
+ raise NotImplementedError()
147
+
148
+
149
+ class Operator(six.with_metaclass(abc.ABCMeta)):
150
+ """An interface through which to participate in an operation."""
151
+
152
+ @abc.abstractmethod
153
+ def advance(self,
154
+ initial_metadata=None,
155
+ payload=None,
156
+ completion=None,
157
+ allowance=None):
158
+ """Progresses the operation.
159
+
160
+ Args:
161
+ initial_metadata: An initial metadata value. Only one may ever be
162
+ communicated in each direction for an operation, and they must be
163
+ communicated no later than either the first payload or the completion.
164
+ payload: A payload value.
165
+ completion: A Completion value. May only ever be non-None once in either
166
+ direction, and no payloads may be passed after it has been communicated.
167
+ allowance: A positive integer communicating the number of additional
168
+ payloads allowed to be passed by the remote side of the operation.
169
+ """
170
+ raise NotImplementedError()
171
+
172
+
173
+ class ProtocolReceiver(six.with_metaclass(abc.ABCMeta)):
174
+ """A means of receiving protocol values during an operation."""
175
+
176
+ @abc.abstractmethod
177
+ def context(self, protocol_context):
178
+ """Accepts the protocol context object for the operation.
179
+
180
+ Args:
181
+ protocol_context: The protocol context object for the operation.
182
+ """
183
+ raise NotImplementedError()
184
+
185
+
186
+ class Subscription(six.with_metaclass(abc.ABCMeta)):
187
+ """Describes customer code's interest in values from the other side.
188
+
189
+ Attributes:
190
+ kind: A Kind value describing the overall kind of this value.
191
+ termination_callback: A callable to be passed the Outcome associated with
192
+ the operation after it has terminated. Must be non-None if kind is
193
+ Kind.TERMINATION_ONLY. Must be None otherwise.
194
+ allowance: A callable behavior that accepts positive integers representing
195
+ the number of additional payloads allowed to be passed to the other side
196
+ of the operation. Must be None if kind is Kind.FULL. Must not be None
197
+ otherwise.
198
+ operator: An Operator to be passed values from the other side of the
199
+ operation. Must be non-None if kind is Kind.FULL. Must be None otherwise.
200
+ protocol_receiver: A ProtocolReceiver to be passed protocol objects as they
201
+ become available during the operation. Must be non-None if kind is
202
+ Kind.FULL.
203
+ """
204
+
205
+ @enum.unique
206
+ class Kind(enum.Enum):
207
+
208
+ NONE = 'none'
209
+ TERMINATION_ONLY = 'termination only'
210
+ FULL = 'full'
211
+
212
+
213
+ class Servicer(six.with_metaclass(abc.ABCMeta)):
214
+ """Interface for service implementations."""
215
+
216
+ @abc.abstractmethod
217
+ def service(self, group, method, context, output_operator):
218
+ """Services an operation.
219
+
220
+ Args:
221
+ group: The group identifier of the operation to be serviced.
222
+ method: The method identifier of the operation to be serviced.
223
+ context: An OperationContext object affording contextual information and
224
+ actions.
225
+ output_operator: An Operator that will accept output values of the
226
+ operation.
227
+
228
+ Returns:
229
+ A Subscription via which this object may or may not accept more values of
230
+ the operation.
231
+
232
+ Raises:
233
+ NoSuchMethodError: If this Servicer does not handle operations with the
234
+ given group and method.
235
+ abandonment.Abandoned: If the operation has been aborted and there no
236
+ longer is any reason to service the operation.
237
+ """
238
+ raise NotImplementedError()
239
+
240
+
241
+ class End(six.with_metaclass(abc.ABCMeta)):
242
+ """Common type for entry-point objects on both sides of an operation."""
243
+
244
+ @abc.abstractmethod
245
+ def start(self):
246
+ """Starts this object's service of operations."""
247
+ raise NotImplementedError()
248
+
249
+ @abc.abstractmethod
250
+ def stop(self, grace):
251
+ """Stops this object's service of operations.
252
+
253
+ This object will refuse service of new operations as soon as this method is
254
+ called but operations under way at the time of the call may be given a
255
+ grace period during which they are allowed to finish.
256
+
257
+ Args:
258
+ grace: A duration of time in seconds to allow ongoing operations to
259
+ terminate before being forcefully terminated by the stopping of this
260
+ End. May be zero to terminate all ongoing operations and immediately
261
+ stop.
262
+
263
+ Returns:
264
+ A threading.Event that will be set to indicate all operations having
265
+ terminated and this End having completely stopped. The returned event
266
+ may not be set until after the full grace period (if some ongoing
267
+ operation continues for the full length of the period) or it may be set
268
+ much sooner (if for example this End had no operations in progress at
269
+ the time its stop method was called).
270
+ """
271
+ raise NotImplementedError()
272
+
273
+ @abc.abstractmethod
274
+ def operate(self,
275
+ group,
276
+ method,
277
+ subscription,
278
+ timeout,
279
+ initial_metadata=None,
280
+ payload=None,
281
+ completion=None,
282
+ protocol_options=None):
283
+ """Commences an operation.
284
+
285
+ Args:
286
+ group: The group identifier of the invoked operation.
287
+ method: The method identifier of the invoked operation.
288
+ subscription: A Subscription to which the results of the operation will be
289
+ passed.
290
+ timeout: A length of time in seconds to allow for the operation.
291
+ initial_metadata: An initial metadata value to be sent to the other side
292
+ of the operation. May be None if the initial metadata will be later
293
+ passed via the returned operator or if there will be no initial metadata
294
+ passed at all.
295
+ payload: An initial payload for the operation.
296
+ completion: A Completion value indicating the end of transmission to the
297
+ other side of the operation.
298
+ protocol_options: A value specified by the provider of a Base interface
299
+ implementation affording custom state and behavior.
300
+
301
+ Returns:
302
+ A pair of objects affording information about the operation and action
303
+ continuing the operation. The first element of the returned pair is an
304
+ OperationContext for the operation and the second element of the
305
+ returned pair is an Operator to which operation values not passed in
306
+ this call should later be passed.
307
+ """
308
+ raise NotImplementedError()
309
+
310
+ @abc.abstractmethod
311
+ def operation_stats(self):
312
+ """Reports the number of terminated operations broken down by outcome.
313
+
314
+ Returns:
315
+ A dictionary from Outcome.Kind value to an integer identifying the number
316
+ of operations that terminated with that outcome kind.
317
+ """
318
+ raise NotImplementedError()
319
+
320
+ @abc.abstractmethod
321
+ def add_idle_action(self, action):
322
+ """Adds an action to be called when this End has no ongoing operations.
323
+
324
+ Args:
325
+ action: A callable that accepts no arguments.
326
+ """
327
+ raise NotImplementedError()
@@ -0,0 +1,71 @@
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 use with the base interface of RPC Framework."""
15
+
16
+ import collections
17
+
18
+ from grpc.framework.interfaces.base import base
19
+
20
+
21
+ class _Completion(base.Completion,
22
+ collections.namedtuple('_Completion', (
23
+ 'terminal_metadata',
24
+ 'code',
25
+ 'message',
26
+ ))):
27
+ """A trivial implementation of base.Completion."""
28
+
29
+
30
+ class _Subscription(base.Subscription,
31
+ collections.namedtuple('_Subscription', (
32
+ 'kind',
33
+ 'termination_callback',
34
+ 'allowance',
35
+ 'operator',
36
+ 'protocol_receiver',
37
+ ))):
38
+ """A trivial implementation of base.Subscription."""
39
+
40
+
41
+ _NONE_SUBSCRIPTION = _Subscription(base.Subscription.Kind.NONE, None, None,
42
+ None, None)
43
+
44
+
45
+ def completion(terminal_metadata, code, message):
46
+ """Creates a base.Completion aggregating the given operation values.
47
+
48
+ Args:
49
+ terminal_metadata: A terminal metadata value for an operaton.
50
+ code: A code value for an operation.
51
+ message: A message value for an operation.
52
+
53
+ Returns:
54
+ A base.Completion aggregating the given operation values.
55
+ """
56
+ return _Completion(terminal_metadata, code, message)
57
+
58
+
59
+ def full_subscription(operator, protocol_receiver):
60
+ """Creates a "full" base.Subscription for the given base.Operator.
61
+
62
+ Args:
63
+ operator: A base.Operator to be used in an operation.
64
+ protocol_receiver: A base.ProtocolReceiver to be used in an operation.
65
+
66
+ Returns:
67
+ A base.Subscription of kind base.Subscription.Kind.FULL wrapping the given
68
+ base.Operator and base.ProtocolReceiver.
69
+ """
70
+ return _Subscription(base.Subscription.Kind.FULL, None, None, operator,
71
+ protocol_receiver)