refactor: rename ambiguous variables in config loader
pp -> pool_raw, ps -> src_raw for clarity. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -176,9 +176,9 @@ def load_config(path: str | Path) -> Config:
|
||||
)
|
||||
|
||||
if "proxy_pool" in raw:
|
||||
pp = raw["proxy_pool"]
|
||||
pool_raw = raw["proxy_pool"]
|
||||
sources = []
|
||||
for src in pp.get("sources", []):
|
||||
for src in pool_raw.get("sources", []):
|
||||
sources.append(
|
||||
PoolSourceConfig(
|
||||
url=src.get("url"),
|
||||
@@ -190,26 +190,26 @@ def load_config(path: str | Path) -> Config:
|
||||
)
|
||||
config.proxy_pool = ProxyPoolConfig(
|
||||
sources=sources,
|
||||
refresh=float(pp.get("refresh", 300)),
|
||||
test_interval=float(pp.get("test_interval", 120)),
|
||||
test_url=pp.get("test_url", "http://httpbin.org/ip"),
|
||||
test_timeout=float(pp.get("test_timeout", 15)),
|
||||
test_concurrency=int(pp.get("test_concurrency", 5)),
|
||||
max_fails=int(pp.get("max_fails", 3)),
|
||||
state_file=pp.get("state_file", ""),
|
||||
report_url=pp.get("report_url", ""),
|
||||
refresh=float(pool_raw.get("refresh", 300)),
|
||||
test_interval=float(pool_raw.get("test_interval", 120)),
|
||||
test_url=pool_raw.get("test_url", "http://httpbin.org/ip"),
|
||||
test_timeout=float(pool_raw.get("test_timeout", 15)),
|
||||
test_concurrency=int(pool_raw.get("test_concurrency", 5)),
|
||||
max_fails=int(pool_raw.get("max_fails", 3)),
|
||||
state_file=pool_raw.get("state_file", ""),
|
||||
report_url=pool_raw.get("report_url", ""),
|
||||
)
|
||||
elif "proxy_source" in raw:
|
||||
# backward compat: convert legacy proxy_source to proxy_pool
|
||||
ps = raw["proxy_source"]
|
||||
if isinstance(ps, str):
|
||||
url, proto, country, limit, refresh = ps, None, None, 1000, 300.0
|
||||
elif isinstance(ps, dict):
|
||||
url = ps.get("url", "")
|
||||
proto = ps.get("proto")
|
||||
country = ps.get("country")
|
||||
limit = ps.get("limit", 1000)
|
||||
refresh = float(ps.get("refresh", 300))
|
||||
src_raw = raw["proxy_source"]
|
||||
if isinstance(src_raw, str):
|
||||
url, proto, country, limit, refresh = src_raw, None, None, 1000, 300.0
|
||||
elif isinstance(src_raw, dict):
|
||||
url = src_raw.get("url", "")
|
||||
proto = src_raw.get("proto")
|
||||
country = src_raw.get("country")
|
||||
limit = src_raw.get("limit", 1000)
|
||||
refresh = float(src_raw.get("refresh", 300))
|
||||
else:
|
||||
url, proto, country, limit, refresh = "", None, None, 1000, 300.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user