Archived
refactor: 清理 13 处生产死代码
为什么:用 AST 级引用分析(而非文本 grep——同名符号会互相掩盖)确认这些 符号全项目零引用。文本 grep 查不出的原因是它们都有「活着的同名兄弟」: services/downloads.py(共 6 个,93 行) _parse_cookie_str / _global_music_u / _vip_name / _detect_vip / _admin_client / _user_client —— 活的是 core.media.parse_cookie_str、web/routers/music.py、account.py 的版本 随之失效的 import:USER_COOKIE_FILE / GLOBAL_MUSIC_U_CACHE / VIP_PROBE_LOCK / account_info / detect_vip_by_probe / QRLoginClient services/api_service.py APIResponse 类(29 行)—— web/response.py 才是活的响应封装 services/_shared.py _rate_ok —— 逐字复制 web.ratelimit.rate_ok core/utils.py safe_int / safe_console_print —— 活的是 web/request_utils.safe_int core/repo.py all_settings / get_user_by_name —— auth_system.get_user_by_name 才是活的 core/db.py / web/auth_state.py / web/request_utils.py execute_many / _safe_register_credits + secrets_rand / dedup_ids 结果:生产代码死代码候选 13 → 0(余下 118 个全是 pytest 测试函数,属正常)。
This commit is contained in:
1 parent
445c16c329
commit
0569b50737
8 files changed
+10
-217
No files matched your search
+1
-22
@@ -1,34 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""纯函数工具(框架无关,无 Web 框架依赖)。
|
||||
|
||||
安全整数解析、控制台输出兜底、SRT 时间轴、
|
||||
LRC→SRT 转换、字段参数解析、163cn.tv 短链展开(含私有缓存)。
|
||||
SRT 时间轴、LRC→SRT 转换、字段参数解析、163cn.tv 短链展开(含私有缓存)。
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import threading
|
||||
|
||||
|
||||
def safe_int(value, default: int) -> int:
|
||||
"""用户输入的安全整数解析:垃圾值回退默认值(而非 500)"""
|
||||
try:
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
|
||||
|
||||
def safe_console_print(text: str) -> None:
|
||||
"""控制台输出兜底:stdout 被重定向到文件且系统编码非 UTF-8 时
|
||||
(典型:NSSM 服务日志 + 中文 Windows GBK 控制台),emoji 等字符会触发
|
||||
UnicodeEncodeError 中断启动流程——实测崩溃循环。此处降级为可编码字符。"""
|
||||
try:
|
||||
print(text)
|
||||
except UnicodeEncodeError:
|
||||
enc = getattr(sys.stdout, 'encoding', None) or 'ascii'
|
||||
print(text.encode(enc, errors='replace').decode(enc, errors='replace'))
|
||||
|
||||
|
||||
def srt_time(t: float) -> str:
|
||||
"""秒 → SRT 时间格式 HH:MM:SS,mmm"""
|
||||
h = int(t // 3600)
|
||||
|
||||
Reference in new issue
Block a user