feat: 自动学习按视频完成和五分钟刷新学时,代理仅 HTTP/SOCKS
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
"""账号级 HTTP/HTTPS/SOCKS4/SOCKS5 代理。不处理 VPN 或隧道。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from urllib.parse import urlparse
|
||||
|
||||
_SCHEMES = {"http", "https", "socks4", "socks5", "socks5h"}
|
||||
|
||||
|
||||
def parse_proxy(value: str | None) -> str | None:
|
||||
"""把代理地址规范成 httpx 可用的 URL。空值表示直连。"""
|
||||
text = (value or "").strip()
|
||||
if not text:
|
||||
return None
|
||||
if "://" not in text:
|
||||
text = "http://" + text
|
||||
parsed = urlparse(text)
|
||||
scheme = (parsed.scheme or "").lower()
|
||||
if scheme not in _SCHEMES:
|
||||
raise ValueError("代理只支持 HTTP、HTTPS、SOCKS4、SOCKS5")
|
||||
if not parsed.hostname:
|
||||
raise ValueError("代理地址不完整")
|
||||
return text
|
||||
Reference in New Issue
Block a user