b24api 0.6.1__tar.gz → 0.7.1__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.
- {b24api-0.6.1/b24api.egg-info → b24api-0.7.1}/PKG-INFO +1 -1
- {b24api-0.6.1 → b24api-0.7.1}/b24api/async_api.py +29 -13
- {b24api-0.6.1 → b24api-0.7.1}/b24api/error.py +3 -3
- {b24api-0.6.1 → b24api-0.7.1/b24api.egg-info}/PKG-INFO +1 -1
- {b24api-0.6.1 → b24api-0.7.1}/LICENSE +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/MANIFEST.in +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/README.md +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api/__init__.py +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api/base_api.py +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api/entity.py +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api/query.py +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api/settings.py +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api/sync_api.py +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api/type.py +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api.egg-info/SOURCES.txt +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api.egg-info/dependency_links.txt +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api.egg-info/requires.txt +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/b24api.egg-info/top_level.txt +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/pyproject.toml +0 -0
- {b24api-0.6.1 → b24api-0.7.1}/setup.cfg +0 -0
|
@@ -2,6 +2,7 @@ from collections.abc import AsyncGenerator, AsyncIterable, Iterable
|
|
|
2
2
|
from itertools import batched, islice
|
|
3
3
|
from typing import Any
|
|
4
4
|
|
|
5
|
+
from aioitertools.itertools import batched as abatched
|
|
5
6
|
from aioitertools.itertools import chain as achain
|
|
6
7
|
from httpx import AsyncClient
|
|
7
8
|
from tenacity import AsyncRetrying
|
|
@@ -48,7 +49,8 @@ class AsyncBitrix24(BaseBitrix24):
|
|
|
48
49
|
|
|
49
50
|
async def batch(
|
|
50
51
|
self,
|
|
51
|
-
requests: Iterable[Request | dict | tuple[Request | dict, Any]]
|
|
52
|
+
requests: Iterable[Request | dict | tuple[Request | dict, Any]]
|
|
53
|
+
| AsyncIterable[Request | dict | tuple[Request | dict, Any]],
|
|
52
54
|
*,
|
|
53
55
|
batch_size: int | None = None,
|
|
54
56
|
list_method: bool = False,
|
|
@@ -57,20 +59,34 @@ class AsyncBitrix24(BaseBitrix24):
|
|
|
57
59
|
"""Call unlimited sequence of methods within batches and return `result` from responses."""
|
|
58
60
|
batch_size = batch_size or self.settings.batch_size
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
if isinstance(requests, AsyncIterable):
|
|
63
|
+
async for batched_requests_ in abatched(requests, batch_size):
|
|
64
|
+
async for item in self._batch_common_body(batched_requests_, list_method, with_payload):
|
|
65
|
+
yield item
|
|
66
|
+
else:
|
|
67
|
+
for batched_requests_ in batched(requests, batch_size):
|
|
68
|
+
async for item in self._batch_common_body(batched_requests_, list_method, with_payload):
|
|
69
|
+
yield item
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
async def _batch_common_body(
|
|
72
|
+
self,
|
|
73
|
+
requests: tuple[Request | dict | tuple[Request | dict, Any], ...],
|
|
74
|
+
list_method: bool = False, # noqa: FBT001, FBT002
|
|
75
|
+
with_payload: bool = False, # noqa: FBT001, FBT002
|
|
76
|
+
) -> AsyncGenerator[ApiTypes | tuple[ApiTypes, Any]]:
|
|
77
|
+
if with_payload:
|
|
78
|
+
batched_requests, batched_payloads = zip(*requests, strict=True)
|
|
79
|
+
else:
|
|
80
|
+
batched_requests, batched_payloads = requests, None
|
|
81
|
+
|
|
82
|
+
batched_responses = await self.retry(self._batch, batched_requests)
|
|
67
83
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
for i, response in enumerate(batched_responses):
|
|
85
|
+
result = response.list_result if list_method else response.result
|
|
86
|
+
if with_payload:
|
|
87
|
+
yield result, batched_payloads[i]
|
|
88
|
+
else:
|
|
89
|
+
yield result
|
|
74
90
|
|
|
75
91
|
async def list_sequential(
|
|
76
92
|
self,
|
|
@@ -10,11 +10,11 @@ class ApiResponseError(Exception):
|
|
|
10
10
|
|
|
11
11
|
def __init__(self, *, code: str, description: str | None, request: str) -> None:
|
|
12
12
|
if code and description:
|
|
13
|
-
message = f"API error [{code}]: {description} for
|
|
13
|
+
message = f"API error [{code}]: {description} for <Request {request}>"
|
|
14
14
|
elif code:
|
|
15
|
-
message = f"API error [{code}] for
|
|
15
|
+
message = f"API error [{code}] for <Request {request}>"
|
|
16
16
|
else:
|
|
17
|
-
message = f"API error: {description} for
|
|
17
|
+
message = f"API error: {description} for <Request {request}>"
|
|
18
18
|
super().__init__(message)
|
|
19
19
|
|
|
20
20
|
|
|
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
|