ezKit 3.0.43__tar.gz → 3.0.45__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.
- {ezkit-3.0.43/ezKit.egg-info → ezkit-3.0.45}/PKG-INFO +1 -1
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/cipher.py +3 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/database.py +1 -1
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/fastapix.py +15 -11
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/http.py +1 -1
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/markdownx.py +2 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/sendemail.py +2 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/stock.py +1 -1
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/utils.py +36 -1
- {ezkit-3.0.43 → ezkit-3.0.45/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.43 → ezkit-3.0.45}/setup.py +1 -1
- {ezkit-3.0.43 → ezkit-3.0.45}/LICENSE +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/MANIFEST.in +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/README.md +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/__init__.py +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit/markdown_to_html.template +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.43 → ezkit-3.0.45}/pyproject.toml +1 -1
- {ezkit-3.0.43 → ezkit-3.0.45}/setup.cfg +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"""Cipher library"""
|
|
2
|
+
|
|
1
3
|
import base64
|
|
2
4
|
from dataclasses import dataclass
|
|
3
5
|
from os import environ, urandom
|
|
@@ -10,6 +12,7 @@ from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
|
|
10
12
|
from loguru import logger
|
|
11
13
|
|
|
12
14
|
DEBUG = bool(environ.get("DEBUG"))
|
|
15
|
+
|
|
13
16
|
_SERIALIZED_PREFIX = b"\xffEZK1"
|
|
14
17
|
|
|
15
18
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"""FastAPI extension"""
|
|
2
|
+
|
|
1
3
|
import logging
|
|
2
4
|
import sys
|
|
3
5
|
from collections.abc import Awaitable, Callable
|
|
@@ -94,26 +96,25 @@ def Response(code: int = 200, data: Any = None, message: str | None = None, stat
|
|
|
94
96
|
def exceptions(app: FastAPI):
|
|
95
97
|
|
|
96
98
|
@app.exception_handler(StarletteHTTPException)
|
|
97
|
-
async def http_exception_handler(request: Request, exc: StarletteHTTPException): # pylint: disable=
|
|
99
|
+
async def http_exception_handler(request: Request, exc: StarletteHTTPException): # pylint: disable=W0613
|
|
98
100
|
logger.warning(f"HTTP Exception: {exc.detail}")
|
|
99
101
|
return Response(code=exc.status_code, message=f"HTTP Exception: {exc.detail}", status_code=exc.status_code)
|
|
100
|
-
# return JSONResponse(content={"code": exc.status_code, "data": None, "message": exc.detail}, status_code=exc.status_code)
|
|
101
102
|
|
|
102
103
|
# 参数验证错误
|
|
103
104
|
@app.exception_handler(RequestValidationError)
|
|
104
|
-
async def validation_exception_handler(request: Request, exc: RequestValidationError): # pylint: disable=
|
|
105
|
+
async def validation_exception_handler(request: Request, exc: RequestValidationError): # pylint: disable=W0613
|
|
105
106
|
logger.warning(f"Request Validation Error: {exc.errors()}")
|
|
106
107
|
return Response(code=422, message=f"Request Validation Error: {exc.errors()}")
|
|
107
108
|
|
|
108
109
|
# 参数验证错误
|
|
109
110
|
@app.exception_handler(ValidationError)
|
|
110
|
-
async def pydantic_validation_error_handler(request: Request, exc: ValidationError): # pylint: disable=
|
|
111
|
+
async def pydantic_validation_error_handler(request: Request, exc: ValidationError): # # pylint: disable=W0613
|
|
111
112
|
logger.warning(f"Pydantic Validation Error: {exc.errors()}")
|
|
112
113
|
return Response(code=422, message=f"Pydantic Validation Error: {exc.errors()}")
|
|
113
114
|
|
|
114
115
|
# 内部服务错误
|
|
115
116
|
@app.exception_handler(Exception)
|
|
116
|
-
async def global_exception_handler(request: Request, exc: Exception): # pylint: disable=
|
|
117
|
+
async def global_exception_handler(request: Request, exc: Exception): # pylint: disable=W0613
|
|
117
118
|
logger.exception(f"Internal Server Error: {exc}")
|
|
118
119
|
return Response(code=500, message=f"Internal Server Error: {exc}")
|
|
119
120
|
|
|
@@ -145,7 +146,7 @@ async def generic_api_execute(
|
|
|
145
146
|
params_object: Any,
|
|
146
147
|
params_type: str = "text",
|
|
147
148
|
) -> JSONResponse:
|
|
148
|
-
"""
|
|
149
|
+
"""Generic API Execution"""
|
|
149
150
|
|
|
150
151
|
# param: operation 函数
|
|
151
152
|
# param: params_object 参数对象
|
|
@@ -207,7 +208,7 @@ async def generic_database_create(
|
|
|
207
208
|
model: type[DeclarativeBase],
|
|
208
209
|
params: dict[str, Any] | list[dict[str, Any]],
|
|
209
210
|
) -> dict | None:
|
|
210
|
-
"""
|
|
211
|
+
"""Generic Database Create"""
|
|
211
212
|
|
|
212
213
|
try:
|
|
213
214
|
|
|
@@ -238,7 +239,7 @@ async def generic_database_read(
|
|
|
238
239
|
model: type[DeclarativeBase],
|
|
239
240
|
params: dict[str, Any],
|
|
240
241
|
) -> list | None:
|
|
241
|
-
"""
|
|
242
|
+
"""Generic Database Read"""
|
|
242
243
|
|
|
243
244
|
try:
|
|
244
245
|
|
|
@@ -274,7 +275,7 @@ async def generic_database_update(
|
|
|
274
275
|
model: type[DeclarativeBase],
|
|
275
276
|
params: dict[str, Any] | list[dict[str, Any]],
|
|
276
277
|
) -> dict | None:
|
|
277
|
-
"""
|
|
278
|
+
"""Generic Database Update"""
|
|
278
279
|
|
|
279
280
|
try:
|
|
280
281
|
|
|
@@ -333,7 +334,7 @@ async def generic_database_delete(
|
|
|
333
334
|
model: type[DeclarativeBase],
|
|
334
335
|
params: dict[str, Any] | list[dict[str, Any]],
|
|
335
336
|
) -> dict | None:
|
|
336
|
-
"""
|
|
337
|
+
"""Generic Database Delete"""
|
|
337
338
|
|
|
338
339
|
try:
|
|
339
340
|
|
|
@@ -342,7 +343,10 @@ async def generic_database_delete(
|
|
|
342
343
|
if not conditions:
|
|
343
344
|
return {"count": 0}
|
|
344
345
|
|
|
345
|
-
filters = [
|
|
346
|
+
filters = [
|
|
347
|
+
and_(true(), *(getattr(model, key) == value for key, value in condition.items()))
|
|
348
|
+
for condition in conditions
|
|
349
|
+
]
|
|
346
350
|
|
|
347
351
|
stmt = delete(model).where(or_(*filters))
|
|
348
352
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Utils
|
|
1
|
+
"""Utils library"""
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import subprocess
|
|
@@ -11,6 +11,7 @@ from functools import wraps
|
|
|
11
11
|
from itertools import islice
|
|
12
12
|
from os import environ
|
|
13
13
|
from pathlib import Path
|
|
14
|
+
from secrets import choice
|
|
14
15
|
from typing import Any, Callable, Coroutine, ParamSpec, TypeVar
|
|
15
16
|
from uuid import UUID
|
|
16
17
|
|
|
@@ -603,3 +604,37 @@ def shell(
|
|
|
603
604
|
logger.error(e)
|
|
604
605
|
|
|
605
606
|
return None
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
# --------------------------------------------------------------------------------------------------
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
def generate_random_id(alphabet: str = _ALPHABET, size: int = 12) -> str | None:
|
|
616
|
+
"""Generate a cryptographically random ID from a unique alphabet"""
|
|
617
|
+
|
|
618
|
+
# 基于唯一字符集生成密码学安全的随机 ID
|
|
619
|
+
# 用于生成唯一短码
|
|
620
|
+
|
|
621
|
+
try:
|
|
622
|
+
|
|
623
|
+
if not isinstance(alphabet, str) or not isinstance(size, int):
|
|
624
|
+
return None
|
|
625
|
+
|
|
626
|
+
size = 12 if size < 1 else size
|
|
627
|
+
|
|
628
|
+
if len(alphabet) < 2 or len(set(alphabet)) != len(alphabet):
|
|
629
|
+
alphabet = _ALPHABET
|
|
630
|
+
|
|
631
|
+
return "".join(choice(alphabet) for _ in range(size))
|
|
632
|
+
|
|
633
|
+
except Exception as e:
|
|
634
|
+
|
|
635
|
+
if DEBUG:
|
|
636
|
+
logger.exception(e)
|
|
637
|
+
else:
|
|
638
|
+
logger.error(e)
|
|
639
|
+
|
|
640
|
+
return None
|
|
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
|