encore-dev 2.0.0b9__tar.gz → 2.0.0b10__tar.gz
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.
- encore_dev-2.0.0b9/README.md → encore_dev-2.0.0b10/PKG-INFO +56 -3
- encore_dev-2.0.0b9/PKG-INFO → encore_dev-2.0.0b10/README.md +32 -26
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/_native.pyi +157 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/clients.py +39 -8
- encore_dev-2.0.0b10/encore/internal/grpc.py +208 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/services/__init__.py +17 -3
- encore_dev-2.0.0b10/encore/storage/__init__.py +5 -0
- encore_dev-2.0.0b10/encore/storage/clickhouse/__init__.py +654 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/pyproject.toml +7 -5
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/pyproject.toml.orig +14 -8
- encore_dev-2.0.0b9/encore/storage/__init__.py +0 -5
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/_run.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/config/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/config/_build.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/config/_markers.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/cron/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/django/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/django/base.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/env/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/errs/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/frontends/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/gateway/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/gateway/_serve.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/gateway/match.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/gateways/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/_loader.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/lazy.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/reqfields.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/runtime.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/startup.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/internal/testscope.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/logs/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/logs/_api.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/logs/_console.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/logs/_runtime.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/metrics/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/metrics/_instrument.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/metrics/_metrics.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/metrics/_provider.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/pubsub/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/py.typed +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/reqctx/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/reqctx/_json.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/secrets/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/server/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/server/_serve.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/server/_span.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/server/_tracing.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/server/asgi.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/server/wsgi.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/services/_propagate.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/services/aiohttp.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/services/httpx.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/services/niquests.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/services/requests.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/shutdown/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/objects/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/postgres/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/_base.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/_batch.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/_errors.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/_responses.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/_scan.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/_values.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/bitmap.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/command.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/generic.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/geo.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/hash.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/hyperloglog.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/json.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/list.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/pubsub.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/script.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/set.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/sorted_set.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/stream.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/storage/redis/string.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/testing/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/testing/_playwright_fixtures.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/testing/_steps.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/testing/playwright.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/testing/pytest_plugin.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/testing/system.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/tracing/__init__.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/tracing/_context.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/tracing/_encode.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/tracing/_provider.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/tracing/_span.py +0 -0
- {encore_dev-2.0.0b9 → encore_dev-2.0.0b10}/encore/tracing/_tracer.py +0 -0
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: encore-dev
|
|
3
|
+
Version: 2.0.0b10
|
|
4
|
+
Summary: Encore SDK for Python — infrastructure resources
|
|
5
|
+
Author: Encore
|
|
6
|
+
License: MPL-2.0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Requires-Dist: opentelemetry-api>=1.27
|
|
9
|
+
Requires-Dist: typing-extensions>=4.13
|
|
10
|
+
Requires-Dist: aiohttp>=3.14.4 ; python_full_version >= '3.10' and extra == 'aiohttp'
|
|
11
|
+
Requires-Dist: connectrpc>=0.13.0,<0.14 ; python_full_version >= '3.11' and extra == 'grpc'
|
|
12
|
+
Requires-Dist: protobuf-py==0.7.0 ; python_full_version >= '3.11' and extra == 'grpc'
|
|
13
|
+
Requires-Dist: pyqwest>=0.14 ; python_full_version >= '3.11' and extra == 'grpc'
|
|
14
|
+
Requires-Dist: httpx>=0.27 ; extra == 'httpx'
|
|
15
|
+
Requires-Dist: niquests>=3.19 ; extra == 'niquests'
|
|
16
|
+
Requires-Dist: requests>=2.34 ; python_full_version >= '3.10' and extra == 'requests'
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Provides-Extra: aiohttp
|
|
19
|
+
Provides-Extra: grpc
|
|
20
|
+
Provides-Extra: httpx
|
|
21
|
+
Provides-Extra: niquests
|
|
22
|
+
Provides-Extra: requests
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
1
25
|
# Encore SDK for Python
|
|
2
26
|
|
|
3
27
|
The Python SDK for [Encore](https://encore.dev) — **infrastructure resources only**.
|
|
@@ -187,7 +211,9 @@ its `code` is the `ErrCode` the service answered with, or the one its HTTP
|
|
|
187
211
|
status means; `UNAVAILABLE` when no answer came, and `DEADLINE_EXCEEDED` when
|
|
188
212
|
the call took longer than its timeout. `message` says what went wrong, and
|
|
189
213
|
`status` is the HTTP status of the service's answer, 0 when there was none. A GraphQL answer with errors raises its subclass
|
|
190
|
-
`GraphQLRequestError`, whose `errors` are the answer's
|
|
214
|
+
`GraphQLRequestError`, whose `errors` are the answer's, and a gRPC status's
|
|
215
|
+
details are its `details`, each its protobuf-py message, or the
|
|
216
|
+
`protobuf.wkt.Any` it came as, for a type the client's protos lack.
|
|
191
217
|
|
|
192
218
|
```python
|
|
193
219
|
from encore.errs import ErrCode
|
|
@@ -201,9 +227,36 @@ except CallError as error:
|
|
|
201
227
|
product = None
|
|
202
228
|
```
|
|
203
229
|
|
|
230
|
+
A gRPC module speaks the gRPC protocol over HTTP/2, with connectrpc, so it
|
|
231
|
+
calls any gRPC server: h2c to an `http://` URL, TLS to an `https://` one,
|
|
232
|
+
trusting the system's certificates and those `SSL_CERT_FILE` and
|
|
233
|
+
`SSL_CERT_DIR` name. A server or bidi stream is an async iterator, and a client
|
|
234
|
+
or bidi stream takes an async iterable of requests. Its messages are
|
|
235
|
+
protobuf-py's, which `protoc-gen-py` generates into `encore_gen/protos/`, a
|
|
236
|
+
module per `.proto` file that every client of the service shares; the gRPC
|
|
237
|
+
module has the top-level messages and enums of the service's protos as its
|
|
238
|
+
own, and the well-known types its RPCs take and return.
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
async for update in catalog.grpc.stuff_service.watch_stuff(
|
|
242
|
+
catalog.grpc.WatchRequest(), timeout=30.0
|
|
243
|
+
):
|
|
244
|
+
print(update)
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
A gRPC call behaves as connectrpc makes it, which `CallError` only carries
|
|
248
|
+
the code of. Its timeout is its deadline, which the service is told, and which
|
|
249
|
+
applies to each read from the network: a stream raises `DEADLINE_EXCEEDED` at
|
|
250
|
+
the read after it, so messages that arrived together in one read can still
|
|
251
|
+
come past it. Cancelling the task that makes a call fails the call with
|
|
252
|
+
`CANCELED`, which an `except CallError` catches too unless it raises that code
|
|
253
|
+
again, and an exception the requests of a stream raise fails it with
|
|
254
|
+
`UNAVAILABLE`, that exception its `__cause__`.
|
|
255
|
+
|
|
204
256
|
OpenAPI and GraphQL modules need httpx (`encore-dev[httpx]`), and gRPC modules
|
|
205
|
-
connectrpc (`encore-dev[grpc]`, on Python 3.11 and later). A
|
|
206
|
-
when first used, so a service needs only what the modules it
|
|
257
|
+
connectrpc and protobuf-py (`encore-dev[grpc]`, on Python 3.11 and later). A
|
|
258
|
+
module is imported when first used, so a service needs only what the modules it
|
|
259
|
+
uses need.
|
|
207
260
|
|
|
208
261
|
## Request Context
|
|
209
262
|
|
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: encore-dev
|
|
3
|
-
Version: 2.0.0b9
|
|
4
|
-
Summary: Encore SDK for Python — infrastructure resources
|
|
5
|
-
Author: Encore
|
|
6
|
-
License: MPL-2.0
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Requires-Dist: opentelemetry-api>=1.27
|
|
9
|
-
Requires-Dist: typing-extensions>=4.13
|
|
10
|
-
Requires-Dist: aiohttp>=3.14.4 ; python_full_version >= '3.10' and extra == 'aiohttp'
|
|
11
|
-
Requires-Dist: connectrpc>=0.10.1,<0.11 ; python_full_version >= '3.11' and extra == 'grpc'
|
|
12
|
-
Requires-Dist: pyqwest>=0.12 ; python_full_version >= '3.11' and extra == 'grpc'
|
|
13
|
-
Requires-Dist: httpx>=0.27 ; extra == 'httpx'
|
|
14
|
-
Requires-Dist: niquests>=3.19 ; extra == 'niquests'
|
|
15
|
-
Requires-Dist: requests>=2.34 ; python_full_version >= '3.10' and extra == 'requests'
|
|
16
|
-
Requires-Python: >=3.9
|
|
17
|
-
Provides-Extra: aiohttp
|
|
18
|
-
Provides-Extra: grpc
|
|
19
|
-
Provides-Extra: httpx
|
|
20
|
-
Provides-Extra: niquests
|
|
21
|
-
Provides-Extra: requests
|
|
22
|
-
Description-Content-Type: text/markdown
|
|
23
|
-
|
|
24
1
|
# Encore SDK for Python
|
|
25
2
|
|
|
26
3
|
The Python SDK for [Encore](https://encore.dev) — **infrastructure resources only**.
|
|
@@ -210,7 +187,9 @@ its `code` is the `ErrCode` the service answered with, or the one its HTTP
|
|
|
210
187
|
status means; `UNAVAILABLE` when no answer came, and `DEADLINE_EXCEEDED` when
|
|
211
188
|
the call took longer than its timeout. `message` says what went wrong, and
|
|
212
189
|
`status` is the HTTP status of the service's answer, 0 when there was none. A GraphQL answer with errors raises its subclass
|
|
213
|
-
`GraphQLRequestError`, whose `errors` are the answer's
|
|
190
|
+
`GraphQLRequestError`, whose `errors` are the answer's, and a gRPC status's
|
|
191
|
+
details are its `details`, each its protobuf-py message, or the
|
|
192
|
+
`protobuf.wkt.Any` it came as, for a type the client's protos lack.
|
|
214
193
|
|
|
215
194
|
```python
|
|
216
195
|
from encore.errs import ErrCode
|
|
@@ -224,9 +203,36 @@ except CallError as error:
|
|
|
224
203
|
product = None
|
|
225
204
|
```
|
|
226
205
|
|
|
206
|
+
A gRPC module speaks the gRPC protocol over HTTP/2, with connectrpc, so it
|
|
207
|
+
calls any gRPC server: h2c to an `http://` URL, TLS to an `https://` one,
|
|
208
|
+
trusting the system's certificates and those `SSL_CERT_FILE` and
|
|
209
|
+
`SSL_CERT_DIR` name. A server or bidi stream is an async iterator, and a client
|
|
210
|
+
or bidi stream takes an async iterable of requests. Its messages are
|
|
211
|
+
protobuf-py's, which `protoc-gen-py` generates into `encore_gen/protos/`, a
|
|
212
|
+
module per `.proto` file that every client of the service shares; the gRPC
|
|
213
|
+
module has the top-level messages and enums of the service's protos as its
|
|
214
|
+
own, and the well-known types its RPCs take and return.
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
async for update in catalog.grpc.stuff_service.watch_stuff(
|
|
218
|
+
catalog.grpc.WatchRequest(), timeout=30.0
|
|
219
|
+
):
|
|
220
|
+
print(update)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
A gRPC call behaves as connectrpc makes it, which `CallError` only carries
|
|
224
|
+
the code of. Its timeout is its deadline, which the service is told, and which
|
|
225
|
+
applies to each read from the network: a stream raises `DEADLINE_EXCEEDED` at
|
|
226
|
+
the read after it, so messages that arrived together in one read can still
|
|
227
|
+
come past it. Cancelling the task that makes a call fails the call with
|
|
228
|
+
`CANCELED`, which an `except CallError` catches too unless it raises that code
|
|
229
|
+
again, and an exception the requests of a stream raise fails it with
|
|
230
|
+
`UNAVAILABLE`, that exception its `__cause__`.
|
|
231
|
+
|
|
227
232
|
OpenAPI and GraphQL modules need httpx (`encore-dev[httpx]`), and gRPC modules
|
|
228
|
-
connectrpc (`encore-dev[grpc]`, on Python 3.11 and later). A
|
|
229
|
-
when first used, so a service needs only what the modules it
|
|
233
|
+
connectrpc and protobuf-py (`encore-dev[grpc]`, on Python 3.11 and later). A
|
|
234
|
+
module is imported when first used, so a service needs only what the modules it
|
|
235
|
+
uses need.
|
|
230
236
|
|
|
231
237
|
## Request Context
|
|
232
238
|
|
|
@@ -56,6 +56,153 @@ class BucketObject:
|
|
|
56
56
|
class ByteRange:
|
|
57
57
|
def __new__(cls, /, *, offset: int, length: int |None = None) -> "ByteRange": ...
|
|
58
58
|
|
|
59
|
+
@final
|
|
60
|
+
class ClickHouseAccess:
|
|
61
|
+
"""
|
|
62
|
+
What a handle may do: which of the database's users its requests are
|
|
63
|
+
made as. A level without a user of its own uses the next one up, and
|
|
64
|
+
reads made so are kept read-only by setting.
|
|
65
|
+
"""
|
|
66
|
+
Admin: Final[ClickHouseAccess]
|
|
67
|
+
Read: Final[ClickHouseAccess]
|
|
68
|
+
Write: Final[ClickHouseAccess]
|
|
69
|
+
def __eq__(self, value: object, /) -> bool: ...
|
|
70
|
+
def __int__(self, /) -> int: ...
|
|
71
|
+
def __ne__(self, value: object, /) -> bool: ...
|
|
72
|
+
def __repr__(self, /) -> str: ...
|
|
73
|
+
|
|
74
|
+
@final
|
|
75
|
+
class ClickHouseCursor:
|
|
76
|
+
"""
|
|
77
|
+
A streaming query result. Its rows are read in batches; closing it, or
|
|
78
|
+
dropping it, stops a read-only query on the server.
|
|
79
|
+
"""
|
|
80
|
+
def close(self, /) -> "typing.Awaitable[None]":
|
|
81
|
+
"""
|
|
82
|
+
Close the cursor: a read-only query still running stops.
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
An awaitable that completes once any active read finishes.
|
|
86
|
+
Repeated closes have no effect.
|
|
87
|
+
"""
|
|
88
|
+
@property
|
|
89
|
+
def columns(self, /) -> list[tuple[str, str]]:
|
|
90
|
+
"""
|
|
91
|
+
The result's columns: (name, ClickHouse type) pairs.
|
|
92
|
+
"""
|
|
93
|
+
def next_batch(self, /, max: int) -> "typing.Awaitable[typing.Optional[list[dict[str, typing.Any]]]]":
|
|
94
|
+
"""
|
|
95
|
+
Fetch the next rows.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
max: The most rows to fetch.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
An awaitable that produces up to max dictionaries of column names
|
|
102
|
+
to values, or None once the rows are exhausted or the cursor
|
|
103
|
+
closed.
|
|
104
|
+
|
|
105
|
+
Raises:
|
|
106
|
+
DatabaseError: The server fails the query while sending its rows,
|
|
107
|
+
or they can't be decoded.
|
|
108
|
+
"""
|
|
109
|
+
@property
|
|
110
|
+
def query_id(self, /) -> str:
|
|
111
|
+
"""
|
|
112
|
+
The query's id on the server.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
@final
|
|
116
|
+
class ClickHouseDatabase:
|
|
117
|
+
"""
|
|
118
|
+
A handle to a ClickHouse database at an access level.
|
|
119
|
+
"""
|
|
120
|
+
def conn_string(self, /) -> "str":
|
|
121
|
+
"""
|
|
122
|
+
Return a URL to connect to the database with as the handle's user.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
`http[s]://user:password@host:port/database`.
|
|
126
|
+
|
|
127
|
+
Raises:
|
|
128
|
+
DatabaseError: The database is not configured, or has no user for
|
|
129
|
+
the handle's access level.
|
|
130
|
+
"""
|
|
131
|
+
def exec(self, /, sql: str, params: Any |None = None, settings: Sequence[tuple[str, str]] |None = None, query_id: str |None = None, source: bytes |None = None) -> "typing.Awaitable[tuple[int, int, int, str]]":
|
|
132
|
+
"""
|
|
133
|
+
Run a statement, discarding any rows it returns.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
sql: The statement, its parameters named and typed in it as
|
|
137
|
+
`{name:Type}`.
|
|
138
|
+
params: The parameters' values, by name.
|
|
139
|
+
settings: Settings for this statement only, by name.
|
|
140
|
+
query_id: The statement's id on the server; None lets it choose one.
|
|
141
|
+
source: Encoded parent tracing context, or None when no context is active.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
An awaitable that produces the server's summary: (rows written,
|
|
145
|
+
bytes written, rows read, query id).
|
|
146
|
+
|
|
147
|
+
Raises:
|
|
148
|
+
DatabaseError: A parameter can't be sent, or the server can't be
|
|
149
|
+
reached or fails the statement.
|
|
150
|
+
"""
|
|
151
|
+
def insert(self, /, table: str, rows: Any, settings: Sequence[tuple[str, str]] |None = None, source: bytes |None = None) -> "typing.Awaitable[tuple[int, int, int, str]]":
|
|
152
|
+
"""
|
|
153
|
+
Insert rows into a table.
|
|
154
|
+
|
|
155
|
+
The columns are the union of the rows' keys, in the order first seen.
|
|
156
|
+
A column a row has no key for is sent as NULL, which a column that
|
|
157
|
+
isn't Nullable takes as its default. (The core's insert can't leave
|
|
158
|
+
a row's value out, which would give a Nullable column its DEFAULT.)
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
table: The table, as `table` or `database.table`.
|
|
162
|
+
rows: The rows: mappings of column names to values.
|
|
163
|
+
settings: Settings for this insert only, by name.
|
|
164
|
+
source: Encoded parent tracing context, or None when no context is active.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
An awaitable that produces the server's summary: (rows written,
|
|
168
|
+
bytes written, rows read, query id). No rows insert nothing, and
|
|
169
|
+
produce zeros.
|
|
170
|
+
|
|
171
|
+
Raises:
|
|
172
|
+
DatabaseError: A value can't be sent, the table name is invalid, or
|
|
173
|
+
the server can't be reached or fails the insert.
|
|
174
|
+
"""
|
|
175
|
+
def query(self, /, sql: str, params: Any |None = None, settings: Sequence[tuple[str, str]] |None = None, query_id: str |None = None, source: bytes |None = None) -> "typing.Awaitable[ClickHouseCursor]":
|
|
176
|
+
"""
|
|
177
|
+
Start a query and return an awaitable cursor over its rows.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
sql: The query, its parameters named and typed in it as
|
|
181
|
+
`{name:Type}`.
|
|
182
|
+
params: The parameters' values, by name.
|
|
183
|
+
settings: Settings for this query only, by name.
|
|
184
|
+
query_id: The query's id on the server; None lets it choose one.
|
|
185
|
+
source: Encoded parent tracing context, or None when no context is active.
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
An awaitable that produces a ClickHouseCursor once the server has
|
|
189
|
+
started sending rows.
|
|
190
|
+
|
|
191
|
+
Raises:
|
|
192
|
+
DatabaseError: A parameter can't be sent, or the server can't be
|
|
193
|
+
reached or fails the query.
|
|
194
|
+
"""
|
|
195
|
+
def with_access(self, /, access: ClickHouseAccess) -> "ClickHouseDatabase":
|
|
196
|
+
"""
|
|
197
|
+
Return a handle to the same database for another access level.
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
access: What the handle may do.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
A handle whose requests are made as that level's user.
|
|
204
|
+
"""
|
|
205
|
+
|
|
59
206
|
@final
|
|
60
207
|
class Config:
|
|
61
208
|
def current(self, /) -> "tuple[int, str]":
|
|
@@ -1117,6 +1264,11 @@ class Runtime:
|
|
|
1117
1264
|
"""
|
|
1118
1265
|
Wait until shutdown has reached or passed Cleanup. Call begin_shutdown first.
|
|
1119
1266
|
"""
|
|
1267
|
+
def clickhouse_database(self, /, name: str) -> "ClickHouseDatabase":
|
|
1268
|
+
"""
|
|
1269
|
+
A write handle to the named ClickHouse database (looked up in the
|
|
1270
|
+
runtime config). One that isn't configured fails each call with why.
|
|
1271
|
+
"""
|
|
1120
1272
|
def completed(self, /) -> "typing.Awaitable[ShutdownResult]":
|
|
1121
1273
|
"""
|
|
1122
1274
|
Wait for cleanup to finish, including after its deadline has elapsed.
|
|
@@ -1307,6 +1459,11 @@ class TestScope:
|
|
|
1307
1459
|
span, as its 25-byte context and tracestate, where the process
|
|
1308
1460
|
records spans. None for any other test.
|
|
1309
1461
|
"""
|
|
1462
|
+
def clickhouse_database(self, /, name: str) -> "ClickHouseDatabase":
|
|
1463
|
+
"""
|
|
1464
|
+
The test's write handle on its instance of the ClickHouse database
|
|
1465
|
+
`name`. The instance is provisioned when the handle is first used.
|
|
1466
|
+
"""
|
|
1310
1467
|
def config(self, /, name: str) -> "typing.Optional[str]":
|
|
1311
1468
|
"""
|
|
1312
1469
|
The value the test has given the config `name`, as `set_config`
|
|
@@ -11,6 +11,7 @@ import asyncio
|
|
|
11
11
|
import base64
|
|
12
12
|
import importlib
|
|
13
13
|
import json
|
|
14
|
+
import os
|
|
14
15
|
import threading
|
|
15
16
|
import weakref
|
|
16
17
|
from typing import (
|
|
@@ -281,11 +282,13 @@ def pyqwest_client() -> pyqwest.Client:
|
|
|
281
282
|
|
|
282
283
|
For Encore's generated clients, which call it for every request they
|
|
283
284
|
send without an ``http_client`` of the caller's: an app's own code makes
|
|
284
|
-
clients of its own. It
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
285
|
+
clients of its own. It speaks HTTP/2, as gRPC does: with prior knowledge
|
|
286
|
+
(h2c) to an ``http`` URL, and over TLS, with ALPN, to an ``https`` one,
|
|
287
|
+
trusting the system's certificates and those of the files
|
|
288
|
+
``SSL_CERT_FILE`` and ``SSL_CERT_DIR`` name. Its connections are pooled
|
|
289
|
+
for the whole process and work on any event loop. It sends the current
|
|
290
|
+
trace, and adds the current Request Context to the requests it sends to
|
|
291
|
+
the app's services. It is never closed.
|
|
289
292
|
|
|
290
293
|
Raises:
|
|
291
294
|
ImportError: pyqwest is not installed.
|
|
@@ -300,11 +303,39 @@ def pyqwest_client() -> pyqwest.Client:
|
|
|
300
303
|
"Encore's generated gRPC clients need connectrpc: "
|
|
301
304
|
"pip install 'encore-dev[grpc]'"
|
|
302
305
|
) from error
|
|
303
|
-
|
|
304
|
-
|
|
306
|
+
# Redirects are not followed: a gRPC call is a POST to its
|
|
307
|
+
# method's path, which nothing redirects.
|
|
308
|
+
http2 = pyqwest.HTTPTransport(
|
|
309
|
+
http_version=pyqwest.HTTPVersion.HTTP2,
|
|
310
|
+
tls_include_system_certs=True,
|
|
311
|
+
tls_ca_cert=_ca_certificates(),
|
|
312
|
+
follow_redirects=False,
|
|
313
|
+
)
|
|
314
|
+
_pyqwest_client = pyqwest.Client(_PyqwestTransport(http2))
|
|
305
315
|
return _pyqwest_client
|
|
306
316
|
|
|
307
317
|
|
|
318
|
+
def _ca_certificates() -> Optional[bytes]:
|
|
319
|
+
"""The PEM certificates of ``SSL_CERT_FILE`` and ``SSL_CERT_DIR``, as OpenSSL reads them."""
|
|
320
|
+
found = []
|
|
321
|
+
file = os.environ.get("SSL_CERT_FILE")
|
|
322
|
+
if file and os.path.isfile(file):
|
|
323
|
+
with open(file, "rb") as f:
|
|
324
|
+
found.append(f.read())
|
|
325
|
+
for directory in filter(None, os.environ.get("SSL_CERT_DIR", "").split(os.pathsep)):
|
|
326
|
+
if not os.path.isdir(directory):
|
|
327
|
+
continue
|
|
328
|
+
for name in sorted(os.listdir(directory)):
|
|
329
|
+
path = os.path.join(directory, name)
|
|
330
|
+
if not os.path.isfile(path):
|
|
331
|
+
continue
|
|
332
|
+
with open(path, "rb") as f:
|
|
333
|
+
data = f.read()
|
|
334
|
+
if b"-----BEGIN CERTIFICATE-----" in data:
|
|
335
|
+
found.append(data)
|
|
336
|
+
return b"\n".join(found) if found else None
|
|
337
|
+
|
|
338
|
+
|
|
308
339
|
class _PyqwestTransport:
|
|
309
340
|
"""A pyqwest transport adding Request Context to requests for the app's services."""
|
|
310
341
|
|
|
@@ -313,7 +344,7 @@ class _PyqwestTransport:
|
|
|
313
344
|
|
|
314
345
|
def execute(self, request: pyqwest.Request) -> Any:
|
|
315
346
|
"""Send ``request`` through the base transport, with its Request Context."""
|
|
316
|
-
#
|
|
347
|
+
# pyqwest's transport sends the current trace itself. Its headers
|
|
317
348
|
# are a mutable mapping, which their type does not say.
|
|
318
349
|
headers = cast("MutableMapping[Any, Any]", request.headers)
|
|
319
350
|
_propagate.prepare(request.url, headers, trace=False)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"""How Encore's generated gRPC clients call services.
|
|
2
|
+
|
|
3
|
+
For the generated code alone: an app's own code takes the clients' errors
|
|
4
|
+
from [encore.services]. Its API may change with the generator's.
|
|
5
|
+
|
|
6
|
+
A call speaks the gRPC protocol, with connectrpc, over the HTTP/2 connections
|
|
7
|
+
[encore.internal.clients.pyqwest_client] shares, and its messages are
|
|
8
|
+
protobuf-py's, which connectrpc encodes and decodes. The SDK takes the call
|
|
9
|
+
as connectrpc makes it, and only makes connectrpc's errors [CallError]s,
|
|
10
|
+
keeping each code:
|
|
11
|
+
|
|
12
|
+
- A call's timeout is connectrpc's: sent to the service in ``grpc-timeout``,
|
|
13
|
+
and applied to each read from the network, so the messages of a stream
|
|
14
|
+
that one read holds arrive even past it, and the next read fails with
|
|
15
|
+
``DEADLINE_EXCEEDED``.
|
|
16
|
+
- Cancelling the task that makes a call fails the call with ``CANCELED``,
|
|
17
|
+
which an ``except CallError`` catches as it catches any other code.
|
|
18
|
+
- An exception a client stream's requests raise fails the call with
|
|
19
|
+
``UNAVAILABLE``, the exception its cause.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import math
|
|
25
|
+
import sys
|
|
26
|
+
from collections.abc import AsyncIterable, AsyncIterator, Callable, Mapping
|
|
27
|
+
from typing import TYPE_CHECKING, Any, Optional, TypeVar
|
|
28
|
+
|
|
29
|
+
from connectrpc.client import ConnectClient
|
|
30
|
+
from connectrpc.errors import ConnectError
|
|
31
|
+
from connectrpc.protocol import ProtocolType
|
|
32
|
+
from protobuf.wkt import Any as AnyMessage
|
|
33
|
+
|
|
34
|
+
from ..errs import ErrCode
|
|
35
|
+
from ..services import CallError
|
|
36
|
+
from . import clients
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
import pyqwest
|
|
40
|
+
from connectrpc.errors import ErrorDetail
|
|
41
|
+
from connectrpc.method import MethodInfo
|
|
42
|
+
from protobuf import Message, Registry
|
|
43
|
+
|
|
44
|
+
if sys.version_info < (3, 11): # pragma: no cover
|
|
45
|
+
raise ImportError("Encore's generated gRPC clients need Python 3.11")
|
|
46
|
+
|
|
47
|
+
__all__ = ["Call", "connect_client"]
|
|
48
|
+
|
|
49
|
+
_T = TypeVar("_T")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def connect_client(
|
|
53
|
+
base_url: str, http_client: Optional[pyqwest.Client] = None
|
|
54
|
+
) -> ConnectClient:
|
|
55
|
+
"""Return a connectrpc client speaking gRPC to ``base_url``.
|
|
56
|
+
|
|
57
|
+
Over ``http_client``, or the HTTP/2 connections the SDK shares. Requests
|
|
58
|
+
are sent uncompressed, as grpc-go and tonic send them; answers may be
|
|
59
|
+
gzipped.
|
|
60
|
+
"""
|
|
61
|
+
return ConnectClient(
|
|
62
|
+
base_url,
|
|
63
|
+
protocol=ProtocolType.GRPC,
|
|
64
|
+
send_compression=None,
|
|
65
|
+
http_client=http_client
|
|
66
|
+
if http_client is not None
|
|
67
|
+
else clients.pyqwest_client(),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Call:
|
|
72
|
+
"""A call's settings: the client making it, its timeout and its headers."""
|
|
73
|
+
|
|
74
|
+
def __init__(
|
|
75
|
+
self,
|
|
76
|
+
connect: Callable[[], ConnectClient],
|
|
77
|
+
timeout: Optional[float],
|
|
78
|
+
headers: Mapping[str, str],
|
|
79
|
+
registry: Registry,
|
|
80
|
+
) -> None:
|
|
81
|
+
"""Make a call's settings.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
connect: Returns the client to call with, when the call starts:
|
|
85
|
+
it raises when the client is closed, or its service unknown.
|
|
86
|
+
timeout: How long the call may take, in seconds; ``None`` is no
|
|
87
|
+
limit. connectrpc takes it in milliseconds, here rounded up.
|
|
88
|
+
headers: The headers to send, with lowercase names.
|
|
89
|
+
registry: The types of the generated module's files, which
|
|
90
|
+
decode an error's details.
|
|
91
|
+
"""
|
|
92
|
+
self._connect = connect
|
|
93
|
+
self._timeout_ms = None if timeout is None else math.ceil(timeout * 1000)
|
|
94
|
+
self._headers = headers
|
|
95
|
+
self._registry = registry
|
|
96
|
+
|
|
97
|
+
async def unary(self, method: MethodInfo[Any, _T], request: Any) -> _T:
|
|
98
|
+
"""Call a unary method with ``request``."""
|
|
99
|
+
connect = self._connect()
|
|
100
|
+
try:
|
|
101
|
+
return await connect.execute_unary(
|
|
102
|
+
request=request,
|
|
103
|
+
method=method,
|
|
104
|
+
headers=self._headers,
|
|
105
|
+
timeout_ms=self._timeout_ms,
|
|
106
|
+
)
|
|
107
|
+
except ConnectError as error:
|
|
108
|
+
raise _call_error(error, self._registry) from _cause(error)
|
|
109
|
+
|
|
110
|
+
async def client_stream(
|
|
111
|
+
self, method: MethodInfo[Any, _T], requests: AsyncIterable[Any]
|
|
112
|
+
) -> _T:
|
|
113
|
+
"""Call a client stream method with ``requests``."""
|
|
114
|
+
connect = self._connect()
|
|
115
|
+
try:
|
|
116
|
+
return await connect.execute_client_stream(
|
|
117
|
+
request=requests.__aiter__(),
|
|
118
|
+
method=method,
|
|
119
|
+
headers=self._headers,
|
|
120
|
+
timeout_ms=self._timeout_ms,
|
|
121
|
+
)
|
|
122
|
+
except ConnectError as error:
|
|
123
|
+
raise _call_error(error, self._registry) from _cause(error)
|
|
124
|
+
|
|
125
|
+
async def server_stream(
|
|
126
|
+
self, method: MethodInfo[Any, _T], request: Any
|
|
127
|
+
) -> AsyncIterator[_T]:
|
|
128
|
+
"""Call a server stream method with ``request``."""
|
|
129
|
+
connect = self._connect()
|
|
130
|
+
stream = connect.execute_server_stream(
|
|
131
|
+
request=request,
|
|
132
|
+
method=method,
|
|
133
|
+
headers=self._headers,
|
|
134
|
+
timeout_ms=self._timeout_ms,
|
|
135
|
+
)
|
|
136
|
+
async for response in self._responses(stream):
|
|
137
|
+
yield response
|
|
138
|
+
|
|
139
|
+
async def bidi_stream(
|
|
140
|
+
self, method: MethodInfo[Any, _T], requests: AsyncIterable[Any]
|
|
141
|
+
) -> AsyncIterator[_T]:
|
|
142
|
+
"""Call a bidi stream method with ``requests``."""
|
|
143
|
+
connect = self._connect()
|
|
144
|
+
stream = connect.execute_bidi_stream(
|
|
145
|
+
request=requests.__aiter__(),
|
|
146
|
+
method=method,
|
|
147
|
+
headers=self._headers,
|
|
148
|
+
timeout_ms=self._timeout_ms,
|
|
149
|
+
)
|
|
150
|
+
async for response in self._responses(stream):
|
|
151
|
+
yield response
|
|
152
|
+
|
|
153
|
+
async def _responses(self, stream: AsyncIterator[_T]) -> AsyncIterator[_T]:
|
|
154
|
+
"""The messages of connectrpc's ``stream``, its errors made CallErrors."""
|
|
155
|
+
try:
|
|
156
|
+
while True:
|
|
157
|
+
try:
|
|
158
|
+
response = await stream.__anext__()
|
|
159
|
+
except StopAsyncIteration:
|
|
160
|
+
return
|
|
161
|
+
except ConnectError as error:
|
|
162
|
+
raise _call_error(error, self._registry) from _cause(error)
|
|
163
|
+
yield response
|
|
164
|
+
finally:
|
|
165
|
+
# Closed now, rather than when collected, if the caller stopped
|
|
166
|
+
# reading first: it ends the HTTP/2 stream.
|
|
167
|
+
aclose = getattr(stream, "aclose", None)
|
|
168
|
+
if aclose is not None:
|
|
169
|
+
await aclose()
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _cause(error: ConnectError) -> BaseException:
|
|
173
|
+
"""What ``error`` was raised for.
|
|
174
|
+
|
|
175
|
+
connectrpc raises an error it made of an exception (a connection's, the
|
|
176
|
+
task's cancellation, the requests') from that exception; one without a
|
|
177
|
+
cause is the service's answer.
|
|
178
|
+
"""
|
|
179
|
+
return error.__cause__ if error.__cause__ is not None else error
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _call_error(error: ConnectError, registry: Registry) -> CallError:
|
|
183
|
+
"""The error ``error``, which connectrpc raised, means."""
|
|
184
|
+
try:
|
|
185
|
+
code = ErrCode(error.code.value)
|
|
186
|
+
except ValueError:
|
|
187
|
+
code = ErrCode.UNKNOWN
|
|
188
|
+
# Made of an exception, the call got no answer, so no status.
|
|
189
|
+
status = 0 if error.__cause__ is not None else None
|
|
190
|
+
details = [_detail(detail, registry) for detail in error.details]
|
|
191
|
+
return CallError(code, error.message, status, details=details)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _detail(detail: ErrorDetail, registry: Registry) -> Message:
|
|
195
|
+
"""A status's detail: its message, or the ``Any`` it came as.
|
|
196
|
+
|
|
197
|
+
An ``Any``, as protobuf-py has it, for a type ``registry`` lacks, or bytes
|
|
198
|
+
that do not decode as their type.
|
|
199
|
+
"""
|
|
200
|
+
try:
|
|
201
|
+
message = detail.value(registry)
|
|
202
|
+
except Exception: # noqa: BLE001
|
|
203
|
+
message = None
|
|
204
|
+
if message is not None:
|
|
205
|
+
return message
|
|
206
|
+
name = detail.type_name
|
|
207
|
+
type_url = name if "/" in name else f"type.googleapis.com/{name}"
|
|
208
|
+
return AnyMessage(type_url=type_url, value=detail.message_bytes)
|
|
@@ -57,7 +57,8 @@ only its settings, so one made for a single call costs nothing to make. The
|
|
|
57
57
|
connections of an event loop are closed when the loop finishes, as
|
|
58
58
|
``asyncio.run`` and ``encore.run`` finish it. Clients for OpenAPI and GraphQL
|
|
59
59
|
APIs need httpx (``pip install 'encore-dev[httpx]'``), and those for gRPC APIs
|
|
60
|
-
connectrpc (``pip install 'encore-dev[grpc]'``)
|
|
60
|
+
connectrpc and protobuf-py (``pip install 'encore-dev[grpc]'``), whose messages
|
|
61
|
+
they take and return.
|
|
61
62
|
"""
|
|
62
63
|
|
|
63
64
|
from __future__ import annotations
|
|
@@ -129,16 +130,27 @@ class CallError(Exception):
|
|
|
129
130
|
with, in Encore's error body or as its gRPC status;
|
|
130
131
|
``UNAVAILABLE`` when no answer came; ``DEADLINE_EXCEEDED`` when
|
|
131
132
|
the call took longer than its timeout; else the one the answer's
|
|
132
|
-
HTTP status means, as ``NOT_FOUND`` for 404.
|
|
133
|
+
HTTP status means, as ``NOT_FOUND`` for 404. A gRPC call's is
|
|
134
|
+
connectrpc's, as it has it: ``CANCELED`` when the task making it
|
|
135
|
+
was cancelled, and ``UNAVAILABLE``, the exception its cause, when
|
|
136
|
+
the requests of a client stream raised.
|
|
133
137
|
message: What went wrong, as the service said, or as the client saw.
|
|
134
138
|
status: The HTTP status of the service's answer: the answer's own,
|
|
135
139
|
when it was an error status, else (a gRPC or GraphQL error) the
|
|
136
140
|
one Encore answers ``code`` with. 0 when the call got no answer,
|
|
137
141
|
or failed before it was sent.
|
|
142
|
+
details: What a gRPC status carried besides its message: each
|
|
143
|
+
detail its protobuf-py message, decoded with the types of the
|
|
144
|
+
client's protos, or the ``protobuf.wkt.Any`` it came as, for a
|
|
145
|
+
type they lack. Empty for other errors.
|
|
138
146
|
"""
|
|
139
147
|
|
|
140
148
|
def __init__(
|
|
141
|
-
self,
|
|
149
|
+
self,
|
|
150
|
+
code: ErrCode,
|
|
151
|
+
message: str,
|
|
152
|
+
status: Optional[int] = None,
|
|
153
|
+
details: Optional[list[Any]] = None,
|
|
142
154
|
) -> None:
|
|
143
155
|
"""Make an error with ``code`` and ``message``.
|
|
144
156
|
|
|
@@ -147,6 +159,7 @@ class CallError(Exception):
|
|
|
147
159
|
message: What went wrong.
|
|
148
160
|
status: The HTTP status the call failed with. Defaults to the one
|
|
149
161
|
Encore answers ``code`` with.
|
|
162
|
+
details: The status's details. Defaults to none.
|
|
150
163
|
"""
|
|
151
164
|
if not isinstance(code, ErrCode):
|
|
152
165
|
raise TypeError(f"code must be an ErrCode, not {type(code).__name__}")
|
|
@@ -154,6 +167,7 @@ class CallError(Exception):
|
|
|
154
167
|
self.code = code
|
|
155
168
|
self.message = message
|
|
156
169
|
self.status = code.http_status if status is None else status
|
|
170
|
+
self.details: list[Any] = details if details is not None else []
|
|
157
171
|
|
|
158
172
|
|
|
159
173
|
class GraphQLRequestError(CallError):
|