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:
|
if "proxy_pool" in raw:
|
||||||
pp = raw["proxy_pool"]
|
pool_raw = raw["proxy_pool"]
|
||||||
sources = []
|
sources = []
|
||||||
for src in pp.get("sources", []):
|
for src in pool_raw.get("sources", []):
|
||||||
sources.append(
|
sources.append(
|
||||||
PoolSourceConfig(
|
PoolSourceConfig(
|
||||||
url=src.get("url"),
|
url=src.get("url"),
|
||||||
@@ -190,26 +190,26 @@ def load_config(path: str | Path) -> Config:
|
|||||||
)
|
)
|
||||||
config.proxy_pool = ProxyPoolConfig(
|
config.proxy_pool = ProxyPoolConfig(
|
||||||
sources=sources,
|
sources=sources,
|
||||||
refresh=float(pp.get("refresh", 300)),
|
refresh=float(pool_raw.get("refresh", 300)),
|
||||||
test_interval=float(pp.get("test_interval", 120)),
|
test_interval=float(pool_raw.get("test_interval", 120)),
|
||||||
test_url=pp.get("test_url", "http://httpbin.org/ip"),
|
test_url=pool_raw.get("test_url", "http://httpbin.org/ip"),
|
||||||
test_timeout=float(pp.get("test_timeout", 15)),
|
test_timeout=float(pool_raw.get("test_timeout", 15)),
|
||||||
test_concurrency=int(pp.get("test_concurrency", 5)),
|
test_concurrency=int(pool_raw.get("test_concurrency", 5)),
|
||||||
max_fails=int(pp.get("max_fails", 3)),
|
max_fails=int(pool_raw.get("max_fails", 3)),
|
||||||
state_file=pp.get("state_file", ""),
|
state_file=pool_raw.get("state_file", ""),
|
||||||
report_url=pp.get("report_url", ""),
|
report_url=pool_raw.get("report_url", ""),
|
||||||
)
|
)
|
||||||
elif "proxy_source" in raw:
|
elif "proxy_source" in raw:
|
||||||
# backward compat: convert legacy proxy_source to proxy_pool
|
# backward compat: convert legacy proxy_source to proxy_pool
|
||||||
ps = raw["proxy_source"]
|
src_raw = raw["proxy_source"]
|
||||||
if isinstance(ps, str):
|
if isinstance(src_raw, str):
|
||||||
url, proto, country, limit, refresh = ps, None, None, 1000, 300.0
|
url, proto, country, limit, refresh = src_raw, None, None, 1000, 300.0
|
||||||
elif isinstance(ps, dict):
|
elif isinstance(src_raw, dict):
|
||||||
url = ps.get("url", "")
|
url = src_raw.get("url", "")
|
||||||
proto = ps.get("proto")
|
proto = src_raw.get("proto")
|
||||||
country = ps.get("country")
|
country = src_raw.get("country")
|
||||||
limit = ps.get("limit", 1000)
|
limit = src_raw.get("limit", 1000)
|
||||||
refresh = float(ps.get("refresh", 300))
|
refresh = float(src_raw.get("refresh", 300))
|
||||||
else:
|
else:
|
||||||
url, proto, country, limit, refresh = "", None, None, 1000, 300.0
|
url, proto, country, limit, refresh = "", None, None, 1000, 300.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user