arpakitlib 1.7.71__py3-none-any.whl → 1.7.73__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.
@@ -25,7 +25,7 @@ from starlette import status
25
25
  from starlette.middleware.cors import CORSMiddleware
26
26
  from starlette.staticfiles import StaticFiles
27
27
 
28
- from arpakitlib.ar_base_worker_util import BaseWorker
28
+ from arpakitlib.ar_base_worker_util import BaseWorker, safe_run_worker_in_background, SafeRunInBackgroundModes
29
29
  from arpakitlib.ar_dict_util import combine_dicts
30
30
  from arpakitlib.ar_enumeration_util import Enumeration
31
31
  from arpakitlib.ar_file_storage_in_dir_util import FileStorageInDir
@@ -110,11 +110,23 @@ class OperationSO(SimpleSO):
110
110
 
111
111
 
112
112
  class APIJSONResponse(fastapi.responses.JSONResponse):
113
- def __init__(self, *, content: BaseSO, status_code: int = starlette.status.HTTP_200_OK):
113
+ def __init__(self, *, content: dict | list | BaseSO | None, status_code: int = starlette.status.HTTP_200_OK):
114
+ if isinstance(content, dict):
115
+ content = safely_transfer_to_json_str_to_json_obj(content)
116
+ elif isinstance(content, list):
117
+ content = safely_transfer_to_json_str_to_json_obj(content)
118
+ elif isinstance(content, BaseSO):
119
+ content = safely_transfer_to_json_str_to_json_obj(content.model_dump())
120
+ elif content is None:
121
+ content = None
122
+ else:
123
+ raise ValueError(f"unknown content type, type(content)={type(content)}")
124
+
114
125
  self.content_ = content
115
126
  self.status_code_ = status_code
127
+
116
128
  super().__init__(
117
- content=safely_transfer_to_json_str_to_json_obj(content.model_dump()),
129
+ content=content,
118
130
  status_code=status_code
119
131
  )
120
132
 
@@ -225,6 +237,9 @@ def create_handle_exception(
225
237
  if error_so.error_code == BaseAPIErrorCodes.not_found:
226
238
  status_code = status.HTTP_404_NOT_FOUND
227
239
 
240
+ if error_so.error_code == BaseAPIErrorCodes.cannot_authorize:
241
+ status_code = status.HTTP_401_UNAUTHORIZED
242
+
228
243
  if _need_exc_info:
229
244
  _logger.error(str(exception), exc_info=exception)
230
245
  else:
@@ -424,7 +439,7 @@ class SafeRunWorkerStartupAPIEvent(BaseStartupAPIEvent):
424
439
 
425
440
  async def async_on_startup(self, *args, **kwargs):
426
441
  for worker in self.workers:
427
- _ = worker.safe_run_in_background(safe_run_in_background_mode=self.safe_run_in_background_mode)
442
+ _ = safe_run_worker_in_background(worker=worker, mode=SafeRunInBackgroundModes.async_task)
428
443
 
429
444
 
430
445
  class InitFileStoragesInDir(BaseStartupAPIEvent):
@@ -136,12 +136,6 @@ class BaseOperationExecutor:
136
136
  elif operation_dbm.type == BaseOperationTypes.raise_fake_exception_:
137
137
  self._logger.info("raise_fake_exception")
138
138
  raise Exception("raise_fake_exception")
139
- else:
140
- raise Exception(
141
- f"unknown operation_dbm.type,"
142
- f" operation_dbm.id={operation_dbm.id},"
143
- f" operation_dbm.type={operation_dbm.type}"
144
- )
145
139
  return operation_dbm
146
140
 
147
141
  def sync_safe_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
@@ -225,12 +219,6 @@ class BaseOperationExecutor:
225
219
  elif operation_dbm.type == BaseOperationTypes.raise_fake_exception_:
226
220
  self._logger.info("raise_fake_exception")
227
221
  raise Exception("raise_fake_exception")
228
- else:
229
- raise Exception(
230
- f"unknown operation_dbm.type,"
231
- f" operation_dbm.id={operation_dbm.id},"
232
- f" operation_dbm.type={operation_dbm.type}"
233
- )
234
222
  return operation_dbm
235
223
 
236
224
  async def async_safe_execute_operation(self, operation_dbm: OperationDBM) -> OperationDBM:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: arpakitlib
3
- Version: 1.7.71
3
+ Version: 1.7.73
4
4
  Summary: arpakitlib
5
5
  Home-page: https://github.com/ARPAKIT-Company/arpakitlib
6
6
  License: Apache-2.0
@@ -148,7 +148,7 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
148
148
  arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
149
149
  arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
150
150
  arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
151
- arpakitlib/ar_fastapi_util.py,sha256=7NcRLArsrZgzihbDLWzI9JAH8i2SKwPwig8UdANq-jw,24700
151
+ arpakitlib/ar_fastapi_util.py,sha256=UstW6ivH_sRXyREnl8OsImqOmFggmDH4MYMl0YGMc7Q,25349
152
152
  arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
153
153
  arpakitlib/ar_file_util.py,sha256=GUdJYm1tUZnYpY-SIPRHAZBHGra8NKy1eYEI0D5AfhY,489
154
154
  arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
@@ -163,7 +163,7 @@ arpakitlib/ar_logging_util.py,sha256=mx3H6CzX9dsh29ruFmYnva8lL6mwvdBXmeHH9E2tvu8
163
163
  arpakitlib/ar_mongodb_util.py,sha256=2ECkTnGAZ92qxioL-fmN6R4yZOSr3bXdXLWTzT1C3vk,4038
164
164
  arpakitlib/ar_need_type_util.py,sha256=GETiREPMEYhch-yU6T--Bdawlbb04Jp1Qy7cOsUlIeA,2228
165
165
  arpakitlib/ar_openai_api_client_util.py,sha256=_XmlApvHFMSyjvZydPa_kASIt9LsFrZmSC7YEzIG8Bg,1806
166
- arpakitlib/ar_operation_execution_util.py,sha256=F3gX2ZaR-tMFEKjVptpmX2kBTwtyr9Wfp9qNS0DR0Gk,18049
166
+ arpakitlib/ar_operation_execution_util.py,sha256=io0y9h1EX5zs4LndLkgLaBNpdPslvR4eFZUlp-SNwJ0,17607
167
167
  arpakitlib/ar_parse_command.py,sha256=-s61xcATIsfw1eV_iD3xi-grsitbGzSDoAFc5V0OFy4,3447
168
168
  arpakitlib/ar_postgresql_util.py,sha256=1AuLjEaa1Lg4pzn-ukCVnDi35Eg1k91APRTqZhIJAdo,945
169
169
  arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
@@ -177,9 +177,9 @@ arpakitlib/ar_str_util.py,sha256=tFoGSDYoGpfdVHWor5Li9pEOFmDFlHkX-Z8iOy1LK7Y,353
177
177
  arpakitlib/ar_type_util.py,sha256=46ZMuWls3uN0Re5T0sfEAmyNUDnxn9yvj6dHivSDZKs,3915
178
178
  arpakitlib/ar_yookassa_api_client_util.py,sha256=sh4fcUkAkdOetFn9JYoTvjcSXP-M1wU04KEY-ECLfLg,5137
179
179
  arpakitlib/ar_zabbix_api_client_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
180
- arpakitlib-1.7.71.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
181
- arpakitlib-1.7.71.dist-info/METADATA,sha256=qnzJ63_6S3mfsYCd1NzDVXVh8brXxO9JAvpW_sS0KCI,2824
182
- arpakitlib-1.7.71.dist-info/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
183
- arpakitlib-1.7.71.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
184
- arpakitlib-1.7.71.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
185
- arpakitlib-1.7.71.dist-info/RECORD,,
180
+ arpakitlib-1.7.73.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
181
+ arpakitlib-1.7.73.dist-info/METADATA,sha256=UZrOUY7CneX39dLf-oXrO3md1TeMvDTHJuqRM4w1e2I,2824
182
+ arpakitlib-1.7.73.dist-info/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
183
+ arpakitlib-1.7.73.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
184
+ arpakitlib-1.7.73.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
185
+ arpakitlib-1.7.73.dist-info/RECORD,,