python3-commons 0.9.19__py3-none-any.whl → 0.9.21__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.
Potentially problematic release.
This version of python3-commons might be problematic. Click here for more details.
- python3_commons/audit.py +2 -2
- python3_commons/auth.py +5 -5
- python3_commons/cache.py +22 -22
- python3_commons/db/__init__.py +3 -3
- python3_commons/helpers.py +2 -2
- python3_commons/object_storage.py +8 -9
- {python3_commons-0.9.19.dist-info → python3_commons-0.9.21.dist-info}/METADATA +2 -2
- {python3_commons-0.9.19.dist-info → python3_commons-0.9.21.dist-info}/RECORD +12 -12
- {python3_commons-0.9.19.dist-info → python3_commons-0.9.21.dist-info}/WHEEL +0 -0
- {python3_commons-0.9.19.dist-info → python3_commons-0.9.21.dist-info}/licenses/AUTHORS.rst +0 -0
- {python3_commons-0.9.19.dist-info → python3_commons-0.9.21.dist-info}/licenses/LICENSE +0 -0
- {python3_commons-0.9.19.dist-info → python3_commons-0.9.21.dist-info}/top_level.txt +0 -0
python3_commons/audit.py
CHANGED
|
@@ -143,8 +143,8 @@ async def write_audit_data(settings: S3Settings, key: str, data: bytes):
|
|
|
143
143
|
absolute_path = object_storage.get_absolute_path(f'audit/{key}')
|
|
144
144
|
|
|
145
145
|
await object_storage.put_object(settings.s3_bucket, absolute_path, io.BytesIO(data), len(data))
|
|
146
|
-
except Exception
|
|
147
|
-
logger.
|
|
146
|
+
except Exception:
|
|
147
|
+
logger.exception('Failed storing object in storage.')
|
|
148
148
|
else:
|
|
149
149
|
logger.debug(f'Stored object in storage: {key}')
|
|
150
150
|
else:
|
python3_commons/auth.py
CHANGED
|
@@ -78,11 +78,11 @@ def get_token_verifier[T](
|
|
|
78
78
|
payload = jwt.decode(token, jwks, algorithms=['RS256'])
|
|
79
79
|
|
|
80
80
|
token_data = token_cls(**payload)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
except jwt.ExpiredSignatureError:
|
|
84
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail='Token has expired')
|
|
81
|
+
except jwt.ExpiredSignatureError as e:
|
|
82
|
+
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail='Token has expired') from e
|
|
85
83
|
except JWTError as e:
|
|
86
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail=f'Token is invalid: {str(e)}')
|
|
84
|
+
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail=f'Token is invalid: {str(e)}') from e
|
|
85
|
+
|
|
86
|
+
return token_data
|
|
87
87
|
|
|
88
88
|
return get_verified_token
|
python3_commons/cache.py
CHANGED
|
@@ -131,8 +131,8 @@ async def store_sequence(name: str, data: Sequence, ttl: int = None):
|
|
|
131
131
|
|
|
132
132
|
if ttl:
|
|
133
133
|
await r.expire(name, ttl)
|
|
134
|
-
except valkey.exceptions.ConnectionError
|
|
135
|
-
logger.
|
|
134
|
+
except valkey.exceptions.ConnectionError:
|
|
135
|
+
logger.exception('Failed to store sequence in cache.')
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
async def get_sequence(name: str, _type: type = list) -> Sequence:
|
|
@@ -151,8 +151,8 @@ async def store_dict(name: str, data: Mapping, ttl: int = None):
|
|
|
151
151
|
|
|
152
152
|
if ttl:
|
|
153
153
|
await r.expire(name, ttl)
|
|
154
|
-
except valkey.exceptions.ConnectionError
|
|
155
|
-
logger.
|
|
154
|
+
except valkey.exceptions.ConnectionError:
|
|
155
|
+
logger.exception('Failed to store dict in cache.')
|
|
156
156
|
|
|
157
157
|
|
|
158
158
|
async def get_dict(name: str, value_data_type=None) -> dict | None:
|
|
@@ -175,8 +175,8 @@ async def set_dict(name: str, mapping: dict, ttl: int = None):
|
|
|
175
175
|
|
|
176
176
|
if ttl:
|
|
177
177
|
await r.expire(name, ttl)
|
|
178
|
-
except valkey.exceptions.ConnectionError
|
|
179
|
-
logger.
|
|
178
|
+
except valkey.exceptions.ConnectionError:
|
|
179
|
+
logger.exception('Failed to set dict in cache.')
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
async def get_dict_item(name: str, key: str, data_type=None, default=None):
|
|
@@ -185,28 +185,28 @@ async def get_dict_item(name: str, key: str, data_type=None, default=None):
|
|
|
185
185
|
|
|
186
186
|
if data := await r.hget(name, key):
|
|
187
187
|
return deserialize_msgpack_native(data, data_type)
|
|
188
|
+
except valkey.exceptions.ConnectionError:
|
|
189
|
+
logger.exception('Failed to get dict item from cache.')
|
|
188
190
|
|
|
189
|
-
return
|
|
190
|
-
except valkey.exceptions.ConnectionError as e:
|
|
191
|
-
logger.error(f'Failed to get dict item from cache: {e}')
|
|
191
|
+
return None
|
|
192
192
|
|
|
193
|
-
return
|
|
193
|
+
return default
|
|
194
194
|
|
|
195
195
|
|
|
196
196
|
async def set_dict_item(name: str, key: str, obj: Any):
|
|
197
197
|
try:
|
|
198
198
|
r = get_valkey_client()
|
|
199
199
|
await r.hset(name, key, serialize_msgpack_native(obj))
|
|
200
|
-
except valkey.exceptions.ConnectionError
|
|
201
|
-
logger.
|
|
200
|
+
except valkey.exceptions.ConnectionError:
|
|
201
|
+
logger.exception('Failed to set dict item in cache.')
|
|
202
202
|
|
|
203
203
|
|
|
204
204
|
async def delete_dict_item(name: str, *keys):
|
|
205
205
|
try:
|
|
206
206
|
r = get_valkey_client()
|
|
207
207
|
await r.hdel(name, *keys)
|
|
208
|
-
except valkey.exceptions.ConnectionError
|
|
209
|
-
logger.
|
|
208
|
+
except valkey.exceptions.ConnectionError:
|
|
209
|
+
logger.exception('Failed to delete dict item from cache.')
|
|
210
210
|
|
|
211
211
|
|
|
212
212
|
async def store_set(name: str, value: set, ttl: int = None):
|
|
@@ -216,8 +216,8 @@ async def store_set(name: str, value: set, ttl: int = None):
|
|
|
216
216
|
|
|
217
217
|
if ttl:
|
|
218
218
|
await r.expire(name, ttl)
|
|
219
|
-
except valkey.exceptions.ConnectionError
|
|
220
|
-
logger.
|
|
219
|
+
except valkey.exceptions.ConnectionError:
|
|
220
|
+
logger.exception('Failed to store set in cache.')
|
|
221
221
|
|
|
222
222
|
|
|
223
223
|
async def has_set_item(name: str, value: str) -> bool:
|
|
@@ -225,8 +225,8 @@ async def has_set_item(name: str, value: str) -> bool:
|
|
|
225
225
|
r = get_valkey_client()
|
|
226
226
|
|
|
227
227
|
return await r.sismember(name, serialize_msgpack_native(value)) == 1
|
|
228
|
-
except valkey.exceptions.ConnectionError
|
|
229
|
-
logger.
|
|
228
|
+
except valkey.exceptions.ConnectionError:
|
|
229
|
+
logger.exception('Failed to check if set has item in cache.')
|
|
230
230
|
|
|
231
231
|
return False
|
|
232
232
|
|
|
@@ -235,8 +235,8 @@ async def add_set_item(name: str, *values: str):
|
|
|
235
235
|
try:
|
|
236
236
|
r = get_valkey_client()
|
|
237
237
|
await r.sadd(name, *map(serialize_msgpack_native, values))
|
|
238
|
-
except valkey.exceptions.ConnectionError
|
|
239
|
-
logger.
|
|
238
|
+
except valkey.exceptions.ConnectionError:
|
|
239
|
+
logger.exception('Failed to add set item into cache.')
|
|
240
240
|
|
|
241
241
|
|
|
242
242
|
async def delete_set_item(name: str, value: str):
|
|
@@ -250,8 +250,8 @@ async def get_set_members(name: str) -> set[str] | None:
|
|
|
250
250
|
smembers = await r.smembers(name)
|
|
251
251
|
|
|
252
252
|
return set(map(deserialize_msgpack_native, smembers))
|
|
253
|
-
except valkey.exceptions.ConnectionError
|
|
254
|
-
logger.
|
|
253
|
+
except valkey.exceptions.ConnectionError:
|
|
254
|
+
logger.exception('Failed to get set members from cache.')
|
|
255
255
|
|
|
256
256
|
return None
|
|
257
257
|
|
python3_commons/db/__init__.py
CHANGED
|
@@ -24,7 +24,7 @@ class AsyncSessionManager:
|
|
|
24
24
|
try:
|
|
25
25
|
return self.db_settings[name]
|
|
26
26
|
except KeyError:
|
|
27
|
-
logger.
|
|
27
|
+
logger.exception(f'Missing database settings: {name}')
|
|
28
28
|
|
|
29
29
|
raise
|
|
30
30
|
|
|
@@ -83,7 +83,7 @@ async def is_healthy(engine: AsyncEngine) -> bool:
|
|
|
83
83
|
result = await conn.execute('SELECT 1;')
|
|
84
84
|
|
|
85
85
|
return result.scalar() == 1
|
|
86
|
-
except Exception
|
|
87
|
-
logger.
|
|
86
|
+
except Exception:
|
|
87
|
+
logger.exception('Database connection is not healthy.')
|
|
88
88
|
|
|
89
89
|
return False
|
python3_commons/helpers.py
CHANGED
|
@@ -67,14 +67,13 @@ async def put_object(bucket_name: str, path: str, data: io.BytesIO, length: int,
|
|
|
67
67
|
await s3_client.put_object(Bucket=bucket_name, Key=path, Body=data, ContentLength=length)
|
|
68
68
|
|
|
69
69
|
logger.debug(f'Stored object into object storage: {bucket_name}:{path}')
|
|
70
|
-
|
|
71
|
-
return f's3://{bucket_name}/{path}'
|
|
72
|
-
|
|
73
70
|
except Exception as e:
|
|
74
|
-
logger.
|
|
71
|
+
logger.exception(f'Failed to put object to object storage: {bucket_name}:{path}', exc_info=e)
|
|
75
72
|
|
|
76
73
|
raise
|
|
77
74
|
|
|
75
|
+
return f's3://{bucket_name}/{path}'
|
|
76
|
+
|
|
78
77
|
|
|
79
78
|
@asynccontextmanager
|
|
80
79
|
async def get_object_stream(bucket_name: str, path: str) -> AsyncGenerator[StreamingBody]:
|
|
@@ -89,7 +88,7 @@ async def get_object_stream(bucket_name: str, path: str) -> AsyncGenerator[Strea
|
|
|
89
88
|
async with response['Body'] as stream:
|
|
90
89
|
yield stream
|
|
91
90
|
except Exception as e:
|
|
92
|
-
logger.
|
|
91
|
+
logger.exception(f'Failed getting object from object storage: {bucket_name}:{path}', exc_info=e)
|
|
93
92
|
|
|
94
93
|
raise
|
|
95
94
|
|
|
@@ -145,7 +144,7 @@ async def remove_object(bucket_name: str, object_name: str):
|
|
|
145
144
|
await s3_client.delete_object(Bucket=bucket_name, Key=object_name)
|
|
146
145
|
logger.debug(f'Removed object from object storage: {bucket_name}:{object_name}')
|
|
147
146
|
except Exception as e:
|
|
148
|
-
logger.
|
|
147
|
+
logger.exception(f'Failed to remove object from object storage: {bucket_name}:{object_name}', exc_info=e)
|
|
149
148
|
|
|
150
149
|
raise
|
|
151
150
|
|
|
@@ -182,9 +181,9 @@ async def remove_objects(
|
|
|
182
181
|
errors.extend(response['Errors'])
|
|
183
182
|
|
|
184
183
|
logger.debug(f'Removed {len(objects_to_delete)} objects from object storage: {bucket_name}')
|
|
185
|
-
|
|
186
|
-
return errors if errors else None
|
|
187
184
|
except Exception as e:
|
|
188
|
-
logger.
|
|
185
|
+
logger.exception(f'Failed to remove objects from object storage: {bucket_name}', exc_info=e)
|
|
189
186
|
|
|
190
187
|
raise
|
|
188
|
+
|
|
189
|
+
return errors if errors else None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python3-commons
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.21
|
|
4
4
|
Summary: Re-usable Python3 code
|
|
5
5
|
Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0
|
|
@@ -21,7 +21,7 @@ Requires-Dist: lxml~=6.0.2
|
|
|
21
21
|
Requires-Dist: msgpack~=1.1.1
|
|
22
22
|
Requires-Dist: msgspec~=0.19.0
|
|
23
23
|
Requires-Dist: pydantic[email]~=2.11.9
|
|
24
|
-
Requires-Dist: pydantic-settings~=2.
|
|
24
|
+
Requires-Dist: pydantic-settings~=2.11.0
|
|
25
25
|
Requires-Dist: python-jose==3.5.0
|
|
26
26
|
Requires-Dist: SQLAlchemy[asyncio]~=2.0.43
|
|
27
27
|
Requires-Dist: valkey[libvalkey]~=6.1.1
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
python3_commons/__init__.py,sha256=0KgaYU46H_IMKn-BuasoRN3C4Hi45KlkHHoPbU9cwiA,189
|
|
2
2
|
python3_commons/api_client.py,sha256=0PE8iYW5zq7n89veC6afSkwj_fzD_nldBc5wdXyg5jo,5266
|
|
3
|
-
python3_commons/audit.py,sha256=
|
|
4
|
-
python3_commons/auth.py,sha256=
|
|
5
|
-
python3_commons/cache.py,sha256=
|
|
3
|
+
python3_commons/audit.py,sha256=kfUaSiNAg9NJuUhnBXqplNiyuPQuDFM9NcD-HZV2qd4,6077
|
|
4
|
+
python3_commons/auth.py,sha256=fWfoh5665F-YnGTgG9wDAosYIM9vFoTsQXEcCyzD72M,2951
|
|
5
|
+
python3_commons/cache.py,sha256=Hib86F1k1SviF-a2RyoTxRrFi0XV2KaWOfBi5TlOu-g,7697
|
|
6
6
|
python3_commons/conf.py,sha256=GOvR1oYss6AKnNlyj9JbT0mSrfQFrnzmgm0IiGVahho,2428
|
|
7
7
|
python3_commons/fs.py,sha256=dn8ZcwsQf9xcAEg6neoxLN6IzJbWpprfm8wV8S55BL0,337
|
|
8
|
-
python3_commons/helpers.py,sha256=
|
|
9
|
-
python3_commons/object_storage.py,sha256=
|
|
8
|
+
python3_commons/helpers.py,sha256=utcorGvXvZLsC4H_H8WGwzeIMgCOCHac2jbKpVCeixA,3928
|
|
9
|
+
python3_commons/object_storage.py,sha256=pvA-gJehnbIJmqu8ebT6oSqW-dR-uZl3E1AV86ffUpY,6568
|
|
10
10
|
python3_commons/permissions.py,sha256=bhjTp-tq-oaTGFMHNnSBlcVX5XQCTL0nWcu6SdPEAB4,1555
|
|
11
|
-
python3_commons/db/__init__.py,sha256=
|
|
11
|
+
python3_commons/db/__init__.py,sha256=PZTIC0RPzYzZ2Fh4HeyKtYIHaUPB7A92yeOK--PGxnw,2942
|
|
12
12
|
python3_commons/db/helpers.py,sha256=n56yYCE0fvzvU7nL1936NfZhbaQmvfumzRsGimBlNV4,1776
|
|
13
13
|
python3_commons/db/models/__init__.py,sha256=zjZCf0DNDkqmPZ49quJ6KZohtKH87viI_ijDG3E0PVE,554
|
|
14
14
|
python3_commons/db/models/auth.py,sha256=NMHirujigpaRR0Bhhe2gzy8Q8PPABuaA-D8ZY7aaqeE,1177
|
|
@@ -22,9 +22,9 @@ python3_commons/serializers/common.py,sha256=VkA7C6wODvHk0QBXVX_x2JieDstihx3U__U
|
|
|
22
22
|
python3_commons/serializers/json.py,sha256=Dae0gouk9jiUOkmh8z1AcTIHD52OgBn2aXK9JLKMMms,718
|
|
23
23
|
python3_commons/serializers/msgpack.py,sha256=AwzBSUdbdq8yYdGzmEsiWw0bnL9XRQFa1Vh-nt2s56k,1499
|
|
24
24
|
python3_commons/serializers/msgspec.py,sha256=yp3LvsxDUTIv__3AaLed5ddZ0rHm7BYqmrrehVAJb14,3000
|
|
25
|
-
python3_commons-0.9.
|
|
26
|
-
python3_commons-0.9.
|
|
27
|
-
python3_commons-0.9.
|
|
28
|
-
python3_commons-0.9.
|
|
29
|
-
python3_commons-0.9.
|
|
30
|
-
python3_commons-0.9.
|
|
25
|
+
python3_commons-0.9.21.dist-info/licenses/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
|
|
26
|
+
python3_commons-0.9.21.dist-info/licenses/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
|
|
27
|
+
python3_commons-0.9.21.dist-info/METADATA,sha256=HRjkBEmKZRPPU7PU1T3XZtXWkYnEM2tFQUmOz9IxEfw,1134
|
|
28
|
+
python3_commons-0.9.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
29
|
+
python3_commons-0.9.21.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
|
|
30
|
+
python3_commons-0.9.21.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|