-
Notifications
You must be signed in to change notification settings - Fork 22
/
__init__.pyi
457 lines (378 loc) · 16.1 KB
/
__init__.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
import asyncio
import typing
from concurrent import futures
from types import TracebackType
from grpc import (
_Options,
_PartialStubMustCastOrIgnore,
RpcError,
Compression,
GenericRpcHandler,
ServerCredentials,
StatusCode,
ChannelCredentials,
CallCredentials,
ChannelConnectivity,
HandlerCallDetails,
RpcMethodHandler,
)
"""Exceptions"""
class BaseError(Exception): ...
class UsageError(BaseError): ...
class AbortError(BaseError): ...
class InternalError(BaseError): ...
class AioRpcError(RpcError):
def __init__(
self,
code: StatusCode,
initial_metadata: Metadata,
trailing_metadata: Metadata,
details: typing.Optional[str],
debug_error_string: typing.Optional[str],
) -> None:
...
# FIXME: confirm if these are present in the parent type. The remaining
# methods already exist.
def debug_error_string(self) -> str: ...
def initial_metadata(self) -> Metadata: ...
"""Create Client"""
ClientInterceptor = _PartialStubMustCastOrIgnore
def insecure_channel(
target: str,
options: typing.Optional[_Options] = None,
compression: typing.Optional[Compression] = None,
interceptors: typing.Optional[typing.Sequence[ClientInterceptor]] = None,
) -> Channel: ...
def secure_channel(
target: str,
credentials: ChannelCredentials,
options: typing.Optional[_Options] = None,
compression: typing.Optional[Compression] = None,
interceptors: typing.Optional[typing.Sequence[ClientInterceptor]] = None,
) -> Channel: ...
"""Create Server"""
def server(
migration_thread_pool: typing.Optional[futures.Executor] = None,
handlers: typing.Optional[typing.Sequence[GenericRpcHandler]] = None,
interceptors: typing.Optional[typing.Sequence[ServerInterceptor]] = None,
options: typing.Optional[_Options] = None,
maximum_concurrent_rpcs: typing.Optional[int] = None,
compression: typing.Optional[Compression] = None,
) -> Server: ...
"""Channel Object"""
# XXX: The docs suggest these type signatures for aio, but not for non-async,
# and it's unclear why;
# https://grpc.github.io/grpc/python/grpc_asyncio.html#grpc.aio.Channel.stream_stream
RequestSerializer = typing.Callable[[typing.Any], bytes]
ResponseDeserializer = typing.Callable[[bytes], typing.Any]
class Channel:
async def close(self, grace: typing.Optional[float]) -> None: ...
def get_state(self, try_to_connect: bool = False) -> ChannelConnectivity: ...
async def wait_for_state_change(self, last_observed_state: ChannelConnectivity) -> None: ...
def stream_stream(
self,
method: str,
request_serializer: typing.Optional[RequestSerializer],
response_deserializer: typing.Optional[ResponseDeserializer],
) -> StreamStreamMultiCallable: ...
def stream_unary(
self,
method: str,
request_serializer: typing.Optional[RequestSerializer],
response_deserializer: typing.Optional[ResponseDeserializer],
) -> StreamUnaryMultiCallable: ...
def unary_stream(
self,
method: str,
request_serializer: typing.Optional[RequestSerializer],
response_deserializer: typing.Optional[ResponseDeserializer],
) -> UnaryStreamMultiCallable: ...
def unary_unary(
self,
method: str,
request_serializer: typing.Optional[RequestSerializer],
response_deserializer: typing.Optional[ResponseDeserializer],
) -> UnaryUnaryMultiCallable: ...
async def __aenter__(self) -> Channel: ...
async def __aexit__(
self,
exc_type: typing.Optional[typing.Type[BaseException]],
exc_val: typing.Optional[BaseException],
exc_tb: typing.Optional[TracebackType],
) -> typing.Optional[bool]: ...
async def channel_ready(self) -> None: ...
"""Server Object"""
class Server:
def add_generic_rpc_handlers(
self,
generic_rpc_handlers: typing.Iterable[GenericRpcHandler],
) -> None: ...
# Returns an integer port on which server will accept RPC requests.
def add_insecure_port(self, address: str) -> int: ...
# Returns an integer port on which server will accept RPC requests.
def add_secure_port(
self, address: str, server_credentials: ServerCredentials
) -> int: ...
async def start(self) -> None: ...
# Grace period is in seconds.
async def stop(self, grace: typing.Optional[float] = None) -> None: ...
# Returns a bool indicates if the operation times out. Timeout is in seconds.
async def wait_for_termination(
self, timeout: typing.Optional[float] = None
) -> bool: ...
"""Client-Side Context"""
DoneCallbackType = typing.Callable[[typing.Any], None]
EOFType = object
class RpcContext:
def cancelled(self) -> bool: ...
def done(self) -> bool: ...
def time_remaining(self) -> typing.Optional[float]: ...
def cancel(self) -> bool: ...
def add_done_callback(self, callback: DoneCallbackType) -> None: ...
class Call(RpcContext):
async def initial_metadata(self) -> Metadata: ...
async def trailing_metadata(self) -> Metadata: ...
async def code(self) -> StatusCode: ...
async def details(self) -> str: ...
async def wait_for_connection(self) -> None: ...
class UnaryUnaryCall(typing.Generic[TRequest, TResponse], Call):
def __await__(self) -> typing.Generator[None, None, TResponse]: ...
class UnaryStreamCall(typing.Generic[TRequest, TResponse], Call):
def __aiter__(self) -> typing.AsyncIterator[TResponse]: ...
async def read(self) -> typing.Union[EOFType, TResponse]: ...
class StreamUnaryCall(typing.Generic[TRequest, TResponse], Call):
async def write(self, request: TRequest) -> None: ...
async def done_writing(self) -> None: ...
def __await__(self) -> typing.Generator[None, None, TResponse]: ...
class StreamStreamCall(typing.Generic[TRequest, TResponse], Call):
def __aiter__(self) -> typing.AsyncIterator[TResponse]: ...
async def read(self) -> typing.Union[EOFType, TResponse]: ...
async def write(self, request: TRequest) -> None: ...
async def done_writing(self) -> None: ...
TRequest = typing.TypeVar("TRequest")
TResponse = typing.TypeVar("TResponse")
"""Service-Side Context"""
class DoneCallback(typing.Generic[TRequest, TResponse]):
def __call__(
self,
ctx: ServicerContext[TRequest, TResponse],
) -> None:
...
class ServicerContext(typing.Generic[TRequest, TResponse]):
async def abort(
self,
code: StatusCode,
details: str = "",
trailing_metadata: MetadataType = tuple(),
) -> typing.NoReturn: ...
async def read(self) -> TRequest: ...
async def write(self, message: TResponse) -> None: ...
async def send_initial_metadata(self, initial_metadata: MetadataType) -> None: ...
def add_done_callback(self, callback: DoneCallback[TRequest, TResponse]) -> None: ...
def set_trailing_metadata(self, trailing_metadata: MetadataType) -> None: ...
def invocation_metadata(self) -> typing.Optional[Metadata]: ...
def set_code(self, code: StatusCode) -> None: ...
def set_details(self, details: str) -> None: ...
def set_compression(self, compression: Compression) -> None: ...
def disable_next_message_compression(self) -> None: ...
def peer(self) -> str: ...
def peer_identities(self) -> typing.Optional[typing.Iterable[bytes]]: ...
def peer_identity_key(self) -> typing.Optional[str]: ...
def auth_context(self) -> typing.Mapping[str, typing.Iterable[bytes]]: ...
def time_remaining(self) -> float: ...
def trailing_metadata(self) -> Metadata: ...
def code(self) -> StatusCode: ...
def details(self) -> str: ...
def cancelled(self) -> bool: ...
def done(self) -> bool: ...
"""Client-Side Interceptor"""
class ClientCallDetails:
def __init__(
self,
method: str,
timeout: typing.Optional[float],
metadata: typing.Optional[Metadata],
credentials: typing.Optional[CallCredentials],
wait_for_ready: typing.Optional[bool],
) -> None:
...
method: str
timeout: typing.Optional[float]
metadata: typing.Optional[Metadata]
credentials: typing.Optional[CallCredentials]
# "This is an EXPERIMENTAL argument. An optional flag t enable wait for ready mechanism."
wait_for_ready: typing.Optional[bool]
# As at 1.53.0, this is not supported in aio:
# compression: typing.Optional[Compression]
class InterceptedCall(typing.Generic[TRequest, TResponse]):
def __init__(self, interceptors_task: asyncio.Task) -> None: ...
def __del__(self): ...
def cancel(self) -> bool: ...
def cancelled(self) -> bool: ...
def done(self) -> bool: ...
def add_done_callback(self, callback: DoneCallback[TRequest, TResponse]) -> None: ...
def time_remaining(self) -> typing.Optional[float]: ...
async def initial_metadata(self) -> typing.Optional[Metadata]: ...
async def trailing_metadata(self) -> typing.Optional[Metadata]: ...
async def code(self) -> StatusCode: ...
async def details(self) -> str: ...
async def debug_error_string(self) -> typing.Optional[str]: ...
async def wait_for_connection(self) -> None: ...
class InterceptedUnaryUnaryCall(InterceptedCall[TRequest, TResponse], typing.Generic[TRequest, TResponse]):
def __await__(self): ...
def __init__(
self,
interceptors: typing.Sequence[UnaryUnaryClientInterceptor],
request: TRequest,
timeout: typing.Optional[float],
metadata: Metadata,
credentials: typing.Optional[CallCredentials],
wait_for_ready: typing.Optional[bool],
channel: Channel,
method: bytes,
request_serializer: RequestSerializer,
response_deserializer: ResponseDeserializer,
loop: asyncio.AbstractEventLoop,
) -> None:
...
# pylint: disable=too-many-arguments
async def _invoke(
self,
interceptors: typing.Sequence[UnaryUnaryClientInterceptor],
method: bytes,
timeout: typing.Optional[float],
metadata: typing.Optional[Metadata],
credentials: typing.Optional[CallCredentials],
wait_for_ready: typing.Optional[bool],
request: TRequest,
request_serializer: RequestSerializer,
response_deserializer: ResponseDeserializer,
) -> UnaryUnaryCall:
...
def time_remaining(self) -> typing.Optional[float]: ...
class UnaryUnaryClientInterceptor(typing.Generic[TRequest, TResponse]):
async def intercept_unary_unary(
self,
# XXX: See equivalent function in grpc types for notes about continuation:
continuation: typing.Callable[[ClientCallDetails, TRequest], UnaryUnaryCall[TRequest, TResponse]],
client_call_details: ClientCallDetails,
request: TRequest,
) -> TResponse:
...
class UnaryStreamClientInterceptor(typing.Generic[TRequest, TResponse]):
async def intercept_unary_stream(
self,
continuation: typing.Callable[[ClientCallDetails, TRequest], UnaryStreamCall[TRequest, TResponse]],
client_call_details: ClientCallDetails,
request: TRequest,
) -> typing.Union[
typing.AsyncIterable[TResponse],
UnaryStreamCall[TRequest, TResponse],
]:
...
class StreamUnaryClientInterceptor(typing.Generic[TRequest, TResponse]):
async def intercept_stream_unary(
self,
continuation: typing.Callable[[ClientCallDetails, TRequest], StreamUnaryCall[TRequest, TResponse]],
client_call_details: ClientCallDetails,
request_iterator: typing.Union[typing.AsyncIterable[TRequest], typing.Iterable[TRequest]],
) -> typing.Union[
typing.AsyncIterable[TResponse],
UnaryStreamCall[TRequest, TResponse],
]:
...
class StreamStreamClientInterceptor(typing.Generic[TRequest, TResponse]):
async def intercept_stream_stream(
self,
continuation: typing.Callable[[ClientCallDetails, TRequest], StreamStreamCall[TRequest, TResponse]],
client_call_details: ClientCallDetails,
request_iterator: typing.Union[typing.AsyncIterable[TRequest], typing.Iterable[TRequest]],
) -> typing.Union[
typing.AsyncIterable[TResponse],
StreamStreamCall[TRequest, TResponse],
]:
...
"""Server-Side Interceptor"""
class ServerInterceptor(typing.Generic[TRequest, TResponse]):
async def intercept_service(
self,
continuation: typing.Callable[
[HandlerCallDetails],
typing.Awaitable[RpcMethodHandler[TRequest, TResponse]],
],
handler_call_details: HandlerCallDetails,
) -> RpcMethodHandler[TRequest, TResponse]:
...
"""Multi-Callable Interfaces"""
class UnaryUnaryMultiCallable(typing.Generic[TRequest, TResponse]):
def __call__(
self,
request: TRequest,
timeout: typing.Optional[float] = None,
metadata: typing.Optional[MetadataType] = None,
credentials: typing.Optional[CallCredentials] = None,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: typing.Optional[bool] = None,
compression: typing.Optional[Compression] = None,
) -> UnaryUnaryCall[TRequest, TResponse]: ...
class UnaryStreamMultiCallable(typing.Generic[TRequest, TResponse]):
def __call__(
self,
request: TRequest,
timeout: typing.Optional[float] = None,
metadata: typing.Optional[MetadataType] = None,
credentials: typing.Optional[CallCredentials] = None,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: typing.Optional[bool] = None,
compression: typing.Optional[Compression] = None,
) -> UnaryStreamCall[TRequest, TResponse]: ...
class StreamUnaryMultiCallable(typing.Generic[TRequest, TResponse]):
def __call__(
self,
request_iterator: typing.Optional[
typing.Union[typing.AsyncIterator[TRequest], typing.Iterator[TRequest]]
],
timeout: typing.Optional[float] = None,
metadata: typing.Optional[MetadataType] = None,
credentials: typing.Optional[CallCredentials] = None,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: typing.Optional[bool] = None,
compression: typing.Optional[Compression] = None,
) -> StreamUnaryCall[TRequest, TResponse]: ...
class StreamStreamMultiCallable(typing.Generic[TRequest, TResponse]):
def __call__(
self,
request_iterator: typing.Optional[
typing.Union[typing.AsyncIterator[TRequest], typing.Iterator[TRequest]]
],
timeout: typing.Optional[float] = None,
metadata: typing.Optional[MetadataType] = None,
credentials: typing.Optional[CallCredentials] = None,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: typing.Optional[bool] = None,
compression: typing.Optional[Compression] = None,
) -> StreamStreamCall[TRequest, TResponse]: ...
"""Metadata"""
MetadataKey = str
MetadataValue = typing.Union[str, bytes]
MetadatumType = typing.Tuple[MetadataKey, MetadataValue]
MetadataType = typing.Union[Metadata, typing.Sequence[MetadatumType]]
class Metadata(typing.Mapping):
def __init__(self, *args: typing.Tuple[MetadataKey, MetadataValue]) -> None: ...
@classmethod
def from_tuple(
cls, raw_metadata: typing.Tuple[MetadataKey, MetadataValue]
) -> Metadata: ...
def add(self, key: MetadataKey, value: MetadataValue) -> None: ...
def __len__(self) -> int: ...
def __getitem__(self, key: MetadataKey) -> MetadataValue: ...
def __setitem__(self, key: MetadataKey, value: MetadataValue) -> None: ...
def __delitem__(self, key: MetadataKey) -> None: ...
def delete_all(self, key: MetadataKey) -> None: ...
def __iter__(self) -> typing.Iterator[typing.Tuple[MetadataKey, MetadataValue]]: ...
def get_all(self, key: MetadataKey) -> typing.List[MetadataValue]: ...
def set_all(self, key: MetadataKey, values: typing.List[MetadataValue]) -> None: ...
def __contains__(self, key: object) -> bool: ...
def __eq__(self, other: typing.Any) -> bool: ...
def __add__(self, other: typing.Any) -> Metadata: ...
def __repr__(self) -> str: ...