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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.44
3
+ Version: 3.0.45
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.44
3
+ Version: 3.0.45
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
 
5
5
  setup(
6
6
  name="ezKit",
7
- version="3.0.44",
7
+ version="3.0.45",
8
8
  author="septvean",
9
9
  author_email="septvean@gmail.com",
10
10
  description="Easy Kit",
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