style: 统一 Ruff 代码格式

This commit is contained in:
yml2213
2026-08-30 21:04:52 +08:00
parent c891ac982e
commit 47e19ed7b2
90 changed files with 5574 additions and 2350 deletions
+18 -14
View File
@@ -16,24 +16,24 @@ def verify_proxy_url(proxy_url: str, timeout: tuple = (3, 5)) -> tuple[bool, str
Returns:
(是否可用, 消息)
"""
proxies = {'http': proxy_url, 'https': proxy_url}
proxies = {"http": proxy_url, "https": proxy_url}
# ── 斗鱼主站可达性验证 ──
try:
response = requests.get(
'https://www.douyu.com',
"https://www.douyu.com",
proxies=proxies,
timeout=timeout,
headers={'User-Agent': 'Mozilla/5.0'},
headers={"User-Agent": "Mozilla/5.0"},
)
response.raise_for_status()
return True, '代理可用 → 斗鱼可达'
return True, "代理可用 → 斗鱼可达"
except Exception as exc:
err_msg = str(exc)
if 'Tunnel connection failed' in err_msg or '503' in err_msg:
detail = '代理拒绝连接(白名单可能未生效)'
elif 'timed out' in err_msg.lower():
detail = '连接超时'
if "Tunnel connection failed" in err_msg or "503" in err_msg:
detail = "代理拒绝连接(白名单可能未生效)"
elif "timed out" in err_msg.lower():
detail = "连接超时"
else:
detail = type(exc).__name__
logger.debug(f"代理验证失败 [{proxy_url}]: 斗鱼主站不可达: {detail}")
@@ -54,7 +54,7 @@ def verify_proxies_concurrent(
return_all=True: (可用代理 URL 列表或 None, 消息)
"""
if not proxy_urls:
return None, '无代理可验证'
return None, "无代理可验证"
if len(proxy_urls) == 1:
ok, msg = verify_proxy_url(proxy_urls[0], timeout)
@@ -64,7 +64,9 @@ def verify_proxies_concurrent(
if return_all:
available: list[str] = []
with ThreadPoolExecutor(max_workers=min(max_workers, len(proxy_urls))) as executor:
with ThreadPoolExecutor(
max_workers=min(max_workers, len(proxy_urls))
) as executor:
future_map = {
executor.submit(verify_proxy_url, proxy, timeout): proxy
for proxy in proxy_urls
@@ -77,9 +79,11 @@ def verify_proxies_concurrent(
except Exception:
continue
if available:
logger.success(f"并发验证找到 {len(available)}/{len(proxy_urls)} 个可用代理")
return available, f'找到 {len(available)} 个可用代理'
return None, f'{len(proxy_urls)} 个代理均不可用'
logger.success(
f"并发验证找到 {len(available)}/{len(proxy_urls)} 个可用代理"
)
return available, f"找到 {len(available)} 个可用代理"
return None, f"{len(proxy_urls)} 个代理均不可用"
with ThreadPoolExecutor(max_workers=min(max_workers, len(proxy_urls))) as executor:
future_map = {
@@ -99,4 +103,4 @@ def verify_proxies_concurrent(
except Exception:
continue
return None, f'{len(proxy_urls)} 个代理均不可用'
return None, f"{len(proxy_urls)} 个代理均不可用"