ezKit 3.0.2__tar.gz → 3.0.3__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.2
3
+ Version: 3.0.3
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -1,8 +1,10 @@
1
1
  """Utils Library"""
2
2
 
3
+ import time
4
+ from functools import wraps
3
5
  from os import environ
4
6
  from pathlib import Path
5
- from typing import Any
7
+ from typing import Any, Callable, ParamSpec, TypeVar
6
8
 
7
9
  from loguru import logger
8
10
 
@@ -59,6 +61,40 @@ def isTrue(target: object, typeClass: Any) -> bool:
59
61
  # --------------------------------------------------------------------------------------------------
60
62
 
61
63
 
64
+ P = ParamSpec("P")
65
+ R = TypeVar("R")
66
+
67
+
68
+ def retry_decorator(times: int = 3, delay: float = 1.0):
69
+ """重试装饰器"""
70
+
71
+ def decorator(func: Callable[P, R]) -> Callable[P, R | bool]:
72
+ @wraps(func)
73
+ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R | bool:
74
+ max_times = max(1, times)
75
+ for attempt in range(max_times):
76
+ try:
77
+ return func(*args, **kwargs)
78
+ except Exception as e:
79
+ if DEBUG:
80
+ logger.exception(e)
81
+ else:
82
+ logger.error(e)
83
+
84
+ if attempt < (max_times - 1):
85
+ time.sleep(delay)
86
+ else:
87
+ return False
88
+ return False
89
+
90
+ return wrapper
91
+
92
+ return decorator
93
+
94
+
95
+ # --------------------------------------------------------------------------------------------------
96
+
97
+
62
98
  def check_path_type(path_object: str | Path, path_type: str) -> bool:
63
99
  """检查路径类型"""
64
100
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.2
3
+ Version: 3.0.3
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.2",
7
+ version="3.0.3",
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