ezKit 3.0.3__tar.gz → 3.0.5__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.3
3
+ Version: 3.0.5
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -3,6 +3,9 @@
3
3
  Command:
4
4
 
5
5
  ```sh
6
+ # Clear cache
7
+ pip cache purge
8
+
6
9
  # Install or Update
7
10
  pip install -i https://pypi.org/simple --trusted-host pypi.org -U ezKit
8
11
  ```
@@ -14,11 +14,12 @@ from . import utils
14
14
  DEBUG = environ.get("DEBUG")
15
15
 
16
16
 
17
- class TypedSMTP(TypedDict):
17
+ class TypedSMTP(TypedDict, total=False):
18
18
  """smtp type"""
19
19
 
20
20
  server: str
21
21
  port: int
22
+ timeout: Optional[float]
22
23
  # tls: bool
23
24
 
24
25
 
@@ -120,6 +121,7 @@ async def sendemail(
120
121
 
121
122
  smtp_host = smtp.get("server")
122
123
  smtp_port = smtp.get("port")
124
+ smtp_timeout = smtp.get("timeout", 10.0)
123
125
  # smtp_tls = smtp.get("tls", False)
124
126
 
125
127
  if not smtp_host or not smtp_port:
@@ -178,7 +180,7 @@ async def sendemail(
178
180
  # ------------------------------------------------------------------------------------------
179
181
 
180
182
  # 使用 aiomail 发送邮件
181
- async with aiosmtplib.SMTP(hostname=smtp_host, port=smtp_port) as smtp_server:
183
+ async with aiosmtplib.SMTP(hostname=smtp_host, port=smtp_port, timeout=smtp_timeout) as smtp_server:
182
184
 
183
185
  # if smtp_tls:
184
186
  # await smtp_server.starttls()
@@ -1,10 +1,11 @@
1
1
  """Utils Library"""
2
2
 
3
+ import asyncio
3
4
  import time
4
5
  from functools import wraps
5
6
  from os import environ
6
7
  from pathlib import Path
7
- from typing import Any, Callable, ParamSpec, TypeVar
8
+ from typing import Any, Callable, Coroutine, ParamSpec, TypeVar
8
9
 
9
10
  from loguru import logger
10
11
 
@@ -66,16 +67,28 @@ R = TypeVar("R")
66
67
 
67
68
 
68
69
  def retry_decorator(times: int = 3, delay: float = 1.0):
69
- """重试装饰器"""
70
+ """重试装饰器
71
+
72
+ Args:
73
+ times: 最大重试次数
74
+ delay: 每次重试之间的等待时间(秒)
75
+ """
70
76
 
71
77
  def decorator(func: Callable[P, R]) -> Callable[P, R | bool]:
78
+
72
79
  @wraps(func)
73
80
  def wrapper(*args: P.args, **kwargs: P.kwargs) -> R | bool:
81
+
74
82
  max_times = max(1, times)
83
+
75
84
  for attempt in range(max_times):
85
+
76
86
  try:
87
+
77
88
  return func(*args, **kwargs)
89
+
78
90
  except Exception as e:
91
+
79
92
  if DEBUG:
80
93
  logger.exception(e)
81
94
  else:
@@ -85,6 +98,47 @@ def retry_decorator(times: int = 3, delay: float = 1.0):
85
98
  time.sleep(delay)
86
99
  else:
87
100
  return False
101
+
102
+ return False
103
+
104
+ return wrapper
105
+
106
+ return decorator
107
+
108
+
109
+ def async_retry_decorator(times: int = 3, delay: float = 1.0):
110
+ """异步重试装饰器
111
+
112
+ Args:
113
+ times: 最大重试次数
114
+ delay: 每次重试之间的等待时间(秒)
115
+ """
116
+
117
+ def decorator(func: Callable[P, Coroutine[Any, Any, R]]) -> Callable[P, Coroutine[Any, Any, R | bool]]:
118
+
119
+ @wraps(func)
120
+ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R | bool:
121
+
122
+ max_times = max(1, times)
123
+
124
+ for attempt in range(max_times):
125
+
126
+ try:
127
+
128
+ return await func(*args, **kwargs)
129
+
130
+ except Exception as e:
131
+
132
+ if DEBUG:
133
+ logger.exception(e)
134
+ else:
135
+ logger.error(e)
136
+
137
+ if attempt < (max_times - 1):
138
+ await asyncio.sleep(delay)
139
+ else:
140
+ return False
141
+
88
142
  return False
89
143
 
90
144
  return wrapper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.3
3
+ Version: 3.0.5
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.3",
7
+ version="3.0.5",
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