b24api 0.3.10__tar.gz → 0.4.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.
- {b24api-0.3.10/b24api.egg-info → b24api-0.4.0}/PKG-INFO +1 -1
- {b24api-0.3.10 → b24api-0.4.0}/b24api/api.py +51 -14
- {b24api-0.3.10 → b24api-0.4.0/b24api.egg-info}/PKG-INFO +1 -1
- {b24api-0.3.10 → b24api-0.4.0}/LICENSE +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/MANIFEST.in +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/README.md +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api/__init__.py +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api/entity.py +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api/error.py +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api/query.py +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api/settings.py +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api/type.py +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api.egg-info/SOURCES.txt +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api.egg-info/dependency_links.txt +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api.egg-info/requires.txt +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/b24api.egg-info/top_level.txt +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/pyproject.toml +0 -0
- {b24api-0.3.10 → b24api-0.4.0}/setup.cfg +0 -0
|
@@ -3,6 +3,7 @@ import logging
|
|
|
3
3
|
from collections.abc import Generator, Iterable
|
|
4
4
|
from itertools import chain, islice
|
|
5
5
|
from operator import itemgetter
|
|
6
|
+
from typing import Any
|
|
6
7
|
|
|
7
8
|
import h2.exceptions
|
|
8
9
|
import httpx
|
|
@@ -78,16 +79,26 @@ class Bitrix24:
|
|
|
78
79
|
|
|
79
80
|
def batch(
|
|
80
81
|
self,
|
|
81
|
-
requests: Iterable[Request | dict],
|
|
82
|
+
requests: Iterable[Request | dict | tuple[Request | dict, Any]],
|
|
83
|
+
*,
|
|
82
84
|
batch_size: int | None = None,
|
|
83
|
-
|
|
85
|
+
with_payload: bool = False,
|
|
86
|
+
) -> Generator[ApiTypes | tuple[ApiTypes, Any]]:
|
|
84
87
|
"""Call unlimited sequence of methods within batches and return `result` from responses."""
|
|
85
88
|
batch_size = batch_size or self.settings.batch_size
|
|
86
89
|
|
|
87
90
|
tail_requests = iter(requests)
|
|
88
91
|
while batched_requests := list(islice(tail_requests, batch_size)):
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
if with_payload:
|
|
93
|
+
batched_requests, batched_payloads = zip(*batched_requests, strict=True)
|
|
94
|
+
else:
|
|
95
|
+
batched_payloads = None
|
|
96
|
+
|
|
97
|
+
for i, response in enumerate(self.retry(self._batch, batched_requests)):
|
|
98
|
+
if with_payload:
|
|
99
|
+
yield response.result, batched_payloads[i]
|
|
100
|
+
else:
|
|
101
|
+
yield response.result
|
|
91
102
|
|
|
92
103
|
def _batch(self, requests: Iterable[Request | dict]) -> list[Response]:
|
|
93
104
|
"""Call limited batch of methods and return full responses."""
|
|
@@ -134,6 +145,7 @@ class Bitrix24:
|
|
|
134
145
|
def list_sequential(
|
|
135
146
|
self,
|
|
136
147
|
request: Request | dict,
|
|
148
|
+
*,
|
|
137
149
|
list_size: int | None = None,
|
|
138
150
|
) -> Generator[ApiTypes]:
|
|
139
151
|
"""Call `list` method and return full `result`.
|
|
@@ -167,6 +179,7 @@ class Bitrix24:
|
|
|
167
179
|
def list_batched(
|
|
168
180
|
self,
|
|
169
181
|
request: Request | dict,
|
|
182
|
+
*,
|
|
170
183
|
list_size: int | None = None,
|
|
171
184
|
batch_size: int | None = None,
|
|
172
185
|
) -> Generator[ApiTypes]:
|
|
@@ -194,7 +207,7 @@ class Bitrix24:
|
|
|
194
207
|
tail_request.parameters["start"] = start
|
|
195
208
|
yield tail_request
|
|
196
209
|
|
|
197
|
-
tail_responses = self.batch(_tail_requests(), batch_size)
|
|
210
|
+
tail_responses = self.batch(_tail_requests(), batch_size=batch_size)
|
|
198
211
|
tail_responses = map(self._fix_list_result, tail_responses)
|
|
199
212
|
tail_responses = chain.from_iterable(tail_responses)
|
|
200
213
|
yield from tail_responses
|
|
@@ -202,6 +215,7 @@ class Bitrix24:
|
|
|
202
215
|
def list_batched_no_count(
|
|
203
216
|
self,
|
|
204
217
|
request: ListRequest | dict,
|
|
218
|
+
*,
|
|
205
219
|
id_key: str = "ID",
|
|
206
220
|
list_size: int | None = None,
|
|
207
221
|
batch_size: int | None = None,
|
|
@@ -238,7 +252,7 @@ class Bitrix24:
|
|
|
238
252
|
tail_request.parameters.start = -1
|
|
239
253
|
tail_request.parameters.order = {"ID": "DESC"}
|
|
240
254
|
|
|
241
|
-
head_tail_result = self.batch([head_request, tail_request])
|
|
255
|
+
head_tail_result = self.batch([head_request, tail_request], batch_size=batch_size)
|
|
242
256
|
head_result, tail_result = tuple(map(self._fix_list_result, head_tail_result))
|
|
243
257
|
yield from head_result
|
|
244
258
|
|
|
@@ -253,7 +267,7 @@ class Bitrix24:
|
|
|
253
267
|
yield body_request
|
|
254
268
|
|
|
255
269
|
if max_head_id and min_tail_id and max_head_id < min_tail_id:
|
|
256
|
-
body = self.batch(_body_requests(), batch_size)
|
|
270
|
+
body = self.batch(_body_requests(), batch_size=batch_size)
|
|
257
271
|
body = map(self._fix_list_result, body)
|
|
258
272
|
body = chain.from_iterable(body)
|
|
259
273
|
yield from body
|
|
@@ -265,11 +279,13 @@ class Bitrix24:
|
|
|
265
279
|
def reference_batched_no_count(
|
|
266
280
|
self,
|
|
267
281
|
request: ListRequest | dict,
|
|
268
|
-
updates: Iterable[dict],
|
|
282
|
+
updates: Iterable[dict | tuple[dict, Any]],
|
|
283
|
+
*,
|
|
269
284
|
id_key: str = "ID",
|
|
270
285
|
list_size: int | None = None,
|
|
271
286
|
batch_size: int | None = None,
|
|
272
|
-
|
|
287
|
+
with_payload: bool = False,
|
|
288
|
+
) -> Generator[ApiTypes | tuple[ApiTypes, Any]]:
|
|
273
289
|
"""Call `list` method with reference `updates` for `filter` and return full `result`.
|
|
274
290
|
|
|
275
291
|
Fastest (batched, no count) list gathering for methods with `filter` parameter and required `reference`
|
|
@@ -295,8 +311,13 @@ class Bitrix24:
|
|
|
295
311
|
if request.parameters.order:
|
|
296
312
|
raise ValueError("Ordering parameters are reserved `order`in `reference_batched_no_count`")
|
|
297
313
|
|
|
298
|
-
def _tail_requests() -> Generator[ListRequest]:
|
|
314
|
+
def _tail_requests() -> Generator[ListRequest | tuple[ListRequest, Any]]:
|
|
299
315
|
for update in updates:
|
|
316
|
+
if with_payload:
|
|
317
|
+
update, payload = update
|
|
318
|
+
else:
|
|
319
|
+
payload = None
|
|
320
|
+
|
|
300
321
|
if id_from in update:
|
|
301
322
|
raise ValueError(
|
|
302
323
|
f"Filter parameters `{id_from}` is reserved in `reference_batched_no_count`",
|
|
@@ -305,21 +326,37 @@ class Bitrix24:
|
|
|
305
326
|
tail_request.parameters.filter |= update
|
|
306
327
|
tail_request.parameters.start = -1
|
|
307
328
|
tail_request.parameters.order = {"ID": "ASC"}
|
|
308
|
-
|
|
329
|
+
|
|
330
|
+
if with_payload:
|
|
331
|
+
yield tail_request, payload
|
|
332
|
+
else:
|
|
333
|
+
yield tail_request
|
|
309
334
|
|
|
310
335
|
head_requests = []
|
|
311
336
|
tail_requests = iter(_tail_requests())
|
|
312
337
|
while body_requests := head_requests + list(islice(tail_requests, batch_size - len(head_requests))):
|
|
313
|
-
|
|
338
|
+
if with_payload:
|
|
339
|
+
body_requests, body_payloads = zip(*body_requests, strict=True)
|
|
340
|
+
else:
|
|
341
|
+
body_payloads = None
|
|
342
|
+
|
|
343
|
+
body_results = self.batch(body_requests, batch_size=batch_size)
|
|
314
344
|
body_results = map(self._fix_list_result, body_results)
|
|
315
345
|
|
|
316
346
|
head_requests = []
|
|
317
|
-
for body_request, body_result in zip(body_requests, body_results, strict=True):
|
|
347
|
+
for i, (body_request, body_result) in enumerate(zip(body_requests, body_results, strict=True)):
|
|
318
348
|
if len(body_result) == list_size:
|
|
319
349
|
max_id = max(map(int, map(get_id, body_result)), default=None)
|
|
320
350
|
head_request = body_request.model_copy(deep=True)
|
|
321
351
|
head_request.parameters.filter[id_from] = max_id
|
|
322
|
-
|
|
352
|
+
if with_payload:
|
|
353
|
+
head_requests.append((head_request, body_payloads[i]))
|
|
354
|
+
else:
|
|
355
|
+
head_requests.append(head_request)
|
|
356
|
+
|
|
357
|
+
if with_payload:
|
|
358
|
+
body_payload = [body_payloads[i]] * len(body_result)
|
|
359
|
+
body_result = zip(body_result, body_payload, strict=True)
|
|
323
360
|
|
|
324
361
|
yield from body_result
|
|
325
362
|
|
|
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
|