完成 Ruff 全量清理
This commit is contained in:
@@ -5,7 +5,7 @@ import os
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import requests
|
||||
from loguru import logger
|
||||
@@ -68,8 +68,8 @@ class EmailVerifier:
|
||||
f"{self.roundcube_url}?_task=logout",
|
||||
timeout=5,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.debug(f"Roundcube logout failed: {exc}")
|
||||
self._rc_session = None
|
||||
self._rc_logged_in = False
|
||||
|
||||
@@ -176,7 +176,7 @@ class EmailVerifier:
|
||||
logger.debug(f"Roundcube: {password_name}登录成功 ({self.username})")
|
||||
return True, False
|
||||
|
||||
except Exception as e:
|
||||
except Exception as e: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
|
||||
logger.warning(f"Roundcube: 登录异常: {e}")
|
||||
return False, False
|
||||
|
||||
@@ -230,7 +230,7 @@ class EmailVerifier:
|
||||
|
||||
return messages
|
||||
|
||||
except Exception as e:
|
||||
except Exception as e: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
|
||||
logger.warning(f"Roundcube: 获取邮件列表失败: {e}")
|
||||
return []
|
||||
|
||||
@@ -252,7 +252,7 @@ class EmailVerifier:
|
||||
)
|
||||
return resp.text
|
||||
|
||||
except Exception as e:
|
||||
except Exception as e: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
|
||||
logger.warning(f"Roundcube: 读取邮件 {uid} 失败: {e}")
|
||||
return None
|
||||
|
||||
@@ -270,7 +270,7 @@ class EmailVerifier:
|
||||
- "2026-06-20" → 直接解析
|
||||
- "06-20" → 今年的该日期
|
||||
"""
|
||||
now = datetime.now()
|
||||
now = datetime.now(UTC)
|
||||
|
||||
# 今天
|
||||
if date_str.startswith("今天"):
|
||||
@@ -322,32 +322,36 @@ class EmailVerifier:
|
||||
|
||||
# 日期格式 2026-06-20
|
||||
try:
|
||||
return datetime.strptime(date_str.strip(), "%Y-%m-%d")
|
||||
return datetime.strptime(date_str.strip(), "%Y-%m-%d").replace(tzinfo=UTC)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 日期格式 2026-06-20 14:30
|
||||
try:
|
||||
return datetime.strptime(date_str.strip(), "%Y-%m-%d %H:%M")
|
||||
return datetime.strptime(date_str.strip(), "%Y-%m-%d %H:%M").replace(
|
||||
tzinfo=UTC
|
||||
)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 日期格式 2026-06-20 14:30:00
|
||||
try:
|
||||
return datetime.strptime(date_str.strip(), "%Y-%m-%d %H:%M:%S")
|
||||
return datetime.strptime(date_str.strip(), "%Y-%m-%d %H:%M:%S").replace(
|
||||
tzinfo=UTC
|
||||
)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 日期格式 06-20
|
||||
try:
|
||||
dt = datetime.strptime(date_str.strip(), "%m-%d")
|
||||
dt = datetime.strptime(date_str.strip(), "%m-%d").replace(tzinfo=UTC)
|
||||
return dt.replace(year=now.year)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 日期格式 06-20 14:30
|
||||
try:
|
||||
dt = datetime.strptime(date_str.strip(), "%m-%d %H:%M")
|
||||
dt = datetime.strptime(date_str.strip(), "%m-%d %H:%M").replace(tzinfo=UTC)
|
||||
return dt.replace(year=now.year)
|
||||
except ValueError:
|
||||
pass
|
||||
@@ -395,7 +399,7 @@ class EmailVerifier:
|
||||
return code
|
||||
except EmailLoginError:
|
||||
raise
|
||||
except Exception as e:
|
||||
except Exception as e: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
|
||||
last_error = str(e)
|
||||
logger.warning(f"Roundcube 读邮件异常: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user