grpcio-fips 1.53.2__0-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 (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.cp38-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 +139 -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
grpc/aio/_metadata.py ADDED
@@ -0,0 +1,120 @@
1
+ # Copyright 2020 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 the metadata abstraction for gRPC Asyncio Python."""
15
+ from collections import OrderedDict
16
+ from collections import abc
17
+ from typing import Any, Iterator, List, Tuple, Union
18
+
19
+ MetadataKey = str
20
+ MetadataValue = Union[str, bytes]
21
+
22
+
23
+ class Metadata(abc.Mapping):
24
+ """Metadata abstraction for the asynchronous calls and interceptors.
25
+
26
+ The metadata is a mapping from str -> List[str]
27
+
28
+ Traits
29
+ * Multiple entries are allowed for the same key
30
+ * The order of the values by key is preserved
31
+ * Getting by an element by key, retrieves the first mapped value
32
+ * Supports an immutable view of the data
33
+ * Allows partial mutation on the data without recreating the new object from scratch.
34
+ """
35
+
36
+ def __init__(self, *args: Tuple[MetadataKey, MetadataValue]) -> None:
37
+ self._metadata = OrderedDict()
38
+ for md_key, md_value in args:
39
+ self.add(md_key, md_value)
40
+
41
+ @classmethod
42
+ def from_tuple(cls, raw_metadata: tuple):
43
+ if raw_metadata:
44
+ return cls(*raw_metadata)
45
+ return cls()
46
+
47
+ def add(self, key: MetadataKey, value: MetadataValue) -> None:
48
+ self._metadata.setdefault(key, [])
49
+ self._metadata[key].append(value)
50
+
51
+ def __len__(self) -> int:
52
+ """Return the total number of elements that there are in the metadata,
53
+ including multiple values for the same key.
54
+ """
55
+ return sum(map(len, self._metadata.values()))
56
+
57
+ def __getitem__(self, key: MetadataKey) -> MetadataValue:
58
+ """When calling <metadata>[<key>], the first element of all those
59
+ mapped for <key> is returned.
60
+ """
61
+ try:
62
+ return self._metadata[key][0]
63
+ except (ValueError, IndexError) as e:
64
+ raise KeyError("{0!r}".format(key)) from e
65
+
66
+ def __setitem__(self, key: MetadataKey, value: MetadataValue) -> None:
67
+ """Calling metadata[<key>] = <value>
68
+ Maps <value> to the first instance of <key>.
69
+ """
70
+ if key not in self:
71
+ self._metadata[key] = [value]
72
+ else:
73
+ current_values = self.get_all(key)
74
+ self._metadata[key] = [value, *current_values[1:]]
75
+
76
+ def __delitem__(self, key: MetadataKey) -> None:
77
+ """``del metadata[<key>]`` deletes the first mapping for <key>."""
78
+ current_values = self.get_all(key)
79
+ if not current_values:
80
+ raise KeyError(repr(key))
81
+ self._metadata[key] = current_values[1:]
82
+
83
+ def delete_all(self, key: MetadataKey) -> None:
84
+ """Delete all mappings for <key>."""
85
+ del self._metadata[key]
86
+
87
+ def __iter__(self) -> Iterator[Tuple[MetadataKey, MetadataValue]]:
88
+ for key, values in self._metadata.items():
89
+ for value in values:
90
+ yield (key, value)
91
+
92
+ def get_all(self, key: MetadataKey) -> List[MetadataValue]:
93
+ """For compatibility with other Metadata abstraction objects (like in Java),
94
+ this would return all items under the desired <key>.
95
+ """
96
+ return self._metadata.get(key, [])
97
+
98
+ def set_all(self, key: MetadataKey, values: List[MetadataValue]) -> None:
99
+ self._metadata[key] = values
100
+
101
+ def __contains__(self, key: MetadataKey) -> bool:
102
+ return key in self._metadata
103
+
104
+ def __eq__(self, other: Any) -> bool:
105
+ if isinstance(other, self.__class__):
106
+ return self._metadata == other._metadata
107
+ if isinstance(other, tuple):
108
+ return tuple(self) == other
109
+ return NotImplemented # pytype: disable=bad-return-type
110
+
111
+ def __add__(self, other: Any) -> 'Metadata':
112
+ if isinstance(other, self.__class__):
113
+ return Metadata(*(tuple(self) + tuple(other)))
114
+ if isinstance(other, tuple):
115
+ return Metadata(*(tuple(self) + other))
116
+ return NotImplemented # pytype: disable=bad-return-type
117
+
118
+ def __repr__(self) -> str:
119
+ view = tuple(self)
120
+ return "{0}({1!r})".format(self.__class__.__name__, view)
grpc/aio/_server.py ADDED
@@ -0,0 +1,209 @@
1
+ # Copyright 2019 The 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
+ """Server-side implementation of gRPC Asyncio Python."""
15
+
16
+ from concurrent.futures import Executor
17
+ from typing import Any, Optional, Sequence
18
+
19
+ import grpc
20
+ from grpc import _common
21
+ from grpc import _compression
22
+ from grpc._cython import cygrpc
23
+
24
+ from . import _base_server
25
+ from ._interceptor import ServerInterceptor
26
+ from ._typing import ChannelArgumentType
27
+
28
+
29
+ def _augment_channel_arguments(base_options: ChannelArgumentType,
30
+ compression: Optional[grpc.Compression]):
31
+ compression_option = _compression.create_channel_option(compression)
32
+ return tuple(base_options) + compression_option
33
+
34
+
35
+ class Server(_base_server.Server):
36
+ """Serves RPCs."""
37
+
38
+ def __init__(self, thread_pool: Optional[Executor],
39
+ generic_handlers: Optional[Sequence[grpc.GenericRpcHandler]],
40
+ interceptors: Optional[Sequence[Any]],
41
+ options: ChannelArgumentType,
42
+ maximum_concurrent_rpcs: Optional[int],
43
+ compression: Optional[grpc.Compression]):
44
+ self._loop = cygrpc.get_working_loop()
45
+ if interceptors:
46
+ invalid_interceptors = [
47
+ interceptor for interceptor in interceptors
48
+ if not isinstance(interceptor, ServerInterceptor)
49
+ ]
50
+ if invalid_interceptors:
51
+ raise ValueError(
52
+ 'Interceptor must be ServerInterceptor, the '
53
+ f'following are invalid: {invalid_interceptors}')
54
+ self._server = cygrpc.AioServer(
55
+ self._loop, thread_pool, generic_handlers, interceptors,
56
+ _augment_channel_arguments(options, compression),
57
+ maximum_concurrent_rpcs)
58
+
59
+ def add_generic_rpc_handlers(
60
+ self,
61
+ generic_rpc_handlers: Sequence[grpc.GenericRpcHandler]) -> None:
62
+ """Registers GenericRpcHandlers with this Server.
63
+
64
+ This method is only safe to call before the server is started.
65
+
66
+ Args:
67
+ generic_rpc_handlers: A sequence of GenericRpcHandlers that will be
68
+ used to service RPCs.
69
+ """
70
+ self._server.add_generic_rpc_handlers(generic_rpc_handlers)
71
+
72
+ def add_insecure_port(self, address: str) -> int:
73
+ """Opens an insecure port for accepting RPCs.
74
+
75
+ This method may only be called before starting the server.
76
+
77
+ Args:
78
+ address: The address for which to open a port. If the port is 0,
79
+ or not specified in the address, then the gRPC runtime will choose a port.
80
+
81
+ Returns:
82
+ An integer port on which the server will accept RPC requests.
83
+ """
84
+ return _common.validate_port_binding_result(
85
+ address, self._server.add_insecure_port(_common.encode(address)))
86
+
87
+ def add_secure_port(self, address: str,
88
+ server_credentials: grpc.ServerCredentials) -> int:
89
+ """Opens a secure port for accepting RPCs.
90
+
91
+ This method may only be called before starting the server.
92
+
93
+ Args:
94
+ address: The address for which to open a port.
95
+ if the port is 0, or not specified in the address, then the gRPC
96
+ runtime will choose a port.
97
+ server_credentials: A ServerCredentials object.
98
+
99
+ Returns:
100
+ An integer port on which the server will accept RPC requests.
101
+ """
102
+ return _common.validate_port_binding_result(
103
+ address,
104
+ self._server.add_secure_port(_common.encode(address),
105
+ server_credentials))
106
+
107
+ async def start(self) -> None:
108
+ """Starts this Server.
109
+
110
+ This method may only be called once. (i.e. it is not idempotent).
111
+ """
112
+ await self._server.start()
113
+
114
+ async def stop(self, grace: Optional[float]) -> None:
115
+ """Stops this Server.
116
+
117
+ This method immediately stops the server from servicing new RPCs in
118
+ all cases.
119
+
120
+ If a grace period is specified, this method returns immediately and all
121
+ RPCs active at the end of the grace period are aborted. If a grace
122
+ period is not specified (by passing None for grace), all existing RPCs
123
+ are aborted immediately and this method blocks until the last RPC
124
+ handler terminates.
125
+
126
+ This method is idempotent and may be called at any time. Passing a
127
+ smaller grace value in a subsequent call will have the effect of
128
+ stopping the Server sooner (passing None will have the effect of
129
+ stopping the server immediately). Passing a larger grace value in a
130
+ subsequent call will not have the effect of stopping the server later
131
+ (i.e. the most restrictive grace value is used).
132
+
133
+ Args:
134
+ grace: A duration of time in seconds or None.
135
+ """
136
+ await self._server.shutdown(grace)
137
+
138
+ async def wait_for_termination(self,
139
+ timeout: Optional[float] = None) -> bool:
140
+ """Block current coroutine until the server stops.
141
+
142
+ This is an EXPERIMENTAL API.
143
+
144
+ The wait will not consume computational resources during blocking, and
145
+ it will block until one of the two following conditions are met:
146
+
147
+ 1) The server is stopped or terminated;
148
+ 2) A timeout occurs if timeout is not `None`.
149
+
150
+ The timeout argument works in the same way as `threading.Event.wait()`.
151
+ https://docs.python.org/3/library/threading.html#threading.Event.wait
152
+
153
+ Args:
154
+ timeout: A floating point number specifying a timeout for the
155
+ operation in seconds.
156
+
157
+ Returns:
158
+ A bool indicates if the operation times out.
159
+ """
160
+ return await self._server.wait_for_termination(timeout)
161
+
162
+ def __del__(self):
163
+ """Schedules a graceful shutdown in current event loop.
164
+
165
+ The Cython AioServer doesn't hold a ref-count to this class. It should
166
+ be safe to slightly extend the underlying Cython object's life span.
167
+ """
168
+ if hasattr(self, '_server'):
169
+ if self._server.is_running():
170
+ cygrpc.schedule_coro_threadsafe(
171
+ self._server.shutdown(None),
172
+ self._loop,
173
+ )
174
+
175
+
176
+ def server(migration_thread_pool: Optional[Executor] = None,
177
+ handlers: Optional[Sequence[grpc.GenericRpcHandler]] = None,
178
+ interceptors: Optional[Sequence[Any]] = None,
179
+ options: Optional[ChannelArgumentType] = None,
180
+ maximum_concurrent_rpcs: Optional[int] = None,
181
+ compression: Optional[grpc.Compression] = None):
182
+ """Creates a Server with which RPCs can be serviced.
183
+
184
+ Args:
185
+ migration_thread_pool: A futures.ThreadPoolExecutor to be used by the
186
+ Server to execute non-AsyncIO RPC handlers for migration purpose.
187
+ handlers: An optional list of GenericRpcHandlers used for executing RPCs.
188
+ More handlers may be added by calling add_generic_rpc_handlers any time
189
+ before the server is started.
190
+ interceptors: An optional list of ServerInterceptor objects that observe
191
+ and optionally manipulate the incoming RPCs before handing them over to
192
+ handlers. The interceptors are given control in the order they are
193
+ specified. This is an EXPERIMENTAL API.
194
+ options: An optional list of key-value pairs (:term:`channel_arguments` in gRPC runtime)
195
+ to configure the channel.
196
+ maximum_concurrent_rpcs: The maximum number of concurrent RPCs this server
197
+ will service before returning RESOURCE_EXHAUSTED status, or None to
198
+ indicate no limit.
199
+ compression: An element of grpc.compression, e.g.
200
+ grpc.compression.Gzip. This compression algorithm will be used for the
201
+ lifetime of the server unless overridden by set_compression.
202
+
203
+ Returns:
204
+ A Server object.
205
+ """
206
+ return Server(migration_thread_pool, () if handlers is None else handlers,
207
+ () if interceptors is None else interceptors,
208
+ () if options is None else options, maximum_concurrent_rpcs,
209
+ compression)
grpc/aio/_typing.py ADDED
@@ -0,0 +1,35 @@
1
+ # Copyright 2019 The 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
+ """Common types for gRPC Async API"""
15
+
16
+ from typing import (Any, AsyncIterable, Callable, Iterable, Sequence, Tuple,
17
+ TypeVar, Union)
18
+
19
+ from grpc._cython.cygrpc import EOF
20
+
21
+ from ._metadata import Metadata
22
+ from ._metadata import MetadataKey
23
+ from ._metadata import MetadataValue
24
+
25
+ RequestType = TypeVar('RequestType')
26
+ ResponseType = TypeVar('ResponseType')
27
+ SerializingFunction = Callable[[Any], bytes]
28
+ DeserializingFunction = Callable[[bytes], Any]
29
+ MetadatumType = Tuple[MetadataKey, MetadataValue]
30
+ MetadataType = Union[Metadata, Sequence[MetadatumType]]
31
+ ChannelArgumentType = Sequence[Tuple[str, Any]]
32
+ EOFType = type(EOF)
33
+ DoneCallbackType = Callable[[Any], None]
34
+ RequestIterableType = Union[Iterable[Any], AsyncIterable[Any]]
35
+ ResponseIterableType = AsyncIterable[Any]
grpc/aio/_utils.py ADDED
@@ -0,0 +1,22 @@
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
+ """Internal utilities used by the gRPC Aio module."""
15
+ import time
16
+ from typing import Optional
17
+
18
+
19
+ def _timeout_to_deadline(timeout: Optional[float]) -> Optional[float]:
20
+ if timeout is None:
21
+ return None
22
+ return time.time() + timeout
grpc/beta/__init__.py ADDED
@@ -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.