arpakitlib 1.5.38__py3-none-any.whl → 1.5.40__py3-none-any.whl
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.
- arpakitlib/AUTHOR.md +2 -1
- arpakitlib/README.md +3 -2
- arpakitlib/ar_additional_model_util.py +8 -1
- arpakitlib/ar_aiogram_util.py +0 -18
- arpakitlib/ar_arpakit_lib_module_util.py +0 -1
- arpakitlib/{ar_base_worker.py → ar_base_worker_util.py} +6 -7
- arpakitlib/{ar_cache_file.py → ar_cache_file_util.py} +1 -1
- arpakitlib/ar_fastapi_util.py +20 -19
- arpakitlib/ar_generate_env_example.py +4 -0
- arpakitlib/ar_http_request_util.py +8 -3
- arpakitlib/ar_operation_execution_util.py +83 -7
- arpakitlib/ar_postgresql_util.py +2 -9
- arpakitlib/{ar_schedule_uust_api_client.py → ar_schedule_uust_api_client_util.py} +2 -2
- arpakitlib/ar_sqlalchemy_model_util.py +8 -0
- arpakitlib/ar_sqlalchemy_util.py +6 -1
- arpakitlib/{ar_yookassa_api_client.py → ar_yookassa_api_client_util.py} +30 -55
- arpakitlib/ar_zabbix_util.py +6 -1
- {arpakitlib-1.5.38.dist-info → arpakitlib-1.5.40.dist-info}/METADATA +5 -3
- {arpakitlib-1.5.38.dist-info → arpakitlib-1.5.40.dist-info}/RECORD +27 -27
- /arpakitlib/{ar_dream_ai_api_client.py → ar_dream_ai_api_client_util.py} +0 -0
- /arpakitlib/{ar_encrypt_and_decrypt_util.py → ar_encrypt_decrypt_util.py} +0 -0
- /arpakitlib/{ar_file_storage_in_dir.py → ar_file_storage_in_dir_util.py} +0 -0
- /arpakitlib/{ar_json_db.py → ar_json_db_util.py} +0 -0
- /arpakitlib/{ar_run_cmd.py → ar_run_cmd_util.py} +0 -0
- {arpakitlib-1.5.38.dist-info → arpakitlib-1.5.40.dist-info}/LICENSE +0 -0
- {arpakitlib-1.5.38.dist-info → arpakitlib-1.5.40.dist-info}/NOTICE +0 -0
- {arpakitlib-1.5.38.dist-info → arpakitlib-1.5.40.dist-info}/WHEEL +0 -0
arpakitlib/AUTHOR.md
CHANGED
arpakitlib/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# arpakit
|
2
|
-
|
3
2
|
from typing import Any
|
4
3
|
|
5
4
|
from pydantic import BaseModel, ConfigDict
|
@@ -8,3 +7,11 @@ from pydantic import BaseModel, ConfigDict
|
|
8
7
|
class BaseAM(BaseModel):
|
9
8
|
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
|
10
9
|
bus_data: dict[str, Any] = {}
|
10
|
+
|
11
|
+
|
12
|
+
def __example():
|
13
|
+
pass
|
14
|
+
|
15
|
+
|
16
|
+
if __name__ == '__main__':
|
17
|
+
__example()
|
arpakitlib/ar_aiogram_util.py
CHANGED
@@ -23,9 +23,6 @@ _ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
|
23
23
|
_logger = logging.getLogger(__name__)
|
24
24
|
|
25
25
|
|
26
|
-
# ---
|
27
|
-
|
28
|
-
|
29
26
|
class TextFilter(Filter):
|
30
27
|
|
31
28
|
def __init__(
|
@@ -78,9 +75,6 @@ class IsPrivateChat(Filter):
|
|
78
75
|
return False
|
79
76
|
|
80
77
|
|
81
|
-
# ---
|
82
|
-
|
83
|
-
|
84
78
|
_used_cd_prefixes = set()
|
85
79
|
|
86
80
|
|
@@ -118,9 +112,6 @@ class WithFromCD(BaseCD, prefix="WithFromCD"):
|
|
118
112
|
from_: Optional[str] = None
|
119
113
|
|
120
114
|
|
121
|
-
# ---
|
122
|
-
|
123
|
-
|
124
115
|
class BadTgCommandFormat(BadCommandFormat):
|
125
116
|
pass
|
126
117
|
|
@@ -321,18 +312,12 @@ def as_tg_command(
|
|
321
312
|
return decorator
|
322
313
|
|
323
314
|
|
324
|
-
# ---
|
325
|
-
|
326
|
-
|
327
315
|
class SimpleMiddleware(BaseMiddleware, ABC):
|
328
316
|
def __init__(self):
|
329
317
|
self.middleware_name = self.__class__.__name__
|
330
318
|
self._logger = logging.getLogger(self.__class__.__name__)
|
331
319
|
|
332
320
|
|
333
|
-
# ---
|
334
|
-
|
335
|
-
|
336
321
|
def create_tg_bot(*, tg_bot_token: str, tg_bot_proxy_url: str | None = None) -> Bot:
|
337
322
|
session: AiohttpSession | None = None
|
338
323
|
if tg_bot_proxy_url:
|
@@ -349,9 +334,6 @@ def create_tg_bot(*, tg_bot_token: str, tg_bot_proxy_url: str | None = None) ->
|
|
349
334
|
return tg_bot
|
350
335
|
|
351
336
|
|
352
|
-
# ---
|
353
|
-
|
354
|
-
|
355
337
|
def __example():
|
356
338
|
pass
|
357
339
|
|
@@ -4,7 +4,6 @@ import asyncio
|
|
4
4
|
import logging
|
5
5
|
from abc import ABC
|
6
6
|
from datetime import timedelta
|
7
|
-
from typing import Any
|
8
7
|
|
9
8
|
from arpakitlib.ar_sleep_util import sync_safe_sleep, async_safe_sleep
|
10
9
|
|
@@ -16,8 +15,8 @@ class BaseWorker(ABC):
|
|
16
15
|
def __init__(self):
|
17
16
|
self.worker_name = self.__class__.__name__
|
18
17
|
self._logger = logging.getLogger(self.worker_name)
|
19
|
-
self.timeout_after_run
|
20
|
-
self.timeout_after_err_in_run
|
18
|
+
self.timeout_after_run = timedelta(seconds=0.1).total_seconds()
|
19
|
+
self.timeout_after_err_in_run = timedelta(seconds=1).total_seconds()
|
21
20
|
|
22
21
|
def sync_on_startup(self):
|
23
22
|
pass
|
@@ -25,7 +24,7 @@ class BaseWorker(ABC):
|
|
25
24
|
def sync_run(self):
|
26
25
|
raise NotImplementedError()
|
27
26
|
|
28
|
-
def sync_run_on_error(self, exception: BaseException, kwargs
|
27
|
+
def sync_run_on_error(self, exception: BaseException, **kwargs):
|
29
28
|
self._logger.exception(exception)
|
30
29
|
|
31
30
|
def sync_safe_run(self):
|
@@ -49,7 +48,7 @@ class BaseWorker(ABC):
|
|
49
48
|
except BaseException as exception:
|
50
49
|
|
51
50
|
self._logger.info("start sync_run_on_error")
|
52
|
-
self.sync_run_on_error(exception=exception
|
51
|
+
self.sync_run_on_error(exception=exception)
|
53
52
|
self._logger.info("start sync_run_on_error")
|
54
53
|
|
55
54
|
if self.timeout_after_err_in_run is not None:
|
@@ -61,7 +60,7 @@ class BaseWorker(ABC):
|
|
61
60
|
async def async_run(self):
|
62
61
|
raise NotImplementedError()
|
63
62
|
|
64
|
-
async def async_run_on_error(self, exception: BaseException, kwargs
|
63
|
+
async def async_run_on_error(self, exception: BaseException, **kwargs):
|
65
64
|
self._logger.exception(exception)
|
66
65
|
|
67
66
|
async def async_safe_run(self):
|
@@ -83,7 +82,7 @@ class BaseWorker(ABC):
|
|
83
82
|
except BaseException as exception:
|
84
83
|
|
85
84
|
self._logger.info("start async_run_on_error")
|
86
|
-
await self.async_run_on_error(exception=exception
|
85
|
+
await self.async_run_on_error(exception=exception)
|
87
86
|
self._logger.info("finish async_run_on_error")
|
88
87
|
|
89
88
|
if self.timeout_after_err_in_run is not None:
|
@@ -7,7 +7,7 @@ from typing import Optional, Any
|
|
7
7
|
import pytz
|
8
8
|
from pydantic import BaseModel
|
9
9
|
|
10
|
-
from arpakitlib.
|
10
|
+
from arpakitlib.ar_json_db_util import JSONDbFile
|
11
11
|
from arpakitlib.ar_type_util import raise_for_type
|
12
12
|
|
13
13
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
arpakitlib/ar_fastapi_util.py
CHANGED
@@ -23,6 +23,7 @@ from pydantic import BaseModel, ConfigDict
|
|
23
23
|
from starlette.middleware.cors import CORSMiddleware
|
24
24
|
from starlette.staticfiles import StaticFiles
|
25
25
|
|
26
|
+
from arpakitlib.ar_base_worker_util import BaseWorker
|
26
27
|
from arpakitlib.ar_dict_util import combine_dicts
|
27
28
|
from arpakitlib.ar_enumeration_util import Enumeration
|
28
29
|
from arpakitlib.ar_json_util import safely_transfer_to_json_str_to_json_obj
|
@@ -381,6 +382,15 @@ class BaseStartupAPIEvent:
|
|
381
382
|
self._logger.info("on_startup ends")
|
382
383
|
|
383
384
|
|
385
|
+
class BaseShutdownAPIEvent:
|
386
|
+
def __init__(self, *args, **kwargs):
|
387
|
+
self._logger = logging.getLogger(self.__class__.__name__)
|
388
|
+
|
389
|
+
async def async_on_shutdown(self, *args, **kwargs):
|
390
|
+
self._logger.info("on_shutdown starts")
|
391
|
+
self._logger.info("on_shutdown ends")
|
392
|
+
|
393
|
+
|
384
394
|
class InitSqlalchemyDBStartupAPIEvent(BaseStartupAPIEvent):
|
385
395
|
def __init__(self, sqlalchemy_db: SQLAlchemyDB):
|
386
396
|
super().__init__()
|
@@ -390,35 +400,26 @@ class InitSqlalchemyDBStartupAPIEvent(BaseStartupAPIEvent):
|
|
390
400
|
self.sqlalchemy_db.init()
|
391
401
|
|
392
402
|
|
393
|
-
class
|
394
|
-
def __init__(self,
|
403
|
+
class SyncSafeRunWorkerStartupAPIEvent(BaseStartupAPIEvent):
|
404
|
+
def __init__(self, worker: BaseWorker):
|
395
405
|
super().__init__()
|
396
|
-
self.
|
406
|
+
self.worker = worker
|
397
407
|
|
398
408
|
def async_on_startup(self, *args, **kwargs):
|
399
409
|
thread = threading.Thread(
|
400
|
-
target=self.
|
410
|
+
target=self.worker.sync_safe_run,
|
401
411
|
daemon=True
|
402
412
|
)
|
403
413
|
thread.start()
|
404
414
|
|
405
415
|
|
406
|
-
class
|
407
|
-
def __init__(self,
|
416
|
+
class AsyncSafeRunWorkerStartupAPIEvent(BaseStartupAPIEvent):
|
417
|
+
def __init__(self, worker: ExecuteOperationWorker):
|
408
418
|
super().__init__()
|
409
|
-
self.
|
419
|
+
self.worker = worker
|
410
420
|
|
411
421
|
def async_on_startup(self, *args, **kwargs):
|
412
|
-
_ = asyncio.create_task(self.
|
413
|
-
|
414
|
-
|
415
|
-
class BaseShutdownAPIEvent:
|
416
|
-
def __init__(self, *args, **kwargs):
|
417
|
-
self._logger = logging.getLogger(self.__class__.__name__)
|
418
|
-
|
419
|
-
async def async_on_shutdown(self, *args, **kwargs):
|
420
|
-
self._logger.info("on_shutdown starts")
|
421
|
-
self._logger.info("on_shutdown ends")
|
422
|
+
_ = asyncio.create_task(self.worker.async_safe_run())
|
422
423
|
|
423
424
|
|
424
425
|
class BaseTransmittedAPIData(BaseModel):
|
@@ -469,8 +470,8 @@ def simple_api_router_for_testing():
|
|
469
470
|
|
470
471
|
def create_fastapi_app(
|
471
472
|
*,
|
472
|
-
title: str = "
|
473
|
-
description: str | None = "
|
473
|
+
title: str = "arpakitlib FastAPI",
|
474
|
+
description: str | None = "arpakitlib FastAPI",
|
474
475
|
log_filepath: str | None = "./story.log",
|
475
476
|
handle_exception_: Callable | None = create_handle_exception(),
|
476
477
|
startup_api_events: list[BaseStartupAPIEvent] | None = None,
|
@@ -9,22 +9,27 @@ import requests
|
|
9
9
|
from aiohttp_socks import ProxyConnector
|
10
10
|
|
11
11
|
from arpakitlib.ar_sleep_util import sync_safe_sleep, async_safe_sleep
|
12
|
+
from arpakitlib.ar_type_util import raise_for_type
|
12
13
|
|
13
14
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
14
15
|
|
15
16
|
_logger = logging.getLogger(__name__)
|
16
17
|
|
17
18
|
|
18
|
-
def
|
19
|
+
def sync_make_http_request(
|
19
20
|
*,
|
20
21
|
method: str = "GET",
|
21
22
|
url: str,
|
22
23
|
max_tries_: int = 9,
|
23
24
|
proxy_url_: str | None = None,
|
24
25
|
raise_for_status_: bool = False,
|
25
|
-
timeout_: timedelta = timedelta(seconds=15).total_seconds(),
|
26
|
+
timeout_: timedelta | float = timedelta(seconds=15).total_seconds(),
|
26
27
|
**kwargs
|
27
28
|
) -> requests.Response:
|
29
|
+
if isinstance(timeout_, float):
|
30
|
+
timeout_ = timedelta(seconds=timeout_)
|
31
|
+
raise_for_type(timeout_, timedelta)
|
32
|
+
|
28
33
|
tries_counter = 0
|
29
34
|
|
30
35
|
kwargs["method"] = method
|
@@ -55,7 +60,7 @@ def sync_make_request(
|
|
55
60
|
continue
|
56
61
|
|
57
62
|
|
58
|
-
async def
|
63
|
+
async def async_make_http_request(
|
59
64
|
*,
|
60
65
|
method: str = "GET",
|
61
66
|
url: str,
|
@@ -2,15 +2,18 @@
|
|
2
2
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
|
+
import asyncio
|
5
6
|
import logging
|
6
7
|
import traceback
|
7
8
|
from datetime import timedelta
|
8
|
-
from typing import Any
|
9
|
+
from typing import Any, Callable
|
9
10
|
|
11
|
+
from pydantic import ConfigDict
|
12
|
+
from pydantic.v1 import BaseModel
|
10
13
|
from sqlalchemy import asc
|
11
14
|
from sqlalchemy.orm import Session
|
12
15
|
|
13
|
-
from arpakitlib.
|
16
|
+
from arpakitlib.ar_base_worker_util import BaseWorker
|
14
17
|
from arpakitlib.ar_datetime_util import now_utc_dt
|
15
18
|
from arpakitlib.ar_dict_util import combine_dicts
|
16
19
|
from arpakitlib.ar_sqlalchemy_model_util import OperationDBM, StoryLogDBM
|
@@ -216,12 +219,14 @@ class ExecuteOperationWorker(BaseWorker):
|
|
216
219
|
*,
|
217
220
|
sqlalchemy_db: SQLAlchemyDB,
|
218
221
|
operation_executor: BaseOperationExecutor | None = None,
|
219
|
-
filter_operation_type: str | None = None
|
222
|
+
filter_operation_type: str | None = None,
|
223
|
+
timeout_after_run=timedelta(seconds=0.1).total_seconds(),
|
224
|
+
timeout_after_err_in_run=timedelta(seconds=1).total_seconds()
|
220
225
|
):
|
221
226
|
super().__init__()
|
222
227
|
self.sqlalchemy_db = sqlalchemy_db
|
223
|
-
self.timeout_after_run =
|
224
|
-
self.timeout_after_err_in_run =
|
228
|
+
self.timeout_after_run = timeout_after_run
|
229
|
+
self.timeout_after_err_in_run = timeout_after_err_in_run
|
225
230
|
if operation_executor is None:
|
226
231
|
operation_executor = BaseOperationExecutor(sqlalchemy_db=sqlalchemy_db)
|
227
232
|
self.operation_executor = operation_executor
|
@@ -244,7 +249,7 @@ class ExecuteOperationWorker(BaseWorker):
|
|
244
249
|
|
245
250
|
await self.async_execute_operation(operation_dbm=operation_dbm)
|
246
251
|
|
247
|
-
async def async_run_on_error(self, exception: BaseException, kwargs
|
252
|
+
async def async_run_on_error(self, exception: BaseException, **kwargs):
|
248
253
|
self._logger.exception(exception)
|
249
254
|
|
250
255
|
def sync_on_startup(self):
|
@@ -264,5 +269,76 @@ class ExecuteOperationWorker(BaseWorker):
|
|
264
269
|
|
265
270
|
self.sync_execute_operation(operation_dbm=operation_dbm)
|
266
271
|
|
267
|
-
def sync_run_on_error(self, exception: BaseException, kwargs
|
272
|
+
def sync_run_on_error(self, exception: BaseException, **kwargs):
|
268
273
|
self._logger.exception(exception)
|
274
|
+
|
275
|
+
|
276
|
+
class ScheduledOperation(BaseModel):
|
277
|
+
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
|
278
|
+
|
279
|
+
type: str
|
280
|
+
input_data: dict[str, Any] | None = None
|
281
|
+
is_time_func: Callable[[], bool]
|
282
|
+
|
283
|
+
|
284
|
+
class CreateScheduledOperationWorker(BaseWorker):
|
285
|
+
def __init__(
|
286
|
+
self,
|
287
|
+
*,
|
288
|
+
sqlalchemy_db: SQLAlchemyDB,
|
289
|
+
scheduled_operations: list[ScheduledOperation] | None = None,
|
290
|
+
timeout_after_run=timedelta(seconds=0.1).total_seconds(),
|
291
|
+
timeout_after_err_in_run=timedelta(seconds=1).total_seconds()
|
292
|
+
):
|
293
|
+
super().__init__()
|
294
|
+
self.sqlalchemy_db = sqlalchemy_db
|
295
|
+
self.timeout_after_run = timeout_after_run
|
296
|
+
self.timeout_after_err_in_run = timeout_after_err_in_run
|
297
|
+
if scheduled_operations is None:
|
298
|
+
scheduled_operations = []
|
299
|
+
self.scheduled_operations = scheduled_operations
|
300
|
+
|
301
|
+
def sync_on_startup(self):
|
302
|
+
self.sqlalchemy_db.init()
|
303
|
+
|
304
|
+
def sync_run(self):
|
305
|
+
for scheduled_operation in self.scheduled_operations:
|
306
|
+
if not scheduled_operation.is_time_func():
|
307
|
+
continue
|
308
|
+
with self.sqlalchemy_db.new_session() as session:
|
309
|
+
operation_dbm = OperationDBM(
|
310
|
+
type=scheduled_operation.type,
|
311
|
+
input_data=scheduled_operation.input_data
|
312
|
+
)
|
313
|
+
session.add(operation_dbm)
|
314
|
+
session.commit()
|
315
|
+
session.refresh(operation_dbm)
|
316
|
+
|
317
|
+
def async_on_startup(self):
|
318
|
+
self.sqlalchemy_db.init()
|
319
|
+
|
320
|
+
def async_run(self):
|
321
|
+
for scheduled_operation in self.scheduled_operations:
|
322
|
+
if not scheduled_operation.is_time_func():
|
323
|
+
continue
|
324
|
+
with self.sqlalchemy_db.new_session() as session:
|
325
|
+
operation_dbm = OperationDBM(
|
326
|
+
type=scheduled_operation.type,
|
327
|
+
input_data=scheduled_operation.input_data
|
328
|
+
)
|
329
|
+
session.add(operation_dbm)
|
330
|
+
session.commit()
|
331
|
+
session.refresh(operation_dbm)
|
332
|
+
|
333
|
+
|
334
|
+
def __example():
|
335
|
+
pass
|
336
|
+
|
337
|
+
|
338
|
+
async def __async_example():
|
339
|
+
pass
|
340
|
+
|
341
|
+
|
342
|
+
if __name__ == '__main__':
|
343
|
+
__example()
|
344
|
+
asyncio.run(__async_example())
|
arpakitlib/ar_postgresql_util.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# arpakit
|
2
2
|
|
3
|
-
from arpakitlib.
|
4
|
-
from arpakitlib.ar_run_cmd import run_cmd
|
3
|
+
from arpakitlib.ar_run_cmd_util import run_cmd
|
5
4
|
from arpakitlib.ar_type_util import raise_for_type
|
6
5
|
|
7
6
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
@@ -34,13 +33,7 @@ def make_postgresql_db_dump(
|
|
34
33
|
|
35
34
|
|
36
35
|
def __example():
|
37
|
-
|
38
|
-
make_postgresql_db_dump(
|
39
|
-
user="arpakitlib",
|
40
|
-
db_name="arpakitlib",
|
41
|
-
port=50629,
|
42
|
-
password="arpakitlib"
|
43
|
-
)
|
36
|
+
pass
|
44
37
|
|
45
38
|
|
46
39
|
if __name__ == '__main__':
|
@@ -9,7 +9,7 @@ from typing import Any
|
|
9
9
|
import pytz
|
10
10
|
|
11
11
|
from arpakitlib.ar_dict_util import combine_dicts
|
12
|
-
from arpakitlib.ar_http_request_util import
|
12
|
+
from arpakitlib.ar_http_request_util import async_make_http_request
|
13
13
|
from arpakitlib.ar_type_util import raise_for_type
|
14
14
|
|
15
15
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
@@ -75,7 +75,7 @@ class ScheduleUUSTAPIClient:
|
|
75
75
|
url: str,
|
76
76
|
params: dict | None = None
|
77
77
|
) -> dict[str, Any]:
|
78
|
-
response = await
|
78
|
+
response = await async_make_http_request(
|
79
79
|
url=url,
|
80
80
|
method="GET",
|
81
81
|
params=combine_dicts(params, self.auth_params()),
|
arpakitlib/ar_sqlalchemy_util.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# arpakit
|
2
|
-
|
2
|
+
import asyncio
|
3
3
|
import logging
|
4
4
|
from datetime import timedelta
|
5
5
|
from typing import Any
|
@@ -102,5 +102,10 @@ def __example():
|
|
102
102
|
pass
|
103
103
|
|
104
104
|
|
105
|
+
async def __async_example():
|
106
|
+
pass
|
107
|
+
|
108
|
+
|
105
109
|
if __name__ == '__main__':
|
106
110
|
__example()
|
111
|
+
asyncio.run(__async_example())
|
@@ -13,7 +13,7 @@ import requests
|
|
13
13
|
|
14
14
|
from arpakitlib.ar_dict_util import combine_dicts
|
15
15
|
from arpakitlib.ar_enumeration_util import Enumeration
|
16
|
-
from arpakitlib.
|
16
|
+
from arpakitlib.ar_http_request_util import sync_make_http_request, async_make_http_request
|
17
17
|
from arpakitlib.ar_type_util import raise_for_type
|
18
18
|
|
19
19
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
@@ -42,56 +42,23 @@ class YookassaAPIClient:
|
|
42
42
|
self.headers = {"Content-Type": "application/json"}
|
43
43
|
self._logger = logging.getLogger(self.__class__.__name__)
|
44
44
|
|
45
|
-
def _sync_make_request(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
def _sync_make_request(
|
46
|
+
self,
|
47
|
+
*,
|
48
|
+
method: str,
|
49
|
+
url: str,
|
50
|
+
**kwargs
|
51
|
+
) -> requests.Response:
|
52
52
|
if "headers" not in kwargs:
|
53
53
|
kwargs["headers"] = {}
|
54
54
|
kwargs["headers"] = combine_dicts(self.headers, kwargs["headers"])
|
55
55
|
kwargs["auth"] = (self.shop_id, self.secret_key)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
except Exception as err:
|
63
|
-
self._logger.warning(f"{tries}/{max_tries} {err} {method} {url}")
|
64
|
-
if tries >= max_tries:
|
65
|
-
raise YookassaAPIException(err)
|
66
|
-
sync_safe_sleep(timedelta(seconds=0.1).total_seconds())
|
67
|
-
continue
|
68
|
-
|
69
|
-
async def _async_make_request(self, method: str, url: str, **kwargs) -> aiohttp.ClientResponse:
|
70
|
-
max_tries = 7
|
71
|
-
tries = 0
|
72
|
-
|
73
|
-
kwargs["url"] = url
|
74
|
-
kwargs["method"] = method
|
75
|
-
kwargs["timeout"] = aiohttp.ClientTimeout(total=timedelta(seconds=15).total_seconds())
|
76
|
-
if "headers" not in kwargs:
|
77
|
-
kwargs["headers"] = {}
|
78
|
-
kwargs["headers"] = combine_dicts(self.headers, kwargs["headers"])
|
79
|
-
kwargs["auth"] = aiohttp.BasicAuth(login=str(self.shop_id), password=self.secret_key)
|
80
|
-
|
81
|
-
while True:
|
82
|
-
self._logger.info(f"{method} {url}")
|
83
|
-
tries += 1
|
84
|
-
try:
|
85
|
-
async with aiohttp.ClientSession() as session:
|
86
|
-
async with session.request(**kwargs) as response:
|
87
|
-
await response.read()
|
88
|
-
return response
|
89
|
-
except Exception as err:
|
90
|
-
self._logger.warning(f"{tries}/{max_tries} {err} {method} {url}")
|
91
|
-
if tries >= max_tries:
|
92
|
-
raise YookassaAPIException(err)
|
93
|
-
await async_safe_sleep(timedelta(seconds=0.1).total_seconds())
|
94
|
-
continue
|
56
|
+
kwargs["timeout_"] = timedelta(seconds=3)
|
57
|
+
return sync_make_http_request(
|
58
|
+
method=method,
|
59
|
+
url=url,
|
60
|
+
**kwargs
|
61
|
+
)
|
95
62
|
|
96
63
|
def sync_create_payment(
|
97
64
|
self,
|
@@ -121,12 +88,10 @@ class YookassaAPIClient:
|
|
121
88
|
if idempotence_key is None:
|
122
89
|
idempotence_key = str(uuid.uuid4())
|
123
90
|
|
124
|
-
headers = combine_dicts({"Idempotence-Key": idempotence_key})
|
125
|
-
|
126
91
|
response = self._sync_make_request(
|
127
92
|
method="POST",
|
128
93
|
url="https://api.yookassa.ru/v3/payments",
|
129
|
-
headers=
|
94
|
+
headers={"Idempotence-Key": idempotence_key},
|
130
95
|
json=json_body,
|
131
96
|
)
|
132
97
|
|
@@ -154,6 +119,18 @@ class YookassaAPIClient:
|
|
154
119
|
|
155
120
|
return json_data
|
156
121
|
|
122
|
+
async def async_make_request(self, method: str, url: str, **kwargs) -> aiohttp.ClientResponse:
|
123
|
+
if "headers" not in kwargs:
|
124
|
+
kwargs["headers"] = {}
|
125
|
+
kwargs["headers"] = combine_dicts(self.headers, kwargs["headers"])
|
126
|
+
kwargs["auth"] = aiohttp.BasicAuth(login=str(self.shop_id), password=self.secret_key)
|
127
|
+
kwargs["timeout_"] = timedelta(seconds=3)
|
128
|
+
return await async_make_http_request(
|
129
|
+
method=method,
|
130
|
+
url=url,
|
131
|
+
**kwargs
|
132
|
+
)
|
133
|
+
|
157
134
|
async def async_create_payment(
|
158
135
|
self, json_body: dict[str, Any], idempotence_key: Optional[str] = None
|
159
136
|
) -> dict[str, Any]:
|
@@ -180,12 +157,10 @@ class YookassaAPIClient:
|
|
180
157
|
if idempotence_key is None:
|
181
158
|
idempotence_key = str(uuid.uuid4())
|
182
159
|
|
183
|
-
|
184
|
-
|
185
|
-
response = await self._async_make_request(
|
160
|
+
response = await self.async_make_request(
|
186
161
|
method="POST",
|
187
162
|
url="https://api.yookassa.ru/v3/payments",
|
188
|
-
headers=
|
163
|
+
headers={"Idempotence-Key": idempotence_key},
|
189
164
|
json=json_body,
|
190
165
|
)
|
191
166
|
|
@@ -198,7 +173,7 @@ class YookassaAPIClient:
|
|
198
173
|
async def async_get_payment(self, payment_id: str) -> Optional[dict[str, Any]]:
|
199
174
|
raise_for_type(payment_id, str)
|
200
175
|
|
201
|
-
response = await self.
|
176
|
+
response = await self.async_make_request(
|
202
177
|
method="GET",
|
203
178
|
url=f"https://api.yookassa.ru/v3/payments/{payment_id}",
|
204
179
|
)
|
arpakitlib/ar_zabbix_util.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# arpakit
|
2
|
-
|
2
|
+
import asyncio
|
3
3
|
import logging
|
4
4
|
import time
|
5
5
|
from datetime import timedelta, datetime
|
@@ -188,5 +188,10 @@ def __example():
|
|
188
188
|
pass
|
189
189
|
|
190
190
|
|
191
|
+
async def __async_example():
|
192
|
+
pass
|
193
|
+
|
194
|
+
|
191
195
|
if __name__ == '__main__':
|
192
196
|
__example()
|
197
|
+
asyncio.run(__async_example())
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: arpakitlib
|
3
|
-
Version: 1.5.
|
3
|
+
Version: 1.5.40
|
4
4
|
Summary: arpakitlib
|
5
5
|
Home-page: https://github.com/ARPAKIT-Company/arpakitlib
|
6
6
|
License: Apache-2.0
|
@@ -51,6 +51,7 @@ workflow
|
|
51
51
|
---
|
52
52
|
|
53
53
|
### Supported python version
|
54
|
+
|
54
55
|
- Python ^3.12
|
55
56
|
|
56
57
|
---
|
@@ -74,8 +75,9 @@ pip install arpakitlib
|
|
74
75
|
- https://pypi.org/project/arpakitlib/
|
75
76
|
- https://test.pypi.org/project/arpakitlib/
|
76
77
|
- https://github.com/ARPAKIT-Company/arpakitlib
|
77
|
-
- https://t.me/arpakit
|
78
|
-
- arpakit@gmail.com
|
78
|
+
- https://t.me/arpakit
|
79
|
+
- arpakit@gmail.com
|
80
|
+
- support@arpakit.com
|
79
81
|
|
80
82
|
---
|
81
83
|
|
@@ -1,20 +1,20 @@
|
|
1
|
-
arpakitlib/AUTHOR.md,sha256=
|
1
|
+
arpakitlib/AUTHOR.md,sha256=mBdzFR-3Dw6ADRTIbfOz2ZHvZt5589zBjhBkpEcakSY,92
|
2
2
|
arpakitlib/LICENSE,sha256=1jqWIkbnMxDfs_i0SXP5qbV6PHjBr1g8506oW7uPjfg,11347
|
3
3
|
arpakitlib/NOTICE,sha256=wHwmiq3wExfFfgMsE5U5TOBP9_l72ocIG82KurEels0,43
|
4
|
-
arpakitlib/README.md,sha256=
|
4
|
+
arpakitlib/README.md,sha256=mBdzFR-3Dw6ADRTIbfOz2ZHvZt5589zBjhBkpEcakSY,92
|
5
5
|
arpakitlib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
arpakitlib/ar_additional_model_util.py,sha256=
|
7
|
-
arpakitlib/ar_aiogram_util.py,sha256=
|
8
|
-
arpakitlib/ar_arpakit_lib_module_util.py,sha256=
|
6
|
+
arpakitlib/ar_additional_model_util.py,sha256=t95M4Ggl7EBRj7qOJHmuo5p2YmE7LlJdEAMNzse3vhE,309
|
7
|
+
arpakitlib/ar_aiogram_util.py,sha256=zQ5txWe359U8LCSD-jvSz1Ol8N40bEg3DdTRbdRD8fU,11974
|
8
|
+
arpakitlib/ar_arpakit_lib_module_util.py,sha256=V_mc3Ml73Tzz3arxmwEfIxruKMyrwbe8XZ9FfVDtUXY,5446
|
9
9
|
arpakitlib/ar_arpakit_schedule_uust_api_client.py,sha256=SYWWQDohPnw0qpBIu2hEvGZRVdaI4NUUQdEjnMnseo4,18237
|
10
10
|
arpakitlib/ar_arpakitlib_info.py,sha256=cvgrLnEznmYkCAg1adbY46ATjD6GJd-Yk8PTgOPjpKM,248
|
11
11
|
arpakitlib/ar_base64_util.py,sha256=aZkg2cZTuAaP2IWeG_LXJ6RO7qhyskVwec-Lks0iM-k,676
|
12
|
-
arpakitlib/
|
13
|
-
arpakitlib/
|
12
|
+
arpakitlib/ar_base_worker_util.py,sha256=8ruBoF9pARf3yc5duAajUOBi7Cce5KFAkp66lShRf7U,2796
|
13
|
+
arpakitlib/ar_cache_file_util.py,sha256=Fo2pH-Zqm966KWFBHG_pbiySGZvhIFCYqy7k1weRfJ0,3476
|
14
14
|
arpakitlib/ar_datetime_util.py,sha256=Xe1NiT9oPQzNSG7RVRkhukhbg4i-hhS5ImmV7sPUc8o,971
|
15
15
|
arpakitlib/ar_dict_util.py,sha256=cF5LQJ6tLqyGoEXfDljMDZrikeZoWPw7CgINHIFGvXM,419
|
16
|
-
arpakitlib/
|
17
|
-
arpakitlib/
|
16
|
+
arpakitlib/ar_dream_ai_api_client_util.py,sha256=hDPL9wbG4MjIuhn2ed6qepueogANIkt-NddhhiPUv0Y,4029
|
17
|
+
arpakitlib/ar_encrypt_decrypt_util.py,sha256=GhWnp7HHkbhwFVVCzO1H07m-5gryr4yjWsXjOaNQm1Y,520
|
18
18
|
arpakitlib/ar_enumeration_util.py,sha256=0DN46uyI0Gu9JPDgso3XPbnre7hZZefYTZwmmE1iYH4,2250
|
19
19
|
arpakitlib/ar_fastapi_static/redoc/redoc.standalone.js,sha256=WCuodUNv1qVh0oW5fjnJDwb5AwOue73jKHdI9z8iGKU,909365
|
20
20
|
arpakitlib/ar_fastapi_static/swagger-ui/favicon-16x16.png,sha256=ryStYE3Xs7zaj5dauXMHX0ovcKQIeUShL474tjo-B8I,665
|
@@ -35,13 +35,13 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
|
|
35
35
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
|
36
36
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
|
37
37
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
|
38
|
-
arpakitlib/ar_fastapi_util.py,sha256=
|
39
|
-
arpakitlib/
|
40
|
-
arpakitlib/ar_generate_env_example.py,sha256=
|
38
|
+
arpakitlib/ar_fastapi_util.py,sha256=05Bg7PB7LyCdn2I4ptxOJKzMbB3lS1RbBBMc8sE6HWY,16713
|
39
|
+
arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
|
40
|
+
arpakitlib/ar_generate_env_example.py,sha256=R_pdbFZe-mIZxEps2dm-K9m8rAg1pAaMzFOBPTGe4s4,370
|
41
41
|
arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
|
42
|
-
arpakitlib/ar_http_request_util.py,sha256=
|
42
|
+
arpakitlib/ar_http_request_util.py,sha256=hMzu2yedUvwIg6gafSakDjXUEC7WH5iplDGiRW9fgPw,3322
|
43
43
|
arpakitlib/ar_ip_util.py,sha256=aEAa1Hvobh9DWX7cmBAPLqnXSTiKe2hRk-WJaiKMaI8,1009
|
44
|
-
arpakitlib/
|
44
|
+
arpakitlib/ar_json_db_util.py,sha256=CEyhIU4WuNmX5mqwBVYxUKSdpFelXvWmf_tJ1fuxMSE,7187
|
45
45
|
arpakitlib/ar_json_util.py,sha256=S8CskZ3uoYuJGCy1GhQ8Ikhn-fxXk-9JpLUbBvXADqI,833
|
46
46
|
arpakitlib/ar_jwt_util.py,sha256=Rhm4ywoTAn6yOV8NLjDASfAtAtheROxxDP40G3XjnuQ,761
|
47
47
|
arpakitlib/ar_list_of_dicts_to_xlsx.py,sha256=MyjEl4Jl4beLVZqLVQMMv0-XDtBD3Xh4Z_ZPDJeFu04,745
|
@@ -50,21 +50,21 @@ arpakitlib/ar_logging_util.py,sha256=c5wX2FLqCzb4aLckLVhIJ7go52rJQ4GN9dIkJ6KMc3o
|
|
50
50
|
arpakitlib/ar_mongodb_util.py,sha256=2ECkTnGAZ92qxioL-fmN6R4yZOSr3bXdXLWTzT1C3vk,4038
|
51
51
|
arpakitlib/ar_need_type_util.py,sha256=n2kBETxzOSVhSVoy7qUtHtuQzgrrxzgi1_iVQimPb9o,1615
|
52
52
|
arpakitlib/ar_openai_util.py,sha256=dHUbfg1sVVCjsNl_fra3iCMEz1bR-Hk9fE-DdYbu7Wc,1215
|
53
|
-
arpakitlib/ar_operation_execution_util.py,sha256=
|
53
|
+
arpakitlib/ar_operation_execution_util.py,sha256=w_dz4XYEM4WbTxpBoYVkknG3U3_391cJmitgljJJTO0,12373
|
54
54
|
arpakitlib/ar_parse_command.py,sha256=qpr2OwG3Bf7DFiL9S3iWgtbvtE80RSC35E5zFJvjG1I,2714
|
55
|
-
arpakitlib/ar_postgresql_util.py,sha256=
|
56
|
-
arpakitlib/
|
57
|
-
arpakitlib/
|
55
|
+
arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJAdo,945
|
56
|
+
arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
|
57
|
+
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=NpCN8GT96aPvE3Lc-IRn653abjI95CmOqNc4pbHIWxo,5780
|
58
58
|
arpakitlib/ar_sleep_util.py,sha256=9ZN4Qo4eZ_q3hjM7vNBQjFRcH-9-sqv3QLSjnxVJE90,1405
|
59
|
-
arpakitlib/ar_sqlalchemy_model_util.py,sha256=
|
60
|
-
arpakitlib/ar_sqlalchemy_util.py,sha256=
|
59
|
+
arpakitlib/ar_sqlalchemy_model_util.py,sha256=hcXn-t20_ioOg89g6Pzg3VJQd4-a6Lbofvzfg14R_z8,4324
|
60
|
+
arpakitlib/ar_sqlalchemy_util.py,sha256=HgWp7zUGZNNFc4zuAjHeji6MEPFAbNnwpWqsuFRztjs,3754
|
61
61
|
arpakitlib/ar_ssh_util.py,sha256=jlnss4V4pziBN1rBzoK_lDiWm6nMOqGXfa6NFJSKH-Y,6796
|
62
62
|
arpakitlib/ar_str_util.py,sha256=xSEzmsDvRiZVaxyqFFjcgzpphktCbXg2FHcvsd1DYpA,1885
|
63
63
|
arpakitlib/ar_type_util.py,sha256=I6jbTz7_dxR1lkhz1JfUb5ZyLLdXVhG_-hzjdgT6N6s,1932
|
64
|
-
arpakitlib/
|
65
|
-
arpakitlib/ar_zabbix_util.py,sha256=
|
66
|
-
arpakitlib-1.5.
|
67
|
-
arpakitlib-1.5.
|
68
|
-
arpakitlib-1.5.
|
69
|
-
arpakitlib-1.5.
|
70
|
-
arpakitlib-1.5.
|
64
|
+
arpakitlib/ar_yookassa_api_client_util.py,sha256=5GMvu8paByni8buhc1vpHB7n6oXe0gPfj1LSvnyZCrQ,5307
|
65
|
+
arpakitlib/ar_zabbix_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
|
66
|
+
arpakitlib-1.5.40.dist-info/LICENSE,sha256=1jqWIkbnMxDfs_i0SXP5qbV6PHjBr1g8506oW7uPjfg,11347
|
67
|
+
arpakitlib-1.5.40.dist-info/METADATA,sha256=LwdjzZ4mVcgUfIZxUonowzcObR9Rxhj_RkP7k4f1tTM,2320
|
68
|
+
arpakitlib-1.5.40.dist-info/NOTICE,sha256=wHwmiq3wExfFfgMsE5U5TOBP9_l72ocIG82KurEels0,43
|
69
|
+
arpakitlib-1.5.40.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
70
|
+
arpakitlib-1.5.40.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|