grpcio-fips 1.53.2__0-cp310-cp310-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 (62) hide show
  1. grpc/__init__.py +2174 -0
  2. grpc/_auth.py +68 -0
  3. grpc/_channel.py +1767 -0
  4. grpc/_common.py +177 -0
  5. grpc/_compression.py +63 -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.cp310-win_amd64.pyd +0 -0
  10. grpc/_grpcio_metadata.py +1 -0
  11. grpc/_interceptor.py +638 -0
  12. grpc/_plugin_wrapping.py +121 -0
  13. grpc/_runtime_protos.py +159 -0
  14. grpc/_server.py +1141 -0
  15. grpc/_simple_stubs.py +486 -0
  16. grpc/_typing.py +58 -0
  17. grpc/_utilities.py +180 -0
  18. grpc/aio/__init__.py +95 -0
  19. grpc/aio/_base_call.py +248 -0
  20. grpc/aio/_base_channel.py +348 -0
  21. grpc/aio/_base_server.py +369 -0
  22. grpc/aio/_call.py +649 -0
  23. grpc/aio/_channel.py +492 -0
  24. grpc/aio/_interceptor.py +1003 -0
  25. grpc/aio/_metadata.py +120 -0
  26. grpc/aio/_server.py +209 -0
  27. grpc/aio/_typing.py +35 -0
  28. grpc/aio/_utils.py +22 -0
  29. grpc/beta/__init__.py +13 -0
  30. grpc/beta/_client_adaptations.py +706 -0
  31. grpc/beta/_metadata.py +52 -0
  32. grpc/beta/_server_adaptations.py +385 -0
  33. grpc/beta/implementations.py +311 -0
  34. grpc/beta/interfaces.py +163 -0
  35. grpc/beta/utilities.py +149 -0
  36. grpc/experimental/__init__.py +128 -0
  37. grpc/experimental/aio/__init__.py +16 -0
  38. grpc/experimental/gevent.py +27 -0
  39. grpc/experimental/session_cache.py +45 -0
  40. grpc/framework/__init__.py +13 -0
  41. grpc/framework/common/__init__.py +13 -0
  42. grpc/framework/common/cardinality.py +26 -0
  43. grpc/framework/common/style.py +24 -0
  44. grpc/framework/foundation/__init__.py +13 -0
  45. grpc/framework/foundation/abandonment.py +22 -0
  46. grpc/framework/foundation/callable_util.py +94 -0
  47. grpc/framework/foundation/future.py +219 -0
  48. grpc/framework/foundation/logging_pool.py +71 -0
  49. grpc/framework/foundation/stream.py +43 -0
  50. grpc/framework/foundation/stream_util.py +148 -0
  51. grpc/framework/interfaces/__init__.py +13 -0
  52. grpc/framework/interfaces/base/__init__.py +13 -0
  53. grpc/framework/interfaces/base/base.py +325 -0
  54. grpc/framework/interfaces/base/utilities.py +71 -0
  55. grpc/framework/interfaces/face/__init__.py +13 -0
  56. grpc/framework/interfaces/face/face.py +1049 -0
  57. grpc/framework/interfaces/face/utilities.py +168 -0
  58. grpcio_fips-1.53.2.dist-info/LICENSE +610 -0
  59. grpcio_fips-1.53.2.dist-info/METADATA +137 -0
  60. grpcio_fips-1.53.2.dist-info/RECORD +62 -0
  61. grpcio_fips-1.53.2.dist-info/WHEEL +5 -0
  62. grpcio_fips-1.53.2.dist-info/top_level.txt +1 -0
@@ -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.
Binary file
@@ -0,0 +1 @@
1
+ __version__ = """1.53.2"""
grpc/_interceptor.py ADDED
@@ -0,0 +1,638 @@
1
+ # Copyright 2017 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
+ """Implementation of gRPC Python interceptors."""
15
+
16
+ import collections
17
+ import sys
18
+ import types
19
+ from typing import Any, Callable, Optional, Sequence, Tuple, Union
20
+
21
+ import grpc
22
+
23
+ from ._typing import DeserializingFunction
24
+ from ._typing import DoneCallbackType
25
+ from ._typing import MetadataType
26
+ from ._typing import RequestIterableType
27
+ from ._typing import SerializingFunction
28
+
29
+
30
+ class _ServicePipeline(object):
31
+ interceptors: Tuple[grpc.ServerInterceptor]
32
+
33
+ def __init__(self, interceptors: Sequence[grpc.ServerInterceptor]):
34
+ self.interceptors = tuple(interceptors)
35
+
36
+ def _continuation(self, thunk: Callable, index: int) -> Callable:
37
+ return lambda context: self._intercept_at(thunk, index, context)
38
+
39
+ def _intercept_at(
40
+ self, thunk: Callable, index: int,
41
+ context: grpc.HandlerCallDetails) -> grpc.RpcMethodHandler:
42
+ if index < len(self.interceptors):
43
+ interceptor = self.interceptors[index]
44
+ thunk = self._continuation(thunk, index + 1)
45
+ return interceptor.intercept_service(thunk, context)
46
+ else:
47
+ return thunk(context)
48
+
49
+ def execute(self, thunk: Callable,
50
+ context: grpc.HandlerCallDetails) -> grpc.RpcMethodHandler:
51
+ return self._intercept_at(thunk, 0, context)
52
+
53
+
54
+ def service_pipeline(
55
+ interceptors: Optional[Sequence[grpc.ServerInterceptor]]
56
+ ) -> Optional[_ServicePipeline]:
57
+ return _ServicePipeline(interceptors) if interceptors else None
58
+
59
+
60
+ class _ClientCallDetails(
61
+ collections.namedtuple('_ClientCallDetails',
62
+ ('method', 'timeout', 'metadata', 'credentials',
63
+ 'wait_for_ready', 'compression')),
64
+ grpc.ClientCallDetails):
65
+ pass
66
+
67
+
68
+ def _unwrap_client_call_details(
69
+ call_details: grpc.ClientCallDetails,
70
+ default_details: grpc.ClientCallDetails
71
+ ) -> Tuple[str, float, MetadataType, grpc.CallCredentials, bool,
72
+ grpc.Compression]:
73
+ try:
74
+ method = call_details.method # pytype: disable=attribute-error
75
+ except AttributeError:
76
+ method = default_details.method # pytype: disable=attribute-error
77
+
78
+ try:
79
+ timeout = call_details.timeout # pytype: disable=attribute-error
80
+ except AttributeError:
81
+ timeout = default_details.timeout # pytype: disable=attribute-error
82
+
83
+ try:
84
+ metadata = call_details.metadata # pytype: disable=attribute-error
85
+ except AttributeError:
86
+ metadata = default_details.metadata # pytype: disable=attribute-error
87
+
88
+ try:
89
+ credentials = call_details.credentials # pytype: disable=attribute-error
90
+ except AttributeError:
91
+ credentials = default_details.credentials # pytype: disable=attribute-error
92
+
93
+ try:
94
+ wait_for_ready = call_details.wait_for_ready # pytype: disable=attribute-error
95
+ except AttributeError:
96
+ wait_for_ready = default_details.wait_for_ready # pytype: disable=attribute-error
97
+
98
+ try:
99
+ compression = call_details.compression # pytype: disable=attribute-error
100
+ except AttributeError:
101
+ compression = default_details.compression # pytype: disable=attribute-error
102
+
103
+ return method, timeout, metadata, credentials, wait_for_ready, compression
104
+
105
+
106
+ class _FailureOutcome(grpc.RpcError, grpc.Future, grpc.Call): # pylint: disable=too-many-ancestors
107
+ _exception: Exception
108
+ _traceback: types.TracebackType
109
+
110
+ def __init__(self, exception: Exception, traceback: types.TracebackType):
111
+ super(_FailureOutcome, self).__init__()
112
+ self._exception = exception
113
+ self._traceback = traceback
114
+
115
+ def initial_metadata(self) -> Optional[MetadataType]:
116
+ return None
117
+
118
+ def trailing_metadata(self) -> Optional[MetadataType]:
119
+ return None
120
+
121
+ def code(self) -> Optional[grpc.StatusCode]:
122
+ return grpc.StatusCode.INTERNAL
123
+
124
+ def details(self) -> Optional[str]:
125
+ return 'Exception raised while intercepting the RPC'
126
+
127
+ def cancel(self) -> bool:
128
+ return False
129
+
130
+ def cancelled(self) -> bool:
131
+ return False
132
+
133
+ def is_active(self) -> bool:
134
+ return False
135
+
136
+ def time_remaining(self) -> Optional[float]:
137
+ return None
138
+
139
+ def running(self) -> bool:
140
+ return False
141
+
142
+ def done(self) -> bool:
143
+ return True
144
+
145
+ def result(self, ignored_timeout: Optional[float] = None):
146
+ raise self._exception
147
+
148
+ def exception(
149
+ self,
150
+ ignored_timeout: Optional[float] = None) -> Optional[Exception]:
151
+ return self._exception
152
+
153
+ def traceback(
154
+ self,
155
+ ignored_timeout: Optional[float] = None
156
+ ) -> Optional[types.TracebackType]:
157
+ return self._traceback
158
+
159
+ def add_callback(self, unused_callback) -> bool:
160
+ return False
161
+
162
+ def add_done_callback(self, fn: DoneCallbackType) -> None:
163
+ fn(self)
164
+
165
+ def __iter__(self):
166
+ return self
167
+
168
+ def __next__(self):
169
+ raise self._exception
170
+
171
+ def next(self):
172
+ return self.__next__()
173
+
174
+
175
+ class _UnaryOutcome(grpc.Call, grpc.Future):
176
+ _response: Any
177
+ _call: grpc.Call
178
+
179
+ def __init__(self, response: Any, call: grpc.Call):
180
+ self._response = response
181
+ self._call = call
182
+
183
+ def initial_metadata(self) -> Optional[MetadataType]:
184
+ return self._call.initial_metadata()
185
+
186
+ def trailing_metadata(self) -> Optional[MetadataType]:
187
+ return self._call.trailing_metadata()
188
+
189
+ def code(self) -> Optional[grpc.StatusCode]:
190
+ return self._call.code()
191
+
192
+ def details(self) -> Optional[str]:
193
+ return self._call.details()
194
+
195
+ def is_active(self) -> bool:
196
+ return self._call.is_active()
197
+
198
+ def time_remaining(self) -> Optional[float]:
199
+ return self._call.time_remaining()
200
+
201
+ def cancel(self) -> bool:
202
+ return self._call.cancel()
203
+
204
+ def add_callback(self, callback) -> bool:
205
+ return self._call.add_callback(callback)
206
+
207
+ def cancelled(self) -> bool:
208
+ return False
209
+
210
+ def running(self) -> bool:
211
+ return False
212
+
213
+ def done(self) -> bool:
214
+ return True
215
+
216
+ def result(self, ignored_timeout: Optional[float] = None):
217
+ return self._response
218
+
219
+ def exception(self, ignored_timeout: Optional[float] = None):
220
+ return None
221
+
222
+ def traceback(self, ignored_timeout: Optional[float] = None):
223
+ return None
224
+
225
+ def add_done_callback(self, fn: DoneCallbackType) -> None:
226
+ fn(self)
227
+
228
+
229
+ class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable):
230
+ _thunk: Callable
231
+ _method: str
232
+ _interceptor: grpc.UnaryUnaryClientInterceptor
233
+
234
+ def __init__(self, thunk: Callable, method: str,
235
+ interceptor: grpc.UnaryUnaryClientInterceptor):
236
+ self._thunk = thunk
237
+ self._method = method
238
+ self._interceptor = interceptor
239
+
240
+ def __call__(self,
241
+ request: Any,
242
+ timeout: Optional[float] = None,
243
+ metadata: Optional[MetadataType] = None,
244
+ credentials: Optional[grpc.CallCredentials] = None,
245
+ wait_for_ready: Optional[bool] = None,
246
+ compression: Optional[grpc.Compression] = None) -> Any:
247
+ response, ignored_call = self._with_call(request,
248
+ timeout=timeout,
249
+ metadata=metadata,
250
+ credentials=credentials,
251
+ wait_for_ready=wait_for_ready,
252
+ compression=compression)
253
+ return response
254
+
255
+ def _with_call(
256
+ self,
257
+ request: Any,
258
+ timeout: Optional[float] = None,
259
+ metadata: Optional[MetadataType] = None,
260
+ credentials: Optional[grpc.CallCredentials] = None,
261
+ wait_for_ready: Optional[bool] = None,
262
+ compression: Optional[grpc.Compression] = None
263
+ ) -> Tuple[Any, grpc.Call]:
264
+ client_call_details = _ClientCallDetails(self._method, timeout,
265
+ metadata, credentials,
266
+ wait_for_ready, compression)
267
+
268
+ def continuation(new_details, request):
269
+ (new_method, new_timeout, new_metadata, new_credentials,
270
+ new_wait_for_ready,
271
+ new_compression) = (_unwrap_client_call_details(
272
+ new_details, client_call_details))
273
+ try:
274
+ response, call = self._thunk(new_method).with_call(
275
+ request,
276
+ timeout=new_timeout,
277
+ metadata=new_metadata,
278
+ credentials=new_credentials,
279
+ wait_for_ready=new_wait_for_ready,
280
+ compression=new_compression)
281
+ return _UnaryOutcome(response, call)
282
+ except grpc.RpcError as rpc_error:
283
+ return rpc_error
284
+ except Exception as exception: # pylint:disable=broad-except
285
+ return _FailureOutcome(exception, sys.exc_info()[2])
286
+
287
+ call = self._interceptor.intercept_unary_unary(continuation,
288
+ client_call_details,
289
+ request)
290
+ return call.result(), call
291
+
292
+ def with_call(
293
+ self,
294
+ request: Any,
295
+ timeout: Optional[float] = None,
296
+ metadata: Optional[MetadataType] = None,
297
+ credentials: Optional[grpc.CallCredentials] = None,
298
+ wait_for_ready: Optional[bool] = None,
299
+ compression: Optional[grpc.Compression] = None
300
+ ) -> Tuple[Any, grpc.Call]:
301
+ return self._with_call(request,
302
+ timeout=timeout,
303
+ metadata=metadata,
304
+ credentials=credentials,
305
+ wait_for_ready=wait_for_ready,
306
+ compression=compression)
307
+
308
+ def future(self,
309
+ request: Any,
310
+ timeout: Optional[float] = None,
311
+ metadata: Optional[MetadataType] = None,
312
+ credentials: Optional[grpc.CallCredentials] = None,
313
+ wait_for_ready: Optional[bool] = None,
314
+ compression: Optional[grpc.Compression] = None) -> Any:
315
+ client_call_details = _ClientCallDetails(self._method, timeout,
316
+ metadata, credentials,
317
+ wait_for_ready, compression)
318
+
319
+ def continuation(new_details, request):
320
+ (new_method, new_timeout, new_metadata, new_credentials,
321
+ new_wait_for_ready,
322
+ new_compression) = (_unwrap_client_call_details(
323
+ new_details, client_call_details))
324
+ return self._thunk(new_method).future(
325
+ request,
326
+ timeout=new_timeout,
327
+ metadata=new_metadata,
328
+ credentials=new_credentials,
329
+ wait_for_ready=new_wait_for_ready,
330
+ compression=new_compression)
331
+
332
+ try:
333
+ return self._interceptor.intercept_unary_unary(
334
+ continuation, client_call_details, request)
335
+ except Exception as exception: # pylint:disable=broad-except
336
+ return _FailureOutcome(exception, sys.exc_info()[2])
337
+
338
+
339
+ class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable):
340
+ _thunk: Callable
341
+ _method: str
342
+ _interceptor: grpc.UnaryStreamClientInterceptor
343
+
344
+ def __init__(self, thunk: Callable, method: str,
345
+ interceptor: grpc.UnaryStreamClientInterceptor):
346
+ self._thunk = thunk
347
+ self._method = method
348
+ self._interceptor = interceptor
349
+
350
+ def __call__(self,
351
+ request: Any,
352
+ timeout: Optional[float] = None,
353
+ metadata: Optional[MetadataType] = None,
354
+ credentials: Optional[grpc.CallCredentials] = None,
355
+ wait_for_ready: Optional[bool] = None,
356
+ compression: Optional[grpc.Compression] = None):
357
+ client_call_details = _ClientCallDetails(self._method, timeout,
358
+ metadata, credentials,
359
+ wait_for_ready, compression)
360
+
361
+ def continuation(new_details, request):
362
+ (new_method, new_timeout, new_metadata, new_credentials,
363
+ new_wait_for_ready,
364
+ new_compression) = (_unwrap_client_call_details(
365
+ new_details, client_call_details))
366
+ return self._thunk(new_method)(request,
367
+ timeout=new_timeout,
368
+ metadata=new_metadata,
369
+ credentials=new_credentials,
370
+ wait_for_ready=new_wait_for_ready,
371
+ compression=new_compression)
372
+
373
+ try:
374
+ return self._interceptor.intercept_unary_stream(
375
+ continuation, client_call_details, request)
376
+ except Exception as exception: # pylint:disable=broad-except
377
+ return _FailureOutcome(exception, sys.exc_info()[2])
378
+
379
+
380
+ class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable):
381
+ _thunk: Callable
382
+ _method: str
383
+ _interceptor: grpc.StreamUnaryClientInterceptor
384
+
385
+ def __init__(self, thunk: Callable, method: str,
386
+ interceptor: grpc.StreamUnaryClientInterceptor):
387
+ self._thunk = thunk
388
+ self._method = method
389
+ self._interceptor = interceptor
390
+
391
+ def __call__(self,
392
+ request_iterator: RequestIterableType,
393
+ timeout: Optional[float] = None,
394
+ metadata: Optional[MetadataType] = None,
395
+ credentials: Optional[grpc.CallCredentials] = None,
396
+ wait_for_ready: Optional[bool] = None,
397
+ compression: Optional[grpc.Compression] = None) -> Any:
398
+ response, ignored_call = self._with_call(request_iterator,
399
+ timeout=timeout,
400
+ metadata=metadata,
401
+ credentials=credentials,
402
+ wait_for_ready=wait_for_ready,
403
+ compression=compression)
404
+ return response
405
+
406
+ def _with_call(
407
+ self,
408
+ request_iterator: RequestIterableType,
409
+ timeout: Optional[float] = None,
410
+ metadata: Optional[MetadataType] = None,
411
+ credentials: Optional[grpc.CallCredentials] = None,
412
+ wait_for_ready: Optional[bool] = None,
413
+ compression: Optional[grpc.Compression] = None
414
+ ) -> Tuple[Any, grpc.Call]:
415
+ client_call_details = _ClientCallDetails(self._method, timeout,
416
+ metadata, credentials,
417
+ wait_for_ready, compression)
418
+
419
+ def continuation(new_details, request_iterator):
420
+ (new_method, new_timeout, new_metadata, new_credentials,
421
+ new_wait_for_ready,
422
+ new_compression) = (_unwrap_client_call_details(
423
+ new_details, client_call_details))
424
+ try:
425
+ response, call = self._thunk(new_method).with_call(
426
+ request_iterator,
427
+ timeout=new_timeout,
428
+ metadata=new_metadata,
429
+ credentials=new_credentials,
430
+ wait_for_ready=new_wait_for_ready,
431
+ compression=new_compression)
432
+ return _UnaryOutcome(response, call)
433
+ except grpc.RpcError as rpc_error:
434
+ return rpc_error
435
+ except Exception as exception: # pylint:disable=broad-except
436
+ return _FailureOutcome(exception, sys.exc_info()[2])
437
+
438
+ call = self._interceptor.intercept_stream_unary(continuation,
439
+ client_call_details,
440
+ request_iterator)
441
+ return call.result(), call
442
+
443
+ def with_call(
444
+ self,
445
+ request_iterator: RequestIterableType,
446
+ timeout: Optional[float] = None,
447
+ metadata: Optional[MetadataType] = None,
448
+ credentials: Optional[grpc.CallCredentials] = None,
449
+ wait_for_ready: Optional[bool] = None,
450
+ compression: Optional[grpc.Compression] = None
451
+ ) -> Tuple[Any, grpc.Call]:
452
+ return self._with_call(request_iterator,
453
+ timeout=timeout,
454
+ metadata=metadata,
455
+ credentials=credentials,
456
+ wait_for_ready=wait_for_ready,
457
+ compression=compression)
458
+
459
+ def future(self,
460
+ request_iterator: RequestIterableType,
461
+ timeout: Optional[float] = None,
462
+ metadata: Optional[MetadataType] = None,
463
+ credentials: Optional[grpc.CallCredentials] = None,
464
+ wait_for_ready: Optional[bool] = None,
465
+ compression: Optional[grpc.Compression] = None) -> Any:
466
+ client_call_details = _ClientCallDetails(self._method, timeout,
467
+ metadata, credentials,
468
+ wait_for_ready, compression)
469
+
470
+ def continuation(new_details, request_iterator):
471
+ (new_method, new_timeout, new_metadata, new_credentials,
472
+ new_wait_for_ready,
473
+ new_compression) = (_unwrap_client_call_details(
474
+ new_details, client_call_details))
475
+ return self._thunk(new_method).future(
476
+ request_iterator,
477
+ timeout=new_timeout,
478
+ metadata=new_metadata,
479
+ credentials=new_credentials,
480
+ wait_for_ready=new_wait_for_ready,
481
+ compression=new_compression)
482
+
483
+ try:
484
+ return self._interceptor.intercept_stream_unary(
485
+ continuation, client_call_details, request_iterator)
486
+ except Exception as exception: # pylint:disable=broad-except
487
+ return _FailureOutcome(exception, sys.exc_info()[2])
488
+
489
+
490
+ class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable):
491
+ _thunk: Callable
492
+ _method: str
493
+ _interceptor: grpc.StreamStreamClientInterceptor
494
+
495
+ def __init__(self, thunk: Callable, method: str,
496
+ interceptor: grpc.StreamStreamClientInterceptor):
497
+ self._thunk = thunk
498
+ self._method = method
499
+ self._interceptor = interceptor
500
+
501
+ def __call__(self,
502
+ request_iterator: RequestIterableType,
503
+ timeout: Optional[float] = None,
504
+ metadata: Optional[MetadataType] = None,
505
+ credentials: Optional[grpc.CallCredentials] = None,
506
+ wait_for_ready: Optional[bool] = None,
507
+ compression: Optional[grpc.Compression] = None):
508
+ client_call_details = _ClientCallDetails(self._method, timeout,
509
+ metadata, credentials,
510
+ wait_for_ready, compression)
511
+
512
+ def continuation(new_details, request_iterator):
513
+ (new_method, new_timeout, new_metadata, new_credentials,
514
+ new_wait_for_ready,
515
+ new_compression) = (_unwrap_client_call_details(
516
+ new_details, client_call_details))
517
+ return self._thunk(new_method)(request_iterator,
518
+ timeout=new_timeout,
519
+ metadata=new_metadata,
520
+ credentials=new_credentials,
521
+ wait_for_ready=new_wait_for_ready,
522
+ compression=new_compression)
523
+
524
+ try:
525
+ return self._interceptor.intercept_stream_stream(
526
+ continuation, client_call_details, request_iterator)
527
+ except Exception as exception: # pylint:disable=broad-except
528
+ return _FailureOutcome(exception, sys.exc_info()[2])
529
+
530
+
531
+ class _Channel(grpc.Channel):
532
+ _channel: grpc.Channel
533
+ _interceptor: Union[grpc.UnaryUnaryClientInterceptor,
534
+ grpc.UnaryStreamClientInterceptor,
535
+ grpc.StreamStreamClientInterceptor,
536
+ grpc.StreamUnaryClientInterceptor]
537
+
538
+ def __init__(self, channel: grpc.Channel,
539
+ interceptor: Union[grpc.UnaryUnaryClientInterceptor,
540
+ grpc.UnaryStreamClientInterceptor,
541
+ grpc.StreamStreamClientInterceptor,
542
+ grpc.StreamUnaryClientInterceptor]):
543
+ self._channel = channel
544
+ self._interceptor = interceptor
545
+
546
+ def subscribe(self,
547
+ callback: Callable,
548
+ try_to_connect: Optional[bool] = False):
549
+ self._channel.subscribe(callback, try_to_connect=try_to_connect)
550
+
551
+ def unsubscribe(self, callback: Callable):
552
+ self._channel.unsubscribe(callback)
553
+
554
+ def unary_unary(
555
+ self,
556
+ method: str,
557
+ request_serializer: Optional[SerializingFunction] = None,
558
+ response_deserializer: Optional[DeserializingFunction] = None
559
+ ) -> grpc.UnaryUnaryMultiCallable:
560
+ thunk = lambda m: self._channel.unary_unary(m, request_serializer,
561
+ response_deserializer)
562
+ if isinstance(self._interceptor, grpc.UnaryUnaryClientInterceptor):
563
+ return _UnaryUnaryMultiCallable(thunk, method, self._interceptor)
564
+ else:
565
+ return thunk(method)
566
+
567
+ def unary_stream(
568
+ self,
569
+ method: str,
570
+ request_serializer: Optional[SerializingFunction] = None,
571
+ response_deserializer: Optional[DeserializingFunction] = None
572
+ ) -> grpc.UnaryStreamMultiCallable:
573
+ thunk = lambda m: self._channel.unary_stream(m, request_serializer,
574
+ response_deserializer)
575
+ if isinstance(self._interceptor, grpc.UnaryStreamClientInterceptor):
576
+ return _UnaryStreamMultiCallable(thunk, method, self._interceptor)
577
+ else:
578
+ return thunk(method)
579
+
580
+ def stream_unary(
581
+ self,
582
+ method: str,
583
+ request_serializer: Optional[SerializingFunction] = None,
584
+ response_deserializer: Optional[DeserializingFunction] = None
585
+ ) -> grpc.StreamUnaryMultiCallable:
586
+ thunk = lambda m: self._channel.stream_unary(m, request_serializer,
587
+ response_deserializer)
588
+ if isinstance(self._interceptor, grpc.StreamUnaryClientInterceptor):
589
+ return _StreamUnaryMultiCallable(thunk, method, self._interceptor)
590
+ else:
591
+ return thunk(method)
592
+
593
+ def stream_stream(
594
+ self,
595
+ method: str,
596
+ request_serializer: Optional[SerializingFunction] = None,
597
+ response_deserializer: Optional[DeserializingFunction] = None
598
+ ) -> grpc.StreamStreamMultiCallable:
599
+ thunk = lambda m: self._channel.stream_stream(m, request_serializer,
600
+ response_deserializer)
601
+ if isinstance(self._interceptor, grpc.StreamStreamClientInterceptor):
602
+ return _StreamStreamMultiCallable(thunk, method, self._interceptor)
603
+ else:
604
+ return thunk(method)
605
+
606
+ def _close(self):
607
+ self._channel.close()
608
+
609
+ def __enter__(self):
610
+ return self
611
+
612
+ def __exit__(self, exc_type, exc_val, exc_tb):
613
+ self._close()
614
+ return False
615
+
616
+ def close(self):
617
+ self._channel.close()
618
+
619
+
620
+ def intercept_channel(
621
+ channel: grpc.Channel,
622
+ *interceptors: Optional[Sequence[Union[grpc.UnaryUnaryClientInterceptor,
623
+ grpc.UnaryStreamClientInterceptor,
624
+ grpc.StreamStreamClientInterceptor,
625
+ grpc.StreamUnaryClientInterceptor]]]
626
+ ) -> grpc.Channel:
627
+ for interceptor in reversed(list(interceptors)):
628
+ if not isinstance(interceptor, grpc.UnaryUnaryClientInterceptor) and \
629
+ not isinstance(interceptor, grpc.UnaryStreamClientInterceptor) and \
630
+ not isinstance(interceptor, grpc.StreamUnaryClientInterceptor) and \
631
+ not isinstance(interceptor, grpc.StreamStreamClientInterceptor):
632
+ raise TypeError('interceptor must be '
633
+ 'grpc.UnaryUnaryClientInterceptor or '
634
+ 'grpc.UnaryStreamClientInterceptor or '
635
+ 'grpc.StreamUnaryClientInterceptor or '
636
+ 'grpc.StreamStreamClientInterceptor or ')
637
+ channel = _Channel(channel, interceptor)
638
+ return channel