b24api 0.6.0__tar.gz → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: b24api
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Bitrix24 API
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -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
- for batched_requests in batched(requests, batch_size):
61
- if with_payload:
62
- batched_requests, batched_payloads = zip(*batched_requests, strict=True)
63
- else:
64
- batched_payloads = None
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
- batched_responses = await self.retry(self._batch, batched_requests)
71
+ async def _batch_common_body(
72
+ self,
73
+ requests: tuple[Request | dict | tuple[Request | dict, Any], ...],
74
+ list_method: bool = False,
75
+ with_payload: bool = False,
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
- for i, response in enumerate(batched_responses):
69
- result = response.list_result if list_method else response.result
70
- if with_payload:
71
- yield result, batched_payloads[i]
72
- else:
73
- yield result
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,
@@ -200,14 +200,14 @@ class BatchedNoCountHelper:
200
200
 
201
201
 
202
202
  class ReferenceNoCountHelper:
203
- def __init__(
203
+ def __init__( # noqa: PLR0913
204
204
  self,
205
205
  request: ListRequest | dict,
206
206
  updates: Iterable[dict | tuple[dict, Any]] | AsyncIterable[dict | tuple[dict, Any]],
207
207
  id_key: str,
208
208
  list_size: int,
209
209
  batch_size: int,
210
- with_payload: bool,
210
+ with_payload: bool, # noqa: FBT001
211
211
  ) -> None:
212
212
  request = ListRequest.model_validate(request)
213
213
 
@@ -278,12 +278,12 @@ class ReferenceNoCountHelper:
278
278
  body_results: list[ApiTypes | tuple[ApiTypes, Any]],
279
279
  ) -> tuple[ListRequest | tuple[ListRequest, Any], ...]:
280
280
  requests = []
281
- for body_request, body_result in zip(body_requests, body_results, strict=True):
281
+ for body_request_, body_result_ in zip(body_requests, body_results, strict=True):
282
282
  if self.with_payload:
283
- body_request, body_payload = body_request
284
- body_result, _ = body_result
283
+ body_request, body_payload = body_request_
284
+ body_result, _ = body_result_
285
285
  else:
286
- body_payload = None
286
+ body_request, body_result, body_payload = body_request_, body_result_, None
287
287
 
288
288
  id_from = f">{self.id_key}"
289
289
 
@@ -304,7 +304,6 @@ class ReferenceNoCountHelper:
304
304
  ) -> Generator[ApiTypes | tuple[ApiTypes, Any]]:
305
305
  if self.with_payload:
306
306
  for result, payload in results:
307
- result = zip(result, [payload] * len(result), strict=False)
308
- yield from result
307
+ yield from zip(result, [payload] * len(result), strict=False)
309
308
  else:
310
309
  yield from chain.from_iterable(results)
@@ -130,7 +130,7 @@ class BatchResult(BaseModel):
130
130
 
131
131
  @field_validator("result", "result_time", "result_error", "result_total", "result_next", mode="before")
132
132
  @classmethod
133
- def php_dict(cls, value: Any) -> Any:
133
+ def php_dict(cls, value: Any) -> Any: # noqa: ANN401
134
134
  if isinstance(value, list) and not value:
135
135
  return {}
136
136
  return value
@@ -56,11 +56,11 @@ class SyncBitrix24(BaseBitrix24):
56
56
  """Call unlimited sequence of methods within batches and return `result` from responses."""
57
57
  batch_size = batch_size or self.settings.batch_size
58
58
 
59
- for batched_requests in batched(requests, batch_size):
59
+ for batched_requests_ in batched(requests, batch_size):
60
60
  if with_payload:
61
- batched_requests, batched_payloads = zip(*batched_requests, strict=True)
61
+ batched_requests, batched_payloads = zip(*batched_requests_, strict=True)
62
62
  else:
63
- batched_payloads = None
63
+ batched_requests, batched_payloads = batched_requests_, None
64
64
 
65
65
  batched_responses = self.retry(self._batch, batched_requests)
66
66
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: b24api
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: Bitrix24 API
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
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