arpakitlib 1.5.18__tar.gz → 1.5.20__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.
Potentially problematic release.
This version of arpakitlib might be problematic. Click here for more details.
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/PKG-INFO +1 -1
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_datetime_util.py +1 -1
- arpakitlib-1.5.18/arpakitlib/ar_sqlalchemy_util.py → arpakitlib-1.5.20/arpakitlib/ar_easy_sqlalchemy_util.py +8 -39
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_util.py +14 -13
- arpakitlib-1.5.20/arpakitlib/ar_sqlalchemy_model_util.py +42 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/pyproject.toml +1 -1
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/LICENSE +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/NOTICE +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/README.md +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/AUTHOR.md +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/LICENSE +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/NOTICE +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/README.md +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/__init__.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_additional_model_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_aiogram_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_arpakit_lib_module_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_arpakit_schedule_uust_api_client.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_arpakitlib_info.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_base64_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_base_worker.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_cache_file.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_dict_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_dream_ai_api_client.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_encrypt_and_decrypt_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_enumeration.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/redoc/redoc.standalone.js +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/favicon-16x16.png +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/favicon-32x32.png +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/index.css +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/index.html +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/oauth2-redirect.html +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-initializer.js +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-bundle.js +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-bundle.js.map +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-es-bundle-core.js +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-es-bundle-core.js.map +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-es-bundle.js +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-es-bundle.js.map +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-standalone-preset.js +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-standalone-preset.js.map +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_file_storage_in_dir.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_generate_env_example.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_hash_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_http_request_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_ip_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_json_db.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_json_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_jwt_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_list_of_dicts_to_xlsx.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_list_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_logging_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_mongodb_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_need_type_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_openai_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_parse_command.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_postgresql_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_run_cmd.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_safe_sleep.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_schedule_uust_api_client.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_ssh_runner.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_str_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_type_util.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_yookassa_api_client.py +0 -0
- {arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_zabbix_util.py +0 -0
|
@@ -1,49 +1,15 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
from datetime import timedelta
|
|
2
|
+
from datetime import timedelta
|
|
3
3
|
from typing import Any
|
|
4
4
|
from uuid import uuid4
|
|
5
5
|
|
|
6
|
-
from sqlalchemy import create_engine, QueuePool, text, func
|
|
7
|
-
from sqlalchemy.orm import sessionmaker
|
|
6
|
+
from sqlalchemy import create_engine, QueuePool, text, func
|
|
7
|
+
from sqlalchemy.orm import sessionmaker
|
|
8
8
|
from sqlalchemy.orm.session import Session
|
|
9
9
|
|
|
10
|
-
from arpakitlib.ar_datetime_util import now_utc_dt
|
|
11
|
-
from arpakitlib.ar_json_util import safely_transfer_to_json_str
|
|
12
|
-
|
|
13
10
|
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
|
14
11
|
|
|
15
12
|
|
|
16
|
-
class BaseDBM(DeclarativeBase):
|
|
17
|
-
__abstract__ = True
|
|
18
|
-
_bus_data: dict[str, Any] | None = None
|
|
19
|
-
|
|
20
|
-
@property
|
|
21
|
-
def bus_data(self) -> dict[str, Any]:
|
|
22
|
-
if self._bus_data is None:
|
|
23
|
-
self._bus_data = {}
|
|
24
|
-
return self._bus_data
|
|
25
|
-
|
|
26
|
-
def simple_dict(self) -> dict[str, Any]:
|
|
27
|
-
return {c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs}
|
|
28
|
-
|
|
29
|
-
def simple_json(self) -> str:
|
|
30
|
-
return safely_transfer_to_json_str(self.simple_dict())
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class SimpleDBM(BaseDBM):
|
|
34
|
-
__abstract__ = True
|
|
35
|
-
|
|
36
|
-
id: Mapped[int] = mapped_column(
|
|
37
|
-
INTEGER, primary_key=True, autoincrement=True, nullable=False
|
|
38
|
-
)
|
|
39
|
-
long_id: Mapped[str] = mapped_column(
|
|
40
|
-
TEXT, insert_default=uuid4, unique=True, nullable=False
|
|
41
|
-
)
|
|
42
|
-
creation_dt: Mapped[datetime] = mapped_column(
|
|
43
|
-
TIMESTAMP(timezone=True), insert_default=now_utc_dt, index=True, nullable=False
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
|
|
47
13
|
class EasySQLAlchemyDB:
|
|
48
14
|
def __init__(self, *, db_url: str, echo: bool = False):
|
|
49
15
|
self._logger = logging.getLogger(self.__class__.__name__)
|
|
@@ -73,14 +39,17 @@ class EasySQLAlchemyDB:
|
|
|
73
39
|
self._logger.info("celery tables data were removed")
|
|
74
40
|
|
|
75
41
|
def init(self):
|
|
42
|
+
from arpakitlib.ar_sqlalchemy_model_util import BaseDBM
|
|
76
43
|
BaseDBM.metadata.create_all(bind=self.engine, checkfirst=True)
|
|
77
44
|
self._logger.info("db was inited")
|
|
78
45
|
|
|
79
46
|
def drop(self):
|
|
47
|
+
from arpakitlib.ar_sqlalchemy_model_util import BaseDBM
|
|
80
48
|
BaseDBM.metadata.drop_all(bind=self.engine, checkfirst=True)
|
|
81
49
|
self._logger.info("db was dropped")
|
|
82
50
|
|
|
83
51
|
def reinit(self):
|
|
52
|
+
from arpakitlib.ar_sqlalchemy_model_util import BaseDBM
|
|
84
53
|
BaseDBM.metadata.drop_all(bind=self.engine, checkfirst=True)
|
|
85
54
|
BaseDBM.metadata.create_all(bind=self.engine, checkfirst=True)
|
|
86
55
|
self._logger.info("db was reinited")
|
|
@@ -101,14 +70,14 @@ class EasySQLAlchemyDB:
|
|
|
101
70
|
return False
|
|
102
71
|
return True
|
|
103
72
|
|
|
104
|
-
def generate_unique_id(self, *, class_dbm:
|
|
73
|
+
def generate_unique_id(self, *, class_dbm: Any):
|
|
105
74
|
with self.new_session() as session:
|
|
106
75
|
res: int = session.query(func.max(class_dbm.id)).scalar()
|
|
107
76
|
while session.query(class_dbm).filter(class_dbm.id == res).first() is not None:
|
|
108
77
|
res += 1
|
|
109
78
|
return res
|
|
110
79
|
|
|
111
|
-
def generate_unique_long_id(self, *, class_dbm:
|
|
80
|
+
def generate_unique_long_id(self, *, class_dbm: Any):
|
|
112
81
|
with self.new_session() as session:
|
|
113
82
|
res: str = str(uuid4())
|
|
114
83
|
while session.query(class_dbm).filter(class_dbm.long_id == res).first() is not None:
|
|
@@ -53,13 +53,14 @@ class APIJSONResponse(fastapi.responses.JSONResponse):
|
|
|
53
53
|
)
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
class
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
class APIErrorCodes(EasyEnumeration):
|
|
57
|
+
cannot_authorize = "CANNOT_AUTHORIZE"
|
|
58
|
+
unknown_error = "UNKNOWN_ERROR"
|
|
59
|
+
error_in_request = "ERROR_IN_REQUEST"
|
|
60
|
+
not_found = "NOT_FOUND"
|
|
61
|
+
|
|
62
62
|
|
|
63
|
+
class APIErrorSO(BaseAPISO):
|
|
63
64
|
has_error: bool = True
|
|
64
65
|
error_code: str | None = None
|
|
65
66
|
error_code_specification: str | None = None
|
|
@@ -72,7 +73,7 @@ class APIException(fastapi.exceptions.HTTPException):
|
|
|
72
73
|
self,
|
|
73
74
|
*,
|
|
74
75
|
status_code: int = starlette.status.HTTP_400_BAD_REQUEST,
|
|
75
|
-
error_code: str | None =
|
|
76
|
+
error_code: str | None = APIErrorCodes.unknown_error,
|
|
76
77
|
error_code_specification: str | None = None,
|
|
77
78
|
error_description: str | None = None,
|
|
78
79
|
error_data: dict[str, Any] | None = None
|
|
@@ -108,7 +109,7 @@ def from_exception_to_api_json_response(
|
|
|
108
109
|
) -> APIJSONResponse:
|
|
109
110
|
easy_api_error_so = APIErrorSO(
|
|
110
111
|
has_error=True,
|
|
111
|
-
error_code=
|
|
112
|
+
error_code=APIErrorCodes.unknown_error
|
|
112
113
|
)
|
|
113
114
|
|
|
114
115
|
status_code = starlette.status.HTTP_500_INTERNAL_SERVER_ERROR
|
|
@@ -119,11 +120,11 @@ def from_exception_to_api_json_response(
|
|
|
119
120
|
elif isinstance(exception, starlette.exceptions.HTTPException):
|
|
120
121
|
status_code = exception.status_code
|
|
121
122
|
if status_code in (starlette.status.HTTP_403_FORBIDDEN, starlette.status.HTTP_401_UNAUTHORIZED):
|
|
122
|
-
easy_api_error_so.error_code =
|
|
123
|
+
easy_api_error_so.error_code = APIErrorCodes.cannot_authorize
|
|
123
124
|
elif status_code == starlette.status.HTTP_404_NOT_FOUND:
|
|
124
|
-
easy_api_error_so.error_code =
|
|
125
|
+
easy_api_error_so.error_code = APIErrorCodes.not_found
|
|
125
126
|
else:
|
|
126
|
-
easy_api_error_so.error_code =
|
|
127
|
+
easy_api_error_so.error_code = APIErrorCodes.unknown_error
|
|
127
128
|
if (
|
|
128
129
|
isinstance(exception.detail, dict)
|
|
129
130
|
or isinstance(exception.detail, list)
|
|
@@ -136,12 +137,12 @@ def from_exception_to_api_json_response(
|
|
|
136
137
|
|
|
137
138
|
elif isinstance(exception, fastapi.exceptions.RequestValidationError):
|
|
138
139
|
status_code = starlette.status.HTTP_422_UNPROCESSABLE_ENTITY
|
|
139
|
-
easy_api_error_so.error_code =
|
|
140
|
+
easy_api_error_so.error_code = APIErrorCodes.error_in_request
|
|
140
141
|
easy_api_error_so.error_data["raw"] = str(exception.errors()) if exception.errors() else {}
|
|
141
142
|
|
|
142
143
|
else:
|
|
143
144
|
status_code = starlette.status.HTTP_500_INTERNAL_SERVER_ERROR
|
|
144
|
-
easy_api_error_so.error_code =
|
|
145
|
+
easy_api_error_so.error_code = APIErrorCodes.unknown_error
|
|
145
146
|
easy_api_error_so.error_data["raw"] = str(exception)
|
|
146
147
|
_logger.exception(exception)
|
|
147
148
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Any
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
|
|
5
|
+
from sqlalchemy import inspect, INTEGER, TEXT, TIMESTAMP
|
|
6
|
+
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
7
|
+
|
|
8
|
+
from arpakitlib.ar_datetime_util import now_utc_dt
|
|
9
|
+
from arpakitlib.ar_json_util import safely_transfer_to_json_str
|
|
10
|
+
|
|
11
|
+
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class BaseDBM(DeclarativeBase):
|
|
15
|
+
__abstract__ = True
|
|
16
|
+
_bus_data: dict[str, Any] | None = None
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def bus_data(self) -> dict[str, Any]:
|
|
20
|
+
if self._bus_data is None:
|
|
21
|
+
self._bus_data = {}
|
|
22
|
+
return self._bus_data
|
|
23
|
+
|
|
24
|
+
def simple_dict(self) -> dict[str, Any]:
|
|
25
|
+
return {c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs}
|
|
26
|
+
|
|
27
|
+
def simple_json(self) -> str:
|
|
28
|
+
return safely_transfer_to_json_str(self.simple_dict())
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class SimpleDBM(BaseDBM):
|
|
32
|
+
__abstract__ = True
|
|
33
|
+
|
|
34
|
+
id: Mapped[int] = mapped_column(
|
|
35
|
+
INTEGER, primary_key=True, autoincrement=True, nullable=False
|
|
36
|
+
)
|
|
37
|
+
long_id: Mapped[str] = mapped_column(
|
|
38
|
+
TEXT, insert_default=uuid4, unique=True, nullable=False
|
|
39
|
+
)
|
|
40
|
+
creation_dt: Mapped[datetime] = mapped_column(
|
|
41
|
+
TIMESTAMP(timezone=True), insert_default=now_utc_dt, index=True, nullable=False
|
|
42
|
+
)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/redoc/redoc.standalone.js
RENAMED
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/favicon-16x16.png
RENAMED
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/favicon-32x32.png
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/oauth2-redirect.html
RENAMED
|
File without changes
|
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui-bundle.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css
RENAMED
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map
RENAMED
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js
RENAMED
|
File without changes
|
{arpakitlib-1.5.18 → arpakitlib-1.5.20}/arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map
RENAMED
|
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
|
|
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
|