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
grpc/aio/_channel.py ADDED
@@ -0,0 +1,484 @@
1
+ # Copyright 2019 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
+ """Invocation-side implementation of gRPC Asyncio Python."""
15
+
16
+ import asyncio
17
+ import sys
18
+ from typing import Any, Iterable, List, Optional, Sequence
19
+
20
+ import grpc
21
+ from grpc import _common
22
+ from grpc import _compression
23
+ from grpc import _grpcio_metadata
24
+ from grpc._cython import cygrpc
25
+
26
+ from . import _base_call
27
+ from . import _base_channel
28
+ from ._call import StreamStreamCall
29
+ from ._call import StreamUnaryCall
30
+ from ._call import UnaryStreamCall
31
+ from ._call import UnaryUnaryCall
32
+ from ._interceptor import ClientInterceptor
33
+ from ._interceptor import InterceptedStreamStreamCall
34
+ from ._interceptor import InterceptedStreamUnaryCall
35
+ from ._interceptor import InterceptedUnaryStreamCall
36
+ from ._interceptor import InterceptedUnaryUnaryCall
37
+ from ._interceptor import StreamStreamClientInterceptor
38
+ from ._interceptor import StreamUnaryClientInterceptor
39
+ from ._interceptor import UnaryStreamClientInterceptor
40
+ from ._interceptor import UnaryUnaryClientInterceptor
41
+ from ._metadata import Metadata
42
+ from ._typing import ChannelArgumentType
43
+ from ._typing import DeserializingFunction
44
+ from ._typing import RequestIterableType
45
+ from ._typing import SerializingFunction
46
+ from ._utils import _timeout_to_deadline
47
+
48
+ _USER_AGENT = 'grpc-python-asyncio/{}'.format(_grpcio_metadata.__version__)
49
+
50
+ if sys.version_info[1] < 7:
51
+
52
+ def _all_tasks() -> Iterable[asyncio.Task]:
53
+ return asyncio.Task.all_tasks()
54
+ else:
55
+
56
+ def _all_tasks() -> Iterable[asyncio.Task]:
57
+ return asyncio.all_tasks()
58
+
59
+
60
+ def _augment_channel_arguments(base_options: ChannelArgumentType,
61
+ compression: Optional[grpc.Compression]):
62
+ compression_channel_argument = _compression.create_channel_option(
63
+ compression)
64
+ user_agent_channel_argument = ((
65
+ cygrpc.ChannelArgKey.primary_user_agent_string,
66
+ _USER_AGENT,
67
+ ),)
68
+ return tuple(base_options
69
+ ) + compression_channel_argument + user_agent_channel_argument
70
+
71
+
72
+ class _BaseMultiCallable:
73
+ """Base class of all multi callable objects.
74
+
75
+ Handles the initialization logic and stores common attributes.
76
+ """
77
+ _loop: asyncio.AbstractEventLoop
78
+ _channel: cygrpc.AioChannel
79
+ _method: bytes
80
+ _request_serializer: SerializingFunction
81
+ _response_deserializer: DeserializingFunction
82
+ _interceptors: Optional[Sequence[ClientInterceptor]]
83
+ _loop: asyncio.AbstractEventLoop
84
+
85
+ # pylint: disable=too-many-arguments
86
+ def __init__(
87
+ self,
88
+ channel: cygrpc.AioChannel,
89
+ method: bytes,
90
+ request_serializer: SerializingFunction,
91
+ response_deserializer: DeserializingFunction,
92
+ interceptors: Optional[Sequence[ClientInterceptor]],
93
+ loop: asyncio.AbstractEventLoop,
94
+ ) -> None:
95
+ self._loop = loop
96
+ self._channel = channel
97
+ self._method = method
98
+ self._request_serializer = request_serializer
99
+ self._response_deserializer = response_deserializer
100
+ self._interceptors = interceptors
101
+
102
+ @staticmethod
103
+ def _init_metadata(
104
+ metadata: Optional[Metadata] = None,
105
+ compression: Optional[grpc.Compression] = None) -> Metadata:
106
+ """Based on the provided values for <metadata> or <compression> initialise the final
107
+ metadata, as it should be used for the current call.
108
+ """
109
+ metadata = metadata or Metadata()
110
+ if compression:
111
+ metadata = Metadata(
112
+ *_compression.augment_metadata(metadata, compression))
113
+ return metadata
114
+
115
+
116
+ class UnaryUnaryMultiCallable(_BaseMultiCallable,
117
+ _base_channel.UnaryUnaryMultiCallable):
118
+
119
+ def __call__(
120
+ self,
121
+ request: Any,
122
+ *,
123
+ timeout: Optional[float] = None,
124
+ metadata: Optional[Metadata] = None,
125
+ credentials: Optional[grpc.CallCredentials] = None,
126
+ wait_for_ready: Optional[bool] = None,
127
+ compression: Optional[grpc.Compression] = None
128
+ ) -> _base_call.UnaryUnaryCall:
129
+
130
+ metadata = self._init_metadata(metadata, compression)
131
+ if not self._interceptors:
132
+ call = UnaryUnaryCall(request, _timeout_to_deadline(timeout),
133
+ metadata, credentials, wait_for_ready,
134
+ self._channel, self._method,
135
+ self._request_serializer,
136
+ self._response_deserializer, self._loop)
137
+ else:
138
+ call = InterceptedUnaryUnaryCall(
139
+ self._interceptors, request, timeout, metadata, credentials,
140
+ wait_for_ready, self._channel, self._method,
141
+ self._request_serializer, self._response_deserializer,
142
+ self._loop)
143
+
144
+ return call
145
+
146
+
147
+ class UnaryStreamMultiCallable(_BaseMultiCallable,
148
+ _base_channel.UnaryStreamMultiCallable):
149
+
150
+ def __call__(
151
+ self,
152
+ request: Any,
153
+ *,
154
+ timeout: Optional[float] = None,
155
+ metadata: Optional[Metadata] = None,
156
+ credentials: Optional[grpc.CallCredentials] = None,
157
+ wait_for_ready: Optional[bool] = None,
158
+ compression: Optional[grpc.Compression] = None
159
+ ) -> _base_call.UnaryStreamCall:
160
+
161
+ metadata = self._init_metadata(metadata, compression)
162
+ deadline = _timeout_to_deadline(timeout)
163
+
164
+ if not self._interceptors:
165
+ call = UnaryStreamCall(request, deadline, metadata, credentials,
166
+ wait_for_ready, self._channel, self._method,
167
+ self._request_serializer,
168
+ self._response_deserializer, self._loop)
169
+ else:
170
+ call = InterceptedUnaryStreamCall(
171
+ self._interceptors, request, deadline, metadata, credentials,
172
+ wait_for_ready, self._channel, self._method,
173
+ self._request_serializer, self._response_deserializer,
174
+ self._loop)
175
+
176
+ return call
177
+
178
+
179
+ class StreamUnaryMultiCallable(_BaseMultiCallable,
180
+ _base_channel.StreamUnaryMultiCallable):
181
+
182
+ def __call__(
183
+ self,
184
+ request_iterator: Optional[RequestIterableType] = None,
185
+ timeout: Optional[float] = None,
186
+ metadata: Optional[Metadata] = None,
187
+ credentials: Optional[grpc.CallCredentials] = None,
188
+ wait_for_ready: Optional[bool] = None,
189
+ compression: Optional[grpc.Compression] = None
190
+ ) -> _base_call.StreamUnaryCall:
191
+
192
+ metadata = self._init_metadata(metadata, compression)
193
+ deadline = _timeout_to_deadline(timeout)
194
+
195
+ if not self._interceptors:
196
+ call = StreamUnaryCall(request_iterator, deadline, metadata,
197
+ credentials, wait_for_ready, self._channel,
198
+ self._method, self._request_serializer,
199
+ self._response_deserializer, self._loop)
200
+ else:
201
+ call = InterceptedStreamUnaryCall(
202
+ self._interceptors, request_iterator, deadline, metadata,
203
+ credentials, wait_for_ready, self._channel, self._method,
204
+ self._request_serializer, self._response_deserializer,
205
+ self._loop)
206
+
207
+ return call
208
+
209
+
210
+ class StreamStreamMultiCallable(_BaseMultiCallable,
211
+ _base_channel.StreamStreamMultiCallable):
212
+
213
+ def __call__(
214
+ self,
215
+ request_iterator: Optional[RequestIterableType] = None,
216
+ timeout: Optional[float] = None,
217
+ metadata: Optional[Metadata] = None,
218
+ credentials: Optional[grpc.CallCredentials] = None,
219
+ wait_for_ready: Optional[bool] = None,
220
+ compression: Optional[grpc.Compression] = None
221
+ ) -> _base_call.StreamStreamCall:
222
+
223
+ metadata = self._init_metadata(metadata, compression)
224
+ deadline = _timeout_to_deadline(timeout)
225
+
226
+ if not self._interceptors:
227
+ call = StreamStreamCall(request_iterator, deadline, metadata,
228
+ credentials, wait_for_ready, self._channel,
229
+ self._method, self._request_serializer,
230
+ self._response_deserializer, self._loop)
231
+ else:
232
+ call = InterceptedStreamStreamCall(
233
+ self._interceptors, request_iterator, deadline, metadata,
234
+ credentials, wait_for_ready, self._channel, self._method,
235
+ self._request_serializer, self._response_deserializer,
236
+ self._loop)
237
+
238
+ return call
239
+
240
+
241
+ class Channel(_base_channel.Channel):
242
+ _loop: asyncio.AbstractEventLoop
243
+ _channel: cygrpc.AioChannel
244
+ _unary_unary_interceptors: List[UnaryUnaryClientInterceptor]
245
+ _unary_stream_interceptors: List[UnaryStreamClientInterceptor]
246
+ _stream_unary_interceptors: List[StreamUnaryClientInterceptor]
247
+ _stream_stream_interceptors: List[StreamStreamClientInterceptor]
248
+
249
+ def __init__(self, target: str, options: ChannelArgumentType,
250
+ credentials: Optional[grpc.ChannelCredentials],
251
+ compression: Optional[grpc.Compression],
252
+ interceptors: Optional[Sequence[ClientInterceptor]]):
253
+ """Constructor.
254
+
255
+ Args:
256
+ target: The target to which to connect.
257
+ options: Configuration options for the channel.
258
+ credentials: A cygrpc.ChannelCredentials or None.
259
+ compression: An optional value indicating the compression method to be
260
+ used over the lifetime of the channel.
261
+ interceptors: An optional list of interceptors that would be used for
262
+ intercepting any RPC executed with that channel.
263
+ """
264
+ self._unary_unary_interceptors = []
265
+ self._unary_stream_interceptors = []
266
+ self._stream_unary_interceptors = []
267
+ self._stream_stream_interceptors = []
268
+
269
+ if interceptors is not None:
270
+ for interceptor in interceptors:
271
+ if isinstance(interceptor, UnaryUnaryClientInterceptor):
272
+ self._unary_unary_interceptors.append(interceptor)
273
+ elif isinstance(interceptor, UnaryStreamClientInterceptor):
274
+ self._unary_stream_interceptors.append(interceptor)
275
+ elif isinstance(interceptor, StreamUnaryClientInterceptor):
276
+ self._stream_unary_interceptors.append(interceptor)
277
+ elif isinstance(interceptor, StreamStreamClientInterceptor):
278
+ self._stream_stream_interceptors.append(interceptor)
279
+ else:
280
+ raise ValueError(
281
+ "Interceptor {} must be ".format(interceptor) +
282
+ "{} or ".format(UnaryUnaryClientInterceptor.__name__) +
283
+ "{} or ".format(UnaryStreamClientInterceptor.__name__) +
284
+ "{} or ".format(StreamUnaryClientInterceptor.__name__) +
285
+ "{}. ".format(StreamStreamClientInterceptor.__name__))
286
+
287
+ self._loop = cygrpc.get_working_loop()
288
+ self._channel = cygrpc.AioChannel(
289
+ _common.encode(target),
290
+ _augment_channel_arguments(options, compression), credentials,
291
+ self._loop)
292
+
293
+ async def __aenter__(self):
294
+ return self
295
+
296
+ async def __aexit__(self, exc_type, exc_val, exc_tb):
297
+ await self._close(None)
298
+
299
+ async def _close(self, grace): # pylint: disable=too-many-branches
300
+ if self._channel.closed():
301
+ return
302
+
303
+ # No new calls will be accepted by the Cython channel.
304
+ self._channel.closing()
305
+
306
+ # Iterate through running tasks
307
+ tasks = _all_tasks()
308
+ calls = []
309
+ call_tasks = []
310
+ for task in tasks:
311
+ try:
312
+ stack = task.get_stack(limit=1)
313
+ except AttributeError as attribute_error:
314
+ # NOTE(lidiz) tl;dr: If the Task is created with a CPython
315
+ # object, it will trigger AttributeError.
316
+ #
317
+ # In the global finalizer, the event loop schedules
318
+ # a CPython PyAsyncGenAThrow object.
319
+ # https://github.com/python/cpython/blob/00e45877e33d32bb61aa13a2033e3bba370bda4d/Lib/asyncio/base_events.py#L484
320
+ #
321
+ # However, the PyAsyncGenAThrow object is written in C and
322
+ # failed to include the normal Python frame objects. Hence,
323
+ # this exception is a false negative, and it is safe to ignore
324
+ # the failure. It is fixed by https://github.com/python/cpython/pull/18669,
325
+ # but not available until 3.9 or 3.8.3. So, we have to keep it
326
+ # for a while.
327
+ # TODO(lidiz) drop this hack after 3.8 deprecation
328
+ if 'frame' in str(attribute_error):
329
+ continue
330
+ else:
331
+ raise
332
+
333
+ # If the Task is created by a C-extension, the stack will be empty.
334
+ if not stack:
335
+ continue
336
+
337
+ # Locate ones created by `aio.Call`.
338
+ frame = stack[0]
339
+ candidate = frame.f_locals.get('self')
340
+ if candidate:
341
+ if isinstance(candidate, _base_call.Call):
342
+ if hasattr(candidate, '_channel'):
343
+ # For intercepted Call object
344
+ if candidate._channel is not self._channel:
345
+ continue
346
+ elif hasattr(candidate, '_cython_call'):
347
+ # For normal Call object
348
+ if candidate._cython_call._channel is not self._channel:
349
+ continue
350
+ else:
351
+ # Unidentified Call object
352
+ raise cygrpc.InternalError(
353
+ f'Unrecognized call object: {candidate}')
354
+
355
+ calls.append(candidate)
356
+ call_tasks.append(task)
357
+
358
+ # If needed, try to wait for them to finish.
359
+ # Call objects are not always awaitables.
360
+ if grace and call_tasks:
361
+ await asyncio.wait(call_tasks, timeout=grace)
362
+
363
+ # Time to cancel existing calls.
364
+ for call in calls:
365
+ call.cancel()
366
+
367
+ # Destroy the channel
368
+ self._channel.close()
369
+
370
+ async def close(self, grace: Optional[float] = None):
371
+ await self._close(grace)
372
+
373
+ def get_state(self,
374
+ try_to_connect: bool = False) -> grpc.ChannelConnectivity:
375
+ result = self._channel.check_connectivity_state(try_to_connect)
376
+ return _common.CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[result]
377
+
378
+ async def wait_for_state_change(
379
+ self,
380
+ last_observed_state: grpc.ChannelConnectivity,
381
+ ) -> None:
382
+ assert await self._channel.watch_connectivity_state(
383
+ last_observed_state.value[0], None)
384
+
385
+ async def channel_ready(self) -> None:
386
+ state = self.get_state(try_to_connect=True)
387
+ while state != grpc.ChannelConnectivity.READY:
388
+ await self.wait_for_state_change(state)
389
+ state = self.get_state(try_to_connect=True)
390
+
391
+ def unary_unary(
392
+ self,
393
+ method: str,
394
+ request_serializer: Optional[SerializingFunction] = None,
395
+ response_deserializer: Optional[DeserializingFunction] = None
396
+ ) -> UnaryUnaryMultiCallable:
397
+ return UnaryUnaryMultiCallable(self._channel, _common.encode(method),
398
+ request_serializer,
399
+ response_deserializer,
400
+ self._unary_unary_interceptors,
401
+ self._loop)
402
+
403
+ def unary_stream(
404
+ self,
405
+ method: str,
406
+ request_serializer: Optional[SerializingFunction] = None,
407
+ response_deserializer: Optional[DeserializingFunction] = None
408
+ ) -> UnaryStreamMultiCallable:
409
+ return UnaryStreamMultiCallable(self._channel, _common.encode(method),
410
+ request_serializer,
411
+ response_deserializer,
412
+ self._unary_stream_interceptors,
413
+ self._loop)
414
+
415
+ def stream_unary(
416
+ self,
417
+ method: str,
418
+ request_serializer: Optional[SerializingFunction] = None,
419
+ response_deserializer: Optional[DeserializingFunction] = None
420
+ ) -> StreamUnaryMultiCallable:
421
+ return StreamUnaryMultiCallable(self._channel, _common.encode(method),
422
+ request_serializer,
423
+ response_deserializer,
424
+ self._stream_unary_interceptors,
425
+ self._loop)
426
+
427
+ def stream_stream(
428
+ self,
429
+ method: str,
430
+ request_serializer: Optional[SerializingFunction] = None,
431
+ response_deserializer: Optional[DeserializingFunction] = None
432
+ ) -> StreamStreamMultiCallable:
433
+ return StreamStreamMultiCallable(self._channel, _common.encode(method),
434
+ request_serializer,
435
+ response_deserializer,
436
+ self._stream_stream_interceptors,
437
+ self._loop)
438
+
439
+
440
+ def insecure_channel(
441
+ target: str,
442
+ options: Optional[ChannelArgumentType] = None,
443
+ compression: Optional[grpc.Compression] = None,
444
+ interceptors: Optional[Sequence[ClientInterceptor]] = None):
445
+ """Creates an insecure asynchronous Channel to a server.
446
+
447
+ Args:
448
+ target: The server address
449
+ options: An optional list of key-value pairs (:term:`channel_arguments`
450
+ in gRPC Core runtime) to configure the channel.
451
+ compression: An optional value indicating the compression method to be
452
+ used over the lifetime of the channel. This is an EXPERIMENTAL option.
453
+ interceptors: An optional sequence of interceptors that will be executed for
454
+ any call executed with this channel.
455
+
456
+ Returns:
457
+ A Channel.
458
+ """
459
+ return Channel(target, () if options is None else options, None,
460
+ compression, interceptors)
461
+
462
+
463
+ def secure_channel(target: str,
464
+ credentials: grpc.ChannelCredentials,
465
+ options: Optional[ChannelArgumentType] = None,
466
+ compression: Optional[grpc.Compression] = None,
467
+ interceptors: Optional[Sequence[ClientInterceptor]] = None):
468
+ """Creates a secure asynchronous Channel to a server.
469
+
470
+ Args:
471
+ target: The server address.
472
+ credentials: A ChannelCredentials instance.
473
+ options: An optional list of key-value pairs (:term:`channel_arguments`
474
+ in gRPC Core runtime) to configure the channel.
475
+ compression: An optional value indicating the compression method to be
476
+ used over the lifetime of the channel. This is an EXPERIMENTAL option.
477
+ interceptors: An optional sequence of interceptors that will be executed for
478
+ any call executed with this channel.
479
+
480
+ Returns:
481
+ An aio.Channel.
482
+ """
483
+ return Channel(target, () if options is None else options,
484
+ credentials._credentials, compression, interceptors)