fix(tooling): 修复 pyright 解释器配置与类型守卫,补齐 ruff 门禁与两处历史 bug
- pyrightconfig.json 钉死 Python 3.12 虚拟环境,消除由于查找系统 Python 3.9 带来的假性报错 - 修复 huya/login.py 引用不存在函数的问题并补充单元测试 - 修复 browser_harvest.py 对 set 下标访问的错误并提升报错信息质量 - 虎牙 6 个子路由显式导入依赖,消除 import * 带来的未定义变量报警 - 规范化 Pydantic Field(default=...) 默认值声明 - 完善 solver.py / app_login.py 等核心路径类型守卫与 @overload 重载 - 在 pyproject.toml 中显式锁定 ruff lint 规则集 (E4, E7, E9, F, B, I, BLE) - 门禁脚本同步增加 ruff check 检查并在 AGENTS.md 补齐实践经验总结
This commit is contained in:
+47
-7
@@ -31,6 +31,7 @@ import struct
|
||||
import time
|
||||
import uuid
|
||||
from collections.abc import Mapping
|
||||
from typing import Literal, overload
|
||||
from urllib.parse import parse_qs, quote, urlparse
|
||||
|
||||
import requests
|
||||
@@ -245,7 +246,7 @@ def solve_safe_auth(
|
||||
k: v[0]
|
||||
for k, v in parse_qs(urlparse(risk_url).query, keep_blank_values=True).items()
|
||||
}
|
||||
app_id = str(q.get("appId") or "5002")
|
||||
app_id = q.get("appId") or "5002"
|
||||
last_err: Exception | None = None
|
||||
for attempt in range(max_retry):
|
||||
solver = HuyaVerificationSolver(
|
||||
@@ -293,6 +294,42 @@ def parse_real_uid(resp: bytes) -> int:
|
||||
raise HuyaAppLoginError("无法从登录响应解析真实 UID")
|
||||
|
||||
|
||||
@overload
|
||||
def login_cred_with_flow(
|
||||
account: str,
|
||||
password: str,
|
||||
max_rounds: int = ...,
|
||||
device_info: dict | None = ...,
|
||||
proxies: dict | None = ...,
|
||||
include_device_token: Literal[False] = ...,
|
||||
sms_url: str = ...,
|
||||
) -> tuple[bytes, int]: ...
|
||||
|
||||
|
||||
@overload
|
||||
def login_cred_with_flow(
|
||||
account: str,
|
||||
password: str,
|
||||
max_rounds: int = ...,
|
||||
device_info: dict | None = ...,
|
||||
proxies: dict | None = ...,
|
||||
include_device_token: Literal[True] = ...,
|
||||
sms_url: str = ...,
|
||||
) -> tuple[bytes, int, str]: ...
|
||||
|
||||
|
||||
@overload
|
||||
def login_cred_with_flow(
|
||||
account: str,
|
||||
password: str,
|
||||
max_rounds: int = ...,
|
||||
device_info: dict | None = ...,
|
||||
proxies: dict | None = ...,
|
||||
include_device_token: bool = ...,
|
||||
sms_url: str = ...,
|
||||
) -> tuple[bytes, int] | tuple[bytes, int, str]: ...
|
||||
|
||||
|
||||
def login_cred_with_flow(
|
||||
account: str,
|
||||
password: str,
|
||||
@@ -405,7 +442,11 @@ class QrRole:
|
||||
self.req_counter = random.randint(40_000_000, 41_000_000)
|
||||
self.s.headers.update(
|
||||
{
|
||||
"User-Agent": UA_PC if pc else mobile_user_agent(device_info),
|
||||
"User-Agent": (
|
||||
UA_PC
|
||||
if pc or device_info is None
|
||||
else mobile_user_agent(device_info)
|
||||
),
|
||||
"Origin": UDB_BASE,
|
||||
"content-type": "application/json;charset=UTF-8",
|
||||
"Accept": "*/*",
|
||||
@@ -550,8 +591,7 @@ class HuyaAppPasswordLogin:
|
||||
jar = session.cookies
|
||||
if hasattr(jar, "items"):
|
||||
pairs = [
|
||||
(str(key), "" if value is None else str(value))
|
||||
for key, value in jar.items()
|
||||
(key, "" if value is None else value) for key, value in jar.items()
|
||||
]
|
||||
else:
|
||||
pairs = [
|
||||
@@ -576,13 +616,13 @@ class HuyaAppPasswordLogin:
|
||||
raw_cred = (
|
||||
base64.urlsafe_b64encode(cred).decode("ascii").rstrip("=")
|
||||
if isinstance(cred, bytes)
|
||||
else str(cred or "")
|
||||
else (cred or "")
|
||||
)
|
||||
# 本次登录/指纹响应明确返回的字段,必须覆盖旧 Session 值。
|
||||
set_value("udb_cred", raw_cred, overwrite=True)
|
||||
if uid:
|
||||
set_value("udb_uid", int(uid), overwrite=True)
|
||||
set_value("yyuid", int(uid), overwrite=True)
|
||||
set_value("udb_uid", uid, overwrite=True)
|
||||
set_value("yyuid", uid, overwrite=True)
|
||||
set_value("udb_biztoken", biztoken, overwrite=True)
|
||||
set_value("udb_version", "1.0", overwrite=True)
|
||||
set_value("udb_origin", "0", overwrite=True)
|
||||
|
||||
Reference in New Issue
Block a user