|
4 | 4 | from e2b.api.client.api.sandboxes import get_v2_sandboxes |
5 | 5 | from e2b.api.client.types import UNSET |
6 | 6 | from e2b.exceptions import SandboxException |
7 | | -from e2b.sandbox.main import SandboxBase |
8 | 7 | from e2b.sandbox.sandbox_api import SandboxPaginatorBase, SandboxInfo |
9 | | -from e2b.api import AsyncApiClient, handle_api_exception |
| 8 | +from e2b.api import handle_api_exception |
10 | 9 | from e2b.api.client.models.error import Error |
| 10 | +from e2b.api.client_async import get_api_client |
11 | 11 |
|
12 | 12 |
|
13 | 13 | class AsyncSandboxPaginator(SandboxPaginatorBase): |
@@ -44,29 +44,26 @@ async def next_items(self) -> List[SandboxInfo]: |
44 | 44 | } |
45 | 45 | metadata = urllib.parse.urlencode(quoted_metadata) |
46 | 46 |
|
47 | | - async with AsyncApiClient( |
48 | | - self._config, |
49 | | - limits=SandboxBase._limits, |
50 | | - ) as api_client: |
51 | | - res = await get_v2_sandboxes.asyncio_detailed( |
52 | | - client=api_client, |
53 | | - metadata=metadata if metadata else UNSET, |
54 | | - state=self.query.state if self.query and self.query.state else UNSET, |
55 | | - limit=self.limit if self.limit else UNSET, |
56 | | - next_token=self._next_token if self._next_token else UNSET, |
57 | | - ) |
| 47 | + api_client = get_api_client(self._config) |
| 48 | + res = await get_v2_sandboxes.asyncio_detailed( |
| 49 | + client=api_client, |
| 50 | + metadata=metadata if metadata else UNSET, |
| 51 | + state=self.query.state if self.query and self.query.state else UNSET, |
| 52 | + limit=self.limit if self.limit else UNSET, |
| 53 | + next_token=self._next_token if self._next_token else UNSET, |
| 54 | + ) |
58 | 55 |
|
59 | | - if res.status_code >= 300: |
60 | | - raise handle_api_exception(res) |
| 56 | + if res.status_code >= 300: |
| 57 | + raise handle_api_exception(res) |
61 | 58 |
|
62 | | - self._next_token = res.headers.get("x-next-token") |
63 | | - self._has_next = bool(self._next_token) |
| 59 | + self._next_token = res.headers.get("x-next-token") |
| 60 | + self._has_next = bool(self._next_token) |
64 | 61 |
|
65 | | - if res.parsed is None: |
66 | | - return [] |
| 62 | + if res.parsed is None: |
| 63 | + return [] |
67 | 64 |
|
68 | | - # Check if res.parse is Error |
69 | | - if isinstance(res.parsed, Error): |
70 | | - raise SandboxException(f"{res.parsed.message}: Request failed") |
| 65 | + # Check if res.parse is Error |
| 66 | + if isinstance(res.parsed, Error): |
| 67 | + raise SandboxException(f"{res.parsed.message}: Request failed") |
71 | 68 |
|
72 | | - return [SandboxInfo._from_listed_sandbox(sandbox) for sandbox in res.parsed] |
| 69 | + return [SandboxInfo._from_listed_sandbox(sandbox) for sandbox in res.parsed] |
0 commit comments