vercel-internal-core-bundle 0.2.1__tar.gz → 0.3.0__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.
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/PKG-INFO +3 -3
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/_vercel_hatch_build.py +1 -5
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/pyproject.toml +2 -2
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/byte_stream.py +12 -23
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/http/__init__.py +2 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/http/transport.py +45 -7
- vercel_internal_core_bundle-0.3.0/vercel/_internal/core/polyfills/__init__.py +5 -0
- vercel_internal_core_bundle-0.3.0/vercel/_internal/core/polyfills/_typing.py +8 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/session.py +63 -22
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/time.py +3 -3
- vercel_internal_core_bundle-0.3.0/vercel/_internal/core/version.py +1 -0
- vercel_internal_core_bundle-0.2.1/vercel/_internal/core/polyfills/__init__.py +0 -9
- vercel_internal_core_bundle-0.2.1/vercel/_internal/core/polyfills/_datetime.py +0 -5
- vercel_internal_core_bundle-0.2.1/vercel/_internal/core/polyfills/_strenum.py +0 -10
- vercel_internal_core_bundle-0.2.1/vercel/_internal/core/polyfills/_strenum_impl.py +0 -14
- vercel_internal_core_bundle-0.2.1/vercel/_internal/core/polyfills/_typing.py +0 -13
- vercel_internal_core_bundle-0.2.1/vercel/_internal/core/version.py +0 -1
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/LICENSE +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/README.md +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/hatch_build.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/__init__.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/_vendor/__init__.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/_vendor/vendor.txt +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/detect_agent.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/errors.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/http/_compat.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/http/config.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/http/httpx.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/http/retry.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/iter_coroutine.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/options.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/py.typed +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/typeutils.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/url.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/api/__init__.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/api/py.typed +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/errors/__init__.py +0 -0
- {vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/errors/py.typed +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: vercel-internal-core-bundle
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Shared internal runtime for Vercel Python packages
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
7
|
-
Requires-Python: >=3.
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
8
|
Requires-Dist: anyio<5,>=4.11.0
|
|
9
|
-
Requires-Dist: vercel-internal-shared-vendored-deps>=0.1.
|
|
9
|
+
Requires-Dist: vercel-internal-shared-vendored-deps>=0.1.5
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
11
|
|
|
12
12
|
# vercel-internal-core-bundle
|
{vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/_vercel_hatch_build.py
RENAMED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import ast
|
|
6
|
+
import tomllib
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
from typing import Any
|
|
8
9
|
|
|
@@ -10,11 +11,6 @@ from hatchling.metadata.plugin.interface import MetadataHookInterface
|
|
|
10
11
|
from packaging.requirements import Requirement
|
|
11
12
|
from packaging.specifiers import SpecifierSet
|
|
12
13
|
|
|
13
|
-
try:
|
|
14
|
-
import tomllib
|
|
15
|
-
except ModuleNotFoundError: # pragma: no cover - Python < 3.11
|
|
16
|
-
import tomli as tomllib # type: ignore[no-redef]
|
|
17
|
-
|
|
18
14
|
|
|
19
15
|
class WorkspaceDependenciesMetadataHook(MetadataHookInterface):
|
|
20
16
|
"""Generate package dependencies from the repo-owned dependency table."""
|
|
@@ -7,7 +7,7 @@ name = "vercel-internal-core-bundle"
|
|
|
7
7
|
dynamic = ["version", "dependencies"]
|
|
8
8
|
description = "Shared internal runtime for Vercel Python packages"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
11
|
license = "MIT"
|
|
12
12
|
license-files = [
|
|
13
13
|
"LICENSE",
|
|
@@ -21,7 +21,7 @@ path = "hatch_build.py"
|
|
|
21
21
|
[tool.vercel.release.dependencies]
|
|
22
22
|
dependencies = [
|
|
23
23
|
"anyio>=4.11.0,<5",
|
|
24
|
-
"vercel-internal-shared-vendored-deps>=0.1.
|
|
24
|
+
"vercel-internal-shared-vendored-deps>=0.1.5",
|
|
25
25
|
]
|
|
26
26
|
|
|
27
27
|
[tool.hatch.version]
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Shared code consumes the async-shaped ``ReadableByteStream`` and
|
|
4
4
|
``StagingByteFile`` protocols. Callers select the runtime matching their public
|
|
5
5
|
API, then use its factories instead of constructing the private adapters directly.
|
|
6
|
-
The sync runtime
|
|
7
|
-
|
|
6
|
+
The sync runtime accepts buffers and blocking readers and never suspends. The async
|
|
7
|
+
runtime accepts buffers and async readers only; callers adapt blocking readers
|
|
8
|
+
before passing them to async code.
|
|
8
9
|
"""
|
|
9
10
|
|
|
10
11
|
import inspect
|
|
@@ -37,15 +38,14 @@ class AsyncByteReader(Protocol):
|
|
|
37
38
|
|
|
38
39
|
BytesLike: TypeAlias = bytes | bytearray | memoryview
|
|
39
40
|
SyncByteSource: TypeAlias = BytesLike | SyncByteReader
|
|
40
|
-
AsyncByteSource: TypeAlias = AsyncByteReader
|
|
41
|
-
RawByteSource: TypeAlias = SyncByteSource | AsyncByteSource
|
|
41
|
+
AsyncByteSource: TypeAlias = BytesLike | AsyncByteReader
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
class ReadableByteStream(Protocol):
|
|
45
45
|
"""Normalized readable stream consumed by shared internal workflows.
|
|
46
46
|
|
|
47
|
-
Its async shape hides whether a runtime performs the read inline
|
|
48
|
-
async source
|
|
47
|
+
Its async shape hides whether a runtime performs the read inline or awaits an
|
|
48
|
+
async source.
|
|
49
49
|
"""
|
|
50
50
|
|
|
51
51
|
async def read(self, size: int = -1, /) -> bytes: ...
|
|
@@ -126,16 +126,6 @@ class _AsyncReader:
|
|
|
126
126
|
return _bytes_result(await self._source.read(size))
|
|
127
127
|
|
|
128
128
|
|
|
129
|
-
class _ThreadedSyncReader:
|
|
130
|
-
"""Run a blocking reader on a worker thread for use by async workflows."""
|
|
131
|
-
|
|
132
|
-
def __init__(self, source: SyncByteReader) -> None:
|
|
133
|
-
self._source = source
|
|
134
|
-
|
|
135
|
-
async def read(self, size: int = -1, /) -> bytes:
|
|
136
|
-
return _bytes_result(await anyio.to_thread.run_sync(self._source.read, size))
|
|
137
|
-
|
|
138
|
-
|
|
139
129
|
class _SyncTemporaryFile:
|
|
140
130
|
"""Expose a blocking temporary file through non-suspending async methods."""
|
|
141
131
|
|
|
@@ -217,20 +207,20 @@ class SyncByteStreamRuntime:
|
|
|
217
207
|
class AsyncByteStreamRuntime:
|
|
218
208
|
"""Adapt byte primitives for execution under AnyIO.
|
|
219
209
|
|
|
220
|
-
Async readers are awaited directly
|
|
221
|
-
|
|
210
|
+
Async readers are awaited directly. Blocking readers are rejected rather than
|
|
211
|
+
moved to worker threads.
|
|
222
212
|
"""
|
|
223
213
|
|
|
224
214
|
@staticmethod
|
|
225
|
-
def reader(source:
|
|
215
|
+
def reader(source: AsyncByteSource) -> ReadableByteStream:
|
|
226
216
|
if isinstance(source, (bytes, bytearray, memoryview)):
|
|
227
217
|
return _MemoryReader(source)
|
|
228
218
|
read = getattr(source, "read", None)
|
|
229
219
|
if not callable(read):
|
|
230
220
|
raise TypeError("byte source must provide a callable read method")
|
|
231
|
-
if inspect.iscoroutinefunction(read):
|
|
232
|
-
|
|
233
|
-
return
|
|
221
|
+
if not inspect.iscoroutinefunction(read):
|
|
222
|
+
raise TypeError("async byte stream runtime does not support sync readers")
|
|
223
|
+
return _AsyncReader(source)
|
|
234
224
|
|
|
235
225
|
def temporary_file(self) -> AbstractAsyncContextManager[StagingByteFile]:
|
|
236
226
|
return cast(
|
|
@@ -244,7 +234,6 @@ __all__ = [
|
|
|
244
234
|
"AsyncByteSource",
|
|
245
235
|
"AsyncByteStreamRuntime",
|
|
246
236
|
"BytesLike",
|
|
247
|
-
"RawByteSource",
|
|
248
237
|
"ReadableByteStream",
|
|
249
238
|
"StagingByteFile",
|
|
250
239
|
"StagingFileRuntime",
|
|
@@ -10,6 +10,7 @@ from vercel._internal.core.http.retry import (
|
|
|
10
10
|
SleepFn,
|
|
11
11
|
)
|
|
12
12
|
from vercel._internal.core.http.transport import (
|
|
13
|
+
NO_READ_TIMEOUT,
|
|
13
14
|
NO_TIMEOUT,
|
|
14
15
|
AsyncTransport,
|
|
15
16
|
BaseTransport,
|
|
@@ -36,6 +37,7 @@ __all__ = [
|
|
|
36
37
|
"JSONBody",
|
|
37
38
|
"BytesBody",
|
|
38
39
|
"NO_TIMEOUT",
|
|
40
|
+
"NO_READ_TIMEOUT",
|
|
39
41
|
"RawBody",
|
|
40
42
|
"ReadResponsePolicy",
|
|
41
43
|
"RequestBody",
|
|
@@ -10,6 +10,7 @@ from collections.abc import AsyncIterator, Callable, Iterator, Mapping, Sequence
|
|
|
10
10
|
from contextlib import AbstractAsyncContextManager, asynccontextmanager
|
|
11
11
|
from dataclasses import dataclass
|
|
12
12
|
from datetime import timedelta
|
|
13
|
+
from enum import StrEnum
|
|
13
14
|
from types import TracebackType
|
|
14
15
|
from typing import Any, Final, TypeAlias, cast, final
|
|
15
16
|
|
|
@@ -18,7 +19,6 @@ import vercel.internal._vendor.httpx2 as httpx
|
|
|
18
19
|
from anyio.abc import ObjectReceiveStream, ObjectSendStream
|
|
19
20
|
|
|
20
21
|
from vercel._internal.core.http._compat import is_async_http_client
|
|
21
|
-
from vercel._internal.core.polyfills import StrEnum
|
|
22
22
|
from vercel._internal.core.time import to_seconds_float
|
|
23
23
|
|
|
24
24
|
PrimitiveData: TypeAlias = str | int | float | bool | None
|
|
@@ -72,7 +72,17 @@ class _NoTimeout:
|
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
NO_TIMEOUT: Final = _NoTimeout()
|
|
75
|
-
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@final
|
|
78
|
+
class _NoReadTimeout:
|
|
79
|
+
"""Disable read timeouts while retaining the client's other limits."""
|
|
80
|
+
|
|
81
|
+
__slots__ = ()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
NO_READ_TIMEOUT: Final = _NoReadTimeout()
|
|
85
|
+
RequestTimeout: TypeAlias = timedelta | _NoTimeout | _NoReadTimeout | None
|
|
76
86
|
|
|
77
87
|
|
|
78
88
|
class ReadResponsePolicy(StrEnum):
|
|
@@ -167,6 +177,18 @@ class BaseTransport(abc.ABC):
|
|
|
167
177
|
case RawBody():
|
|
168
178
|
content = body.data
|
|
169
179
|
|
|
180
|
+
if timeout is NO_READ_TIMEOUT:
|
|
181
|
+
request = client.build_request(
|
|
182
|
+
method,
|
|
183
|
+
_normalize_path(path),
|
|
184
|
+
params=params,
|
|
185
|
+
headers=headers,
|
|
186
|
+
json=json,
|
|
187
|
+
content=content,
|
|
188
|
+
)
|
|
189
|
+
request.extensions["timeout"] = {**request.extensions["timeout"], "read": None}
|
|
190
|
+
return request
|
|
191
|
+
|
|
170
192
|
if timeout is NO_TIMEOUT:
|
|
171
193
|
return client.build_request(
|
|
172
194
|
method,
|
|
@@ -367,15 +389,22 @@ class _SyncStreamingRequest(StreamingRequest):
|
|
|
367
389
|
if self._closed:
|
|
368
390
|
raise anyio.ClosedResourceError
|
|
369
391
|
self._closed = True
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
392
|
+
early_error: BaseException | None = None
|
|
393
|
+
if not self._finished.is_set() or self._response is None:
|
|
394
|
+
try:
|
|
395
|
+
self._put(_STREAM_EOF)
|
|
396
|
+
except anyio.BrokenResourceError as exc:
|
|
397
|
+
early_error = exc
|
|
398
|
+
else:
|
|
399
|
+
early_error = anyio.BrokenResourceError()
|
|
375
400
|
self._thread.join()
|
|
376
401
|
self._raise_worker_error()
|
|
377
402
|
if self._response is None:
|
|
403
|
+
if early_error is not None:
|
|
404
|
+
raise early_error
|
|
378
405
|
raise anyio.BrokenResourceError
|
|
406
|
+
if early_error is not None and self._response.is_success:
|
|
407
|
+
raise anyio.BrokenResourceError from early_error
|
|
379
408
|
self._completed = True
|
|
380
409
|
return _SyncStreamingResponse(self._response, self._chunk_size)
|
|
381
410
|
|
|
@@ -540,16 +569,25 @@ class _AsyncStreamingRequest(StreamingRequest):
|
|
|
540
569
|
if self._closed:
|
|
541
570
|
raise anyio.ClosedResourceError
|
|
542
571
|
self._closed = True
|
|
572
|
+
early_error: BaseException | None = None
|
|
573
|
+
if self._done.is_set() and self._response is not None:
|
|
574
|
+
early_error = anyio.BrokenResourceError()
|
|
543
575
|
try:
|
|
544
576
|
await self._send.aclose()
|
|
545
577
|
await self._done.wait()
|
|
578
|
+
except anyio.BrokenResourceError as exc:
|
|
579
|
+
early_error = exc
|
|
546
580
|
except BaseException:
|
|
547
581
|
with anyio.CancelScope(shield=True):
|
|
548
582
|
await self.abort()
|
|
549
583
|
raise
|
|
550
584
|
self._raise_worker_error()
|
|
551
585
|
if self._response is None:
|
|
586
|
+
if early_error is not None:
|
|
587
|
+
raise early_error
|
|
552
588
|
raise anyio.BrokenResourceError
|
|
589
|
+
if early_error is not None and self._response.is_success:
|
|
590
|
+
raise anyio.BrokenResourceError from early_error
|
|
553
591
|
self._completed = True
|
|
554
592
|
return _AsyncStreamingResponse(self._response, self._chunk_size)
|
|
555
593
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"""Mode-specific sessions shared by Vercel Python services."""
|
|
2
2
|
|
|
3
|
-
import asyncio
|
|
4
3
|
import threading
|
|
5
4
|
import time
|
|
6
5
|
from collections.abc import Callable, Mapping, Sequence
|
|
7
6
|
from contextvars import ContextVar, Token
|
|
8
7
|
from types import TracebackType
|
|
9
|
-
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, cast, overload
|
|
8
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Self, TypeVar, cast, overload
|
|
10
9
|
|
|
11
10
|
import anyio
|
|
11
|
+
import anyio.lowlevel
|
|
12
12
|
import vercel.internal._vendor.httpx2 as httpx
|
|
13
13
|
|
|
14
14
|
from vercel._internal.core.errors import (
|
|
@@ -21,7 +21,6 @@ from vercel._internal.core.http._compat import (
|
|
|
21
21
|
is_sync_http_client,
|
|
22
22
|
)
|
|
23
23
|
from vercel._internal.core.options import ServiceOptions, merge_service_options
|
|
24
|
-
from vercel._internal.core.polyfills import Self
|
|
25
24
|
|
|
26
25
|
if TYPE_CHECKING:
|
|
27
26
|
from vercel._internal.core.byte_stream import (
|
|
@@ -37,6 +36,45 @@ HttpxClientFactory = Callable[[], httpx.AsyncClient] | Callable[[], httpx.Client
|
|
|
37
36
|
_UNSET = object()
|
|
38
37
|
|
|
39
38
|
|
|
39
|
+
def _current_event_loop() -> object | None:
|
|
40
|
+
"""Return the native AnyIO token of the running event loop, or `None` outside one.
|
|
41
|
+
|
|
42
|
+
The token is the loop itself on asyncio and the run's `TrioToken` on Trio. It
|
|
43
|
+
stays the same object for the whole run, so it can key per-loop state.
|
|
44
|
+
"""
|
|
45
|
+
try:
|
|
46
|
+
return anyio.lowlevel.current_token().native_token
|
|
47
|
+
except RuntimeError:
|
|
48
|
+
# Outside an event loop AnyIO raises `NoEventLoopError`, or sniffio's
|
|
49
|
+
# `AsyncLibraryNotFoundError` on older releases; both are `RuntimeError`s.
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _ignore() -> None:
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _event_loop_has_finished(token: object) -> bool:
|
|
58
|
+
"""Tell whether the event loop behind a native AnyIO token can no longer run.
|
|
59
|
+
|
|
60
|
+
AnyIO does not expose this, so each backend's own token is asked directly.
|
|
61
|
+
"""
|
|
62
|
+
is_closed = getattr(token, "is_closed", None)
|
|
63
|
+
if callable(is_closed):
|
|
64
|
+
# asyncio: the token is the event loop.
|
|
65
|
+
return bool(is_closed())
|
|
66
|
+
run_sync_soon = getattr(token, "run_sync_soon", None)
|
|
67
|
+
if callable(run_sync_soon):
|
|
68
|
+
# Trio: a token whose run has ended raises `RunFinishedError`, a
|
|
69
|
+
# `RuntimeError`, instead of queueing the callback. For a live run the
|
|
70
|
+
# no-op is deduplicated and is harmless.
|
|
71
|
+
try:
|
|
72
|
+
run_sync_soon(_ignore, idempotent=True)
|
|
73
|
+
except RuntimeError:
|
|
74
|
+
return True
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
|
|
40
78
|
class _BaseSdkSession:
|
|
41
79
|
"""Common scoped state shared by one runtime-mode session."""
|
|
42
80
|
|
|
@@ -116,9 +154,10 @@ class SdkSession(_BaseSdkSession):
|
|
|
116
154
|
)
|
|
117
155
|
self._transport: AsyncTransport | None = None
|
|
118
156
|
self._staging_file_runtime: AsyncByteStreamRuntime | None = None
|
|
119
|
-
# Keyed by loop, with `None` for a client
|
|
120
|
-
# session is process-wide, so it outlives
|
|
121
|
-
|
|
157
|
+
# Keyed by the event loop's native AnyIO token, with `None` for a client
|
|
158
|
+
# built outside one. The default session is process-wide, so it outlives
|
|
159
|
+
# any loop its sockets belong to.
|
|
160
|
+
self._clients: dict[object | None, httpx.AsyncClient] = {}
|
|
122
161
|
# One session can be reached from threads running loops of their own.
|
|
123
162
|
self._clients_lock = threading.Lock()
|
|
124
163
|
|
|
@@ -150,13 +189,6 @@ class SdkSession(_BaseSdkSession):
|
|
|
150
189
|
),
|
|
151
190
|
)
|
|
152
191
|
|
|
153
|
-
@staticmethod
|
|
154
|
-
def _running_loop() -> "asyncio.AbstractEventLoop | None":
|
|
155
|
-
try:
|
|
156
|
-
return asyncio.get_running_loop()
|
|
157
|
-
except RuntimeError:
|
|
158
|
-
return None
|
|
159
|
-
|
|
160
192
|
def _client_for_running_loop(self) -> httpx.AsyncClient:
|
|
161
193
|
"""Return the client owned by the loop making this request.
|
|
162
194
|
|
|
@@ -166,7 +198,7 @@ class SdkSession(_BaseSdkSession):
|
|
|
166
198
|
closed`. The caller sees an error for work the server already did, so the
|
|
167
199
|
client is chosen per loop up front rather than repaired afterwards.
|
|
168
200
|
"""
|
|
169
|
-
loop =
|
|
201
|
+
loop = _current_event_loop()
|
|
170
202
|
with self._clients_lock:
|
|
171
203
|
# Under the lock, so a request holding this transport cannot build a
|
|
172
204
|
# client that outlives the session it belongs to.
|
|
@@ -175,7 +207,9 @@ class SdkSession(_BaseSdkSession):
|
|
|
175
207
|
if client is not None:
|
|
176
208
|
return client
|
|
177
209
|
for known in [
|
|
178
|
-
known
|
|
210
|
+
known
|
|
211
|
+
for known in self._clients
|
|
212
|
+
if known is not None and _event_loop_has_finished(known)
|
|
179
213
|
]:
|
|
180
214
|
# Dropped, not closed: `aclose` needs the loop that owns the
|
|
181
215
|
# sockets, and that loop is gone.
|
|
@@ -239,7 +273,7 @@ class SdkSession(_BaseSdkSession):
|
|
|
239
273
|
return
|
|
240
274
|
self._clear_services()
|
|
241
275
|
self._transport = None
|
|
242
|
-
loop =
|
|
276
|
+
loop = _current_event_loop()
|
|
243
277
|
with self._clients_lock:
|
|
244
278
|
# Closing and the flag that stops new clients have to be one step, or
|
|
245
279
|
# a resolver already past the check registers a client nothing closes.
|
|
@@ -300,15 +334,22 @@ class SyncSdkSession(_BaseSdkSession):
|
|
|
300
334
|
)
|
|
301
335
|
|
|
302
336
|
def _close_wrong_async_client(self, client: Any) -> None:
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
337
|
+
"""Close, best effort, an async client a factory returned to this sync session.
|
|
338
|
+
|
|
339
|
+
The client was just built and has sent nothing, so no event loop owns its
|
|
340
|
+
resources and any loop can close it. A fresh one runs in a worker thread,
|
|
341
|
+
because this sync path may itself be called from inside a running loop.
|
|
342
|
+
"""
|
|
343
|
+
|
|
344
|
+
def close() -> None:
|
|
306
345
|
try:
|
|
307
|
-
|
|
346
|
+
anyio.run(client.aclose)
|
|
308
347
|
except Exception:
|
|
309
348
|
pass
|
|
310
|
-
|
|
311
|
-
|
|
349
|
+
|
|
350
|
+
worker = threading.Thread(target=close, name="vercel-close-async-client", daemon=True)
|
|
351
|
+
worker.start()
|
|
352
|
+
worker.join()
|
|
312
353
|
|
|
313
354
|
def get_transport(self) -> "SyncTransport":
|
|
314
355
|
from vercel._internal.core.http import (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from datetime import datetime, timedelta
|
|
3
|
+
from datetime import UTC, datetime, timedelta
|
|
4
4
|
|
|
5
5
|
MILLISECOND = timedelta(milliseconds=1)
|
|
6
6
|
SECOND = timedelta(seconds=1)
|
|
@@ -51,12 +51,12 @@ def to_seconds_float(td: timedelta) -> float:
|
|
|
51
51
|
|
|
52
52
|
def from_epoch_ms(value: int | float) -> datetime:
|
|
53
53
|
"""Read a millisecond epoch timestamp as an aware UTC datetime."""
|
|
54
|
-
return datetime.fromtimestamp(value / 1000, tz=
|
|
54
|
+
return datetime.fromtimestamp(value / 1000, tz=UTC)
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
def from_epoch_seconds(value: int | float) -> datetime:
|
|
58
58
|
"""Read a second epoch timestamp as an aware UTC datetime."""
|
|
59
|
-
return datetime.fromtimestamp(value, tz=
|
|
59
|
+
return datetime.fromtimestamp(value, tz=UTC)
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
def parse_epoch_seconds(value: object) -> datetime | None:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import enum as _enum
|
|
2
|
-
from typing import Any
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class StrEnum(str, _enum.Enum):
|
|
6
|
-
__str__ = str.__str__
|
|
7
|
-
__format__ = str.__format__ # type: ignore[assignment]
|
|
8
|
-
|
|
9
|
-
@staticmethod
|
|
10
|
-
def _generate_next_value_(name: str, start: int, count: int, last_values: list[Any]) -> str:
|
|
11
|
-
return name.lower()
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
__all__ = ("StrEnum",)
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
|
|
3
|
-
if sys.version_info >= (3, 12):
|
|
4
|
-
from collections.abc import Buffer
|
|
5
|
-
else:
|
|
6
|
-
from vercel.internal._vendor.typing_extensions import Buffer
|
|
7
|
-
|
|
8
|
-
if sys.version_info >= (3, 11):
|
|
9
|
-
from typing import Self
|
|
10
|
-
else:
|
|
11
|
-
from vercel.internal._vendor.typing_extensions import Self
|
|
12
|
-
|
|
13
|
-
__all__ = ("Buffer", "Self")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/_internal/core/url.py
RENAMED
|
File without changes
|
{vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/api/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/errors/__init__.py
RENAMED
|
File without changes
|
{vercel_internal_core_bundle-0.2.1 → vercel_internal_core_bundle-0.3.0}/vercel/errors/py.typed
RENAMED
|
File without changes
|