grpcio-fips 1.70.0__4-cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- grpc/__init__.py +2348 -0
- grpc/_auth.py +80 -0
- grpc/_channel.py +2267 -0
- grpc/_common.py +183 -0
- grpc/_compression.py +71 -0
- grpc/_cython/__init__.py +13 -0
- grpc/_cython/_credentials/roots.pem +4337 -0
- grpc/_cython/_cygrpc/__init__.py +13 -0
- grpc/_cython/cygrpc.cp313-win_amd64.pyd +0 -0
- grpc/_grpcio_metadata.py +1 -0
- grpc/_interceptor.py +813 -0
- grpc/_observability.py +299 -0
- grpc/_plugin_wrapping.py +136 -0
- grpc/_runtime_protos.py +165 -0
- grpc/_server.py +1528 -0
- grpc/_simple_stubs.py +588 -0
- grpc/_typing.py +95 -0
- grpc/_utilities.py +222 -0
- grpc/aio/__init__.py +95 -0
- grpc/aio/_base_call.py +257 -0
- grpc/aio/_base_channel.py +364 -0
- grpc/aio/_base_server.py +385 -0
- grpc/aio/_call.py +764 -0
- grpc/aio/_channel.py +627 -0
- grpc/aio/_interceptor.py +1178 -0
- grpc/aio/_metadata.py +137 -0
- grpc/aio/_server.py +239 -0
- grpc/aio/_typing.py +43 -0
- grpc/aio/_utils.py +22 -0
- grpc/beta/__init__.py +13 -0
- grpc/beta/_client_adaptations.py +1015 -0
- grpc/beta/_metadata.py +56 -0
- grpc/beta/_server_adaptations.py +465 -0
- grpc/beta/implementations.py +345 -0
- grpc/beta/interfaces.py +163 -0
- grpc/beta/utilities.py +153 -0
- grpc/experimental/__init__.py +134 -0
- grpc/experimental/aio/__init__.py +16 -0
- grpc/experimental/gevent.py +27 -0
- grpc/experimental/session_cache.py +45 -0
- grpc/framework/__init__.py +13 -0
- grpc/framework/common/__init__.py +13 -0
- grpc/framework/common/cardinality.py +26 -0
- grpc/framework/common/style.py +24 -0
- grpc/framework/foundation/__init__.py +13 -0
- grpc/framework/foundation/abandonment.py +22 -0
- grpc/framework/foundation/callable_util.py +98 -0
- grpc/framework/foundation/future.py +219 -0
- grpc/framework/foundation/logging_pool.py +72 -0
- grpc/framework/foundation/stream.py +43 -0
- grpc/framework/foundation/stream_util.py +148 -0
- grpc/framework/interfaces/__init__.py +13 -0
- grpc/framework/interfaces/base/__init__.py +13 -0
- grpc/framework/interfaces/base/base.py +328 -0
- grpc/framework/interfaces/base/utilities.py +83 -0
- grpc/framework/interfaces/face/__init__.py +13 -0
- grpc/framework/interfaces/face/face.py +1084 -0
- grpc/framework/interfaces/face/utilities.py +245 -0
- grpcio_fips-1.70.0.dist-info/METADATA +55 -0
- grpcio_fips-1.70.0.dist-info/RECORD +63 -0
- grpcio_fips-1.70.0.dist-info/WHEEL +5 -0
- grpcio_fips-1.70.0.dist-info/licenses/LICENSE +610 -0
- grpcio_fips-1.70.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Copyright 2018 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
|
+
"""gRPC's experimental APIs.
|
|
15
|
+
|
|
16
|
+
These APIs are subject to be removed during any minor version release.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import copy
|
|
20
|
+
import functools
|
|
21
|
+
import sys
|
|
22
|
+
import warnings
|
|
23
|
+
|
|
24
|
+
import grpc
|
|
25
|
+
from grpc._cython import cygrpc as _cygrpc
|
|
26
|
+
|
|
27
|
+
_EXPERIMENTAL_APIS_USED = set()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ChannelOptions(object):
|
|
31
|
+
"""Indicates a channel option unique to gRPC Python.
|
|
32
|
+
|
|
33
|
+
This enumeration is part of an EXPERIMENTAL API.
|
|
34
|
+
|
|
35
|
+
Attributes:
|
|
36
|
+
SingleThreadedUnaryStream: Perform unary-stream RPCs on a single thread.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
SingleThreadedUnaryStream = "SingleThreadedUnaryStream"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class UsageError(Exception):
|
|
43
|
+
"""Raised by the gRPC library to indicate usage not allowed by the API."""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# It's important that there be a single insecure credentials object so that its
|
|
47
|
+
# hash is deterministic and can be used for indexing in the simple stubs cache.
|
|
48
|
+
_insecure_channel_credentials = grpc.ChannelCredentials(
|
|
49
|
+
_cygrpc.channel_credentials_insecure()
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def insecure_channel_credentials():
|
|
54
|
+
"""Creates a ChannelCredentials for use with an insecure channel.
|
|
55
|
+
|
|
56
|
+
THIS IS AN EXPERIMENTAL API.
|
|
57
|
+
"""
|
|
58
|
+
return _insecure_channel_credentials
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class ExperimentalApiWarning(Warning):
|
|
62
|
+
"""A warning that an API is experimental."""
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _warn_experimental(api_name, stack_offset):
|
|
66
|
+
if api_name not in _EXPERIMENTAL_APIS_USED:
|
|
67
|
+
_EXPERIMENTAL_APIS_USED.add(api_name)
|
|
68
|
+
msg = (
|
|
69
|
+
"'{}' is an experimental API. It is subject to change or ".format(
|
|
70
|
+
api_name
|
|
71
|
+
)
|
|
72
|
+
+ "removal between minor releases. Proceed with caution."
|
|
73
|
+
)
|
|
74
|
+
warnings.warn(msg, ExperimentalApiWarning, stacklevel=2 + stack_offset)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def experimental_api(f):
|
|
78
|
+
@functools.wraps(f)
|
|
79
|
+
def _wrapper(*args, **kwargs):
|
|
80
|
+
_warn_experimental(f.__name__, 1)
|
|
81
|
+
return f(*args, **kwargs)
|
|
82
|
+
|
|
83
|
+
return _wrapper
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def wrap_server_method_handler(wrapper, handler):
|
|
87
|
+
"""Wraps the server method handler function.
|
|
88
|
+
|
|
89
|
+
The server implementation requires all server handlers being wrapped as
|
|
90
|
+
RpcMethodHandler objects. This helper function ease the pain of writing
|
|
91
|
+
server handler wrappers.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
wrapper: A wrapper function that takes in a method handler behavior
|
|
95
|
+
(the actual function) and returns a wrapped function.
|
|
96
|
+
handler: A RpcMethodHandler object to be wrapped.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
A newly created RpcMethodHandler.
|
|
100
|
+
"""
|
|
101
|
+
if not handler:
|
|
102
|
+
return None
|
|
103
|
+
|
|
104
|
+
if not handler.request_streaming:
|
|
105
|
+
if not handler.response_streaming:
|
|
106
|
+
# NOTE(lidiz) _replace is a public API:
|
|
107
|
+
# https://docs.python.org/dev/library/collections.html
|
|
108
|
+
return handler._replace(unary_unary=wrapper(handler.unary_unary))
|
|
109
|
+
else:
|
|
110
|
+
return handler._replace(unary_stream=wrapper(handler.unary_stream))
|
|
111
|
+
else:
|
|
112
|
+
if not handler.response_streaming:
|
|
113
|
+
return handler._replace(stream_unary=wrapper(handler.stream_unary))
|
|
114
|
+
else:
|
|
115
|
+
return handler._replace(
|
|
116
|
+
stream_stream=wrapper(handler.stream_stream)
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
__all__ = (
|
|
121
|
+
"ChannelOptions",
|
|
122
|
+
"ExperimentalApiWarning",
|
|
123
|
+
"UsageError",
|
|
124
|
+
"insecure_channel_credentials",
|
|
125
|
+
"wrap_server_method_handler",
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
if sys.version_info > (3, 6):
|
|
129
|
+
from grpc._simple_stubs import stream_stream
|
|
130
|
+
from grpc._simple_stubs import stream_unary
|
|
131
|
+
from grpc._simple_stubs import unary_stream
|
|
132
|
+
from grpc._simple_stubs import unary_unary
|
|
133
|
+
|
|
134
|
+
__all__ = __all__ + (unary_unary, unary_stream, stream_unary, stream_stream)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright 2020 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
|
+
"""Alias of grpc.aio to keep backward compatibility."""
|
|
15
|
+
|
|
16
|
+
from grpc.aio import *
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Copyright 2018 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
|
+
"""gRPC's Python gEvent APIs."""
|
|
15
|
+
|
|
16
|
+
from grpc._cython import cygrpc as _cygrpc
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def init_gevent():
|
|
20
|
+
"""Patches gRPC's libraries to be compatible with gevent.
|
|
21
|
+
|
|
22
|
+
This must be called AFTER the python standard lib has been patched,
|
|
23
|
+
but BEFORE creating and gRPC objects.
|
|
24
|
+
|
|
25
|
+
In order for progress to be made, the application must drive the event loop.
|
|
26
|
+
"""
|
|
27
|
+
_cygrpc.init_grpc_gevent()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright 2018 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
|
+
"""gRPC's APIs for TLS Session Resumption support"""
|
|
15
|
+
|
|
16
|
+
from grpc._cython import cygrpc as _cygrpc
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def ssl_session_cache_lru(capacity):
|
|
20
|
+
"""Creates an SSLSessionCache with LRU replacement policy
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
capacity: Size of the cache
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
An SSLSessionCache with LRU replacement policy that can be passed as a value for
|
|
27
|
+
the grpc.ssl_session_cache option to a grpc.Channel. SSL session caches are used
|
|
28
|
+
to store session tickets, which clients can present to resume previous TLS sessions
|
|
29
|
+
with a server.
|
|
30
|
+
"""
|
|
31
|
+
return SSLSessionCache(_cygrpc.SSLSessionCacheLRU(capacity))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class SSLSessionCache(object):
|
|
35
|
+
"""An encapsulation of a session cache used for TLS session resumption.
|
|
36
|
+
|
|
37
|
+
Instances of this class can be passed to a Channel as values for the
|
|
38
|
+
grpc.ssl_session_cache option
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(self, cache):
|
|
42
|
+
self._cache = cache
|
|
43
|
+
|
|
44
|
+
def __int__(self):
|
|
45
|
+
return int(self._cache)
|
|
@@ -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,26 @@
|
|
|
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
|
+
"""Defines an enum for classifying RPC methods by streaming semantics."""
|
|
15
|
+
|
|
16
|
+
import enum
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@enum.unique
|
|
20
|
+
class Cardinality(enum.Enum):
|
|
21
|
+
"""Describes the streaming semantics of an RPC method."""
|
|
22
|
+
|
|
23
|
+
UNARY_UNARY = "request-unary/response-unary"
|
|
24
|
+
UNARY_STREAM = "request-unary/response-streaming"
|
|
25
|
+
STREAM_UNARY = "request-streaming/response-unary"
|
|
26
|
+
STREAM_STREAM = "request-streaming/response-streaming"
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
"""Defines an enum for classifying RPC methods by control flow semantics."""
|
|
15
|
+
|
|
16
|
+
import enum
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@enum.unique
|
|
20
|
+
class Service(enum.Enum):
|
|
21
|
+
"""Describes the control flow style of RPC method implementation."""
|
|
22
|
+
|
|
23
|
+
INLINE = "inline"
|
|
24
|
+
EVENT = "event"
|
|
@@ -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,22 @@
|
|
|
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 indicating abandonment of computation."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Abandoned(Exception):
|
|
18
|
+
"""Indicates that some computation is being abandoned.
|
|
19
|
+
|
|
20
|
+
Abandoning a computation is different than returning a value or raising
|
|
21
|
+
an exception indicating some operational or programming defect.
|
|
22
|
+
"""
|
|
@@ -0,0 +1,98 @@
|
|
|
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 working with callables."""
|
|
15
|
+
|
|
16
|
+
from abc import ABC
|
|
17
|
+
import collections
|
|
18
|
+
import enum
|
|
19
|
+
import functools
|
|
20
|
+
import logging
|
|
21
|
+
|
|
22
|
+
_LOGGER = logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Outcome(ABC):
|
|
26
|
+
"""A sum type describing the outcome of some call.
|
|
27
|
+
|
|
28
|
+
Attributes:
|
|
29
|
+
kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the
|
|
30
|
+
call returned a value or raised an exception.
|
|
31
|
+
return_value: The value returned by the call. Must be present if kind is
|
|
32
|
+
Kind.RETURNED.
|
|
33
|
+
exception: The exception raised by the call. Must be present if kind is
|
|
34
|
+
Kind.RAISED.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
@enum.unique
|
|
38
|
+
class Kind(enum.Enum):
|
|
39
|
+
"""Identifies the general kind of the outcome of some call."""
|
|
40
|
+
|
|
41
|
+
RETURNED = object()
|
|
42
|
+
RAISED = object()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class _EasyOutcome(
|
|
46
|
+
collections.namedtuple(
|
|
47
|
+
"_EasyOutcome", ["kind", "return_value", "exception"]
|
|
48
|
+
),
|
|
49
|
+
Outcome,
|
|
50
|
+
):
|
|
51
|
+
"""A trivial implementation of Outcome."""
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _call_logging_exceptions(behavior, message, *args, **kwargs):
|
|
55
|
+
try:
|
|
56
|
+
return _EasyOutcome(
|
|
57
|
+
Outcome.Kind.RETURNED, behavior(*args, **kwargs), None
|
|
58
|
+
)
|
|
59
|
+
except Exception as e: # pylint: disable=broad-except
|
|
60
|
+
_LOGGER.exception(message)
|
|
61
|
+
return _EasyOutcome(Outcome.Kind.RAISED, None, e)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def with_exceptions_logged(behavior, message):
|
|
65
|
+
"""Wraps a callable in a try-except that logs any exceptions it raises.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
behavior: Any callable.
|
|
69
|
+
message: A string to log if the behavior raises an exception.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
A callable that when executed invokes the given behavior. The returned
|
|
73
|
+
callable takes the same arguments as the given behavior but returns a
|
|
74
|
+
future.Outcome describing whether the given behavior returned a value or
|
|
75
|
+
raised an exception.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
@functools.wraps(behavior)
|
|
79
|
+
def wrapped_behavior(*args, **kwargs):
|
|
80
|
+
return _call_logging_exceptions(behavior, message, *args, **kwargs)
|
|
81
|
+
|
|
82
|
+
return wrapped_behavior
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def call_logging_exceptions(behavior, message, *args, **kwargs):
|
|
86
|
+
"""Calls a behavior in a try-except that logs any exceptions it raises.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
behavior: Any callable.
|
|
90
|
+
message: A string to log if the behavior raises an exception.
|
|
91
|
+
*args: Positional arguments to pass to the given behavior.
|
|
92
|
+
**kwargs: Keyword arguments to pass to the given behavior.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
An Outcome describing whether the given behavior returned a value or raised
|
|
96
|
+
an exception.
|
|
97
|
+
"""
|
|
98
|
+
return _call_logging_exceptions(behavior, message, *args, **kwargs)
|
|
@@ -0,0 +1,219 @@
|
|
|
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 Future interface.
|
|
15
|
+
|
|
16
|
+
Python doesn't have a Future interface in its standard library. In the absence
|
|
17
|
+
of such a standard, three separate, incompatible implementations
|
|
18
|
+
(concurrent.futures.Future, ndb.Future, and asyncio.Future) have appeared. This
|
|
19
|
+
interface attempts to be as compatible as possible with
|
|
20
|
+
concurrent.futures.Future. From ndb.Future it adopts a traceback-object accessor
|
|
21
|
+
method.
|
|
22
|
+
|
|
23
|
+
Unlike the concrete and implemented Future classes listed above, the Future
|
|
24
|
+
class defined in this module is an entirely abstract interface that anyone may
|
|
25
|
+
implement and use.
|
|
26
|
+
|
|
27
|
+
The one known incompatibility between this interface and the interface of
|
|
28
|
+
concurrent.futures.Future is that this interface defines its own CancelledError
|
|
29
|
+
and TimeoutError exceptions rather than raising the implementation-private
|
|
30
|
+
concurrent.futures._base.CancelledError and the
|
|
31
|
+
built-in-but-only-in-3.3-and-later TimeoutError.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
import abc
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class TimeoutError(Exception):
|
|
38
|
+
"""Indicates that a particular call timed out."""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class CancelledError(Exception):
|
|
42
|
+
"""Indicates that the computation underlying a Future was cancelled."""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Future(abc.ABC):
|
|
46
|
+
"""A representation of a computation in another control flow.
|
|
47
|
+
|
|
48
|
+
Computations represented by a Future may be yet to be begun, may be ongoing,
|
|
49
|
+
or may have already completed.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
# NOTE(nathaniel): This isn't the return type that I would want to have if it
|
|
53
|
+
# were up to me. Were this interface being written from scratch, the return
|
|
54
|
+
# type of this method would probably be a sum type like:
|
|
55
|
+
#
|
|
56
|
+
# NOT_COMMENCED
|
|
57
|
+
# COMMENCED_AND_NOT_COMPLETED
|
|
58
|
+
# PARTIAL_RESULT<Partial_Result_Type>
|
|
59
|
+
# COMPLETED<Result_Type>
|
|
60
|
+
# UNCANCELLABLE
|
|
61
|
+
# NOT_IMMEDIATELY_DETERMINABLE
|
|
62
|
+
@abc.abstractmethod
|
|
63
|
+
def cancel(self):
|
|
64
|
+
"""Attempts to cancel the computation.
|
|
65
|
+
|
|
66
|
+
This method does not block.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
True if the computation has not yet begun, will not be allowed to take
|
|
70
|
+
place, and determination of both was possible without blocking. False
|
|
71
|
+
under all other circumstances including but not limited to the
|
|
72
|
+
computation's already having begun, the computation's already having
|
|
73
|
+
finished, and the computation's having been scheduled for execution on a
|
|
74
|
+
remote system for which a determination of whether or not it commenced
|
|
75
|
+
before being cancelled cannot be made without blocking.
|
|
76
|
+
"""
|
|
77
|
+
raise NotImplementedError()
|
|
78
|
+
|
|
79
|
+
# NOTE(nathaniel): Here too this isn't the return type that I'd want this
|
|
80
|
+
# method to have if it were up to me. I think I'd go with another sum type
|
|
81
|
+
# like:
|
|
82
|
+
#
|
|
83
|
+
# NOT_CANCELLED (this object's cancel method hasn't been called)
|
|
84
|
+
# NOT_COMMENCED
|
|
85
|
+
# COMMENCED_AND_NOT_COMPLETED
|
|
86
|
+
# PARTIAL_RESULT<Partial_Result_Type>
|
|
87
|
+
# COMPLETED<Result_Type>
|
|
88
|
+
# UNCANCELLABLE
|
|
89
|
+
# NOT_IMMEDIATELY_DETERMINABLE
|
|
90
|
+
#
|
|
91
|
+
# Notice how giving the cancel method the right semantics obviates most
|
|
92
|
+
# reasons for this method to exist.
|
|
93
|
+
@abc.abstractmethod
|
|
94
|
+
def cancelled(self):
|
|
95
|
+
"""Describes whether the computation was cancelled.
|
|
96
|
+
|
|
97
|
+
This method does not block.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
True if the computation was cancelled any time before its result became
|
|
101
|
+
immediately available. False under all other circumstances including but
|
|
102
|
+
not limited to this object's cancel method not having been called and
|
|
103
|
+
the computation's result having become immediately available.
|
|
104
|
+
"""
|
|
105
|
+
raise NotImplementedError()
|
|
106
|
+
|
|
107
|
+
@abc.abstractmethod
|
|
108
|
+
def running(self):
|
|
109
|
+
"""Describes whether the computation is taking place.
|
|
110
|
+
|
|
111
|
+
This method does not block.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
True if the computation is scheduled to take place in the future or is
|
|
115
|
+
taking place now, or False if the computation took place in the past or
|
|
116
|
+
was cancelled.
|
|
117
|
+
"""
|
|
118
|
+
raise NotImplementedError()
|
|
119
|
+
|
|
120
|
+
# NOTE(nathaniel): These aren't quite the semantics I'd like here either. I
|
|
121
|
+
# would rather this only returned True in cases in which the underlying
|
|
122
|
+
# computation completed successfully. A computation's having been cancelled
|
|
123
|
+
# conflicts with considering that computation "done".
|
|
124
|
+
@abc.abstractmethod
|
|
125
|
+
def done(self):
|
|
126
|
+
"""Describes whether the computation has taken place.
|
|
127
|
+
|
|
128
|
+
This method does not block.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
True if the computation is known to have either completed or have been
|
|
132
|
+
unscheduled or interrupted. False if the computation may possibly be
|
|
133
|
+
executing or scheduled to execute later.
|
|
134
|
+
"""
|
|
135
|
+
raise NotImplementedError()
|
|
136
|
+
|
|
137
|
+
@abc.abstractmethod
|
|
138
|
+
def result(self, timeout=None):
|
|
139
|
+
"""Accesses the outcome of the computation or raises its exception.
|
|
140
|
+
|
|
141
|
+
This method may return immediately or may block.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
timeout: The length of time in seconds to wait for the computation to
|
|
145
|
+
finish or be cancelled, or None if this method should block until the
|
|
146
|
+
computation has finished or is cancelled no matter how long that takes.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
The return value of the computation.
|
|
150
|
+
|
|
151
|
+
Raises:
|
|
152
|
+
TimeoutError: If a timeout value is passed and the computation does not
|
|
153
|
+
terminate within the allotted time.
|
|
154
|
+
CancelledError: If the computation was cancelled.
|
|
155
|
+
Exception: If the computation raised an exception, this call will raise
|
|
156
|
+
the same exception.
|
|
157
|
+
"""
|
|
158
|
+
raise NotImplementedError()
|
|
159
|
+
|
|
160
|
+
@abc.abstractmethod
|
|
161
|
+
def exception(self, timeout=None):
|
|
162
|
+
"""Return the exception raised by the computation.
|
|
163
|
+
|
|
164
|
+
This method may return immediately or may block.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
timeout: The length of time in seconds to wait for the computation to
|
|
168
|
+
terminate or be cancelled, or None if this method should block until
|
|
169
|
+
the computation is terminated or is cancelled no matter how long that
|
|
170
|
+
takes.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
The exception raised by the computation, or None if the computation did
|
|
174
|
+
not raise an exception.
|
|
175
|
+
|
|
176
|
+
Raises:
|
|
177
|
+
TimeoutError: If a timeout value is passed and the computation does not
|
|
178
|
+
terminate within the allotted time.
|
|
179
|
+
CancelledError: If the computation was cancelled.
|
|
180
|
+
"""
|
|
181
|
+
raise NotImplementedError()
|
|
182
|
+
|
|
183
|
+
@abc.abstractmethod
|
|
184
|
+
def traceback(self, timeout=None):
|
|
185
|
+
"""Access the traceback of the exception raised by the computation.
|
|
186
|
+
|
|
187
|
+
This method may return immediately or may block.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
timeout: The length of time in seconds to wait for the computation to
|
|
191
|
+
terminate or be cancelled, or None if this method should block until
|
|
192
|
+
the computation is terminated or is cancelled no matter how long that
|
|
193
|
+
takes.
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
The traceback of the exception raised by the computation, or None if the
|
|
197
|
+
computation did not raise an exception.
|
|
198
|
+
|
|
199
|
+
Raises:
|
|
200
|
+
TimeoutError: If a timeout value is passed and the computation does not
|
|
201
|
+
terminate within the allotted time.
|
|
202
|
+
CancelledError: If the computation was cancelled.
|
|
203
|
+
"""
|
|
204
|
+
raise NotImplementedError()
|
|
205
|
+
|
|
206
|
+
@abc.abstractmethod
|
|
207
|
+
def add_done_callback(self, fn):
|
|
208
|
+
"""Adds a function to be called at completion of the computation.
|
|
209
|
+
|
|
210
|
+
The callback will be passed this Future object describing the outcome of
|
|
211
|
+
the computation.
|
|
212
|
+
|
|
213
|
+
If the computation has already completed, the callback will be called
|
|
214
|
+
immediately.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
fn: A callable taking this Future object as its single parameter.
|
|
218
|
+
"""
|
|
219
|
+
raise NotImplementedError()
|