ezKit 3.0.44__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.44/ezKit.egg-info → ezkit-3.0.45}/PKG-INFO +1 -1
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/cipher.py +0 -31
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/utils.py +35 -0
- {ezkit-3.0.44 → ezkit-3.0.45/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.44 → ezkit-3.0.45}/setup.py +1 -1
- {ezkit-3.0.44 → ezkit-3.0.45}/LICENSE +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/MANIFEST.in +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/README.md +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/__init__.py +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/database.py +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/fastapix.py +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/http.py +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/markdown_to_html.template +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/markdownx.py +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/sendemail.py +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit/stock.py +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/pyproject.toml +0 -0
- {ezkit-3.0.44 → ezkit-3.0.45}/setup.cfg +0 -0
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import base64
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from os import environ, urandom
|
|
6
|
-
from secrets import choice
|
|
7
6
|
from typing import Any, Optional
|
|
8
7
|
|
|
9
8
|
import orjson
|
|
@@ -14,39 +13,9 @@ from loguru import logger
|
|
|
14
13
|
|
|
15
14
|
DEBUG = bool(environ.get("DEBUG"))
|
|
16
15
|
|
|
17
|
-
_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
18
|
-
|
|
19
16
|
_SERIALIZED_PREFIX = b"\xffEZK1"
|
|
20
17
|
|
|
21
18
|
|
|
22
|
-
def generate_random_id(alphabet: str = _ALPHABET, size: int = 12) -> str | None:
|
|
23
|
-
"""Generate a cryptographically random ID from a unique alphabet"""
|
|
24
|
-
|
|
25
|
-
# 基于唯一字符集生成密码学安全的随机 ID
|
|
26
|
-
# 用于生成唯一短码
|
|
27
|
-
|
|
28
|
-
try:
|
|
29
|
-
|
|
30
|
-
if not isinstance(alphabet, str) or not isinstance(size, int):
|
|
31
|
-
return None
|
|
32
|
-
|
|
33
|
-
size = 12 if size < 1 else size
|
|
34
|
-
|
|
35
|
-
if len(alphabet) < 2 or len(set(alphabet)) != len(alphabet):
|
|
36
|
-
alphabet = _ALPHABET
|
|
37
|
-
|
|
38
|
-
return "".join(choice(alphabet) for _ in range(size))
|
|
39
|
-
|
|
40
|
-
except Exception as e:
|
|
41
|
-
|
|
42
|
-
if DEBUG:
|
|
43
|
-
logger.exception(e)
|
|
44
|
-
else:
|
|
45
|
-
logger.error(e)
|
|
46
|
-
|
|
47
|
-
return None
|
|
48
|
-
|
|
49
|
-
|
|
50
19
|
@dataclass
|
|
51
20
|
class AESCipher:
|
|
52
21
|
"""
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|