From 5b4404779b19fadeebbd27440e46f76cb913b7b3 Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Fri, 26 Jan 2024 23:34:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20refactor:=20replace=20`?= =?UTF-8?q?proxies`=20with=20`proxy`=20(#227)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yutto/__main__.py | 2 +- yutto/utils/fetcher.py | 14 +++++++------- yutto/validator.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/yutto/__main__.py b/yutto/__main__.py index 82c463fcf..b6c90974a 100644 --- a/yutto/__main__.py +++ b/yutto/__main__.py @@ -217,7 +217,7 @@ async def run(args_list: list[argparse.Namespace]): async with create_client( cookies=Fetcher.cookies, trust_env=Fetcher.trust_env, - proxies=Fetcher.proxies, + proxy=Fetcher.proxy, ) as client: if len(args_list) > 1: Logger.info(f"列表里共检测到 {len(args_list)} 项") diff --git a/yutto/utils/fetcher.py b/yutto/utils/fetcher.py index a0b5b38a8..4154893a0 100644 --- a/yutto/utils/fetcher.py +++ b/yutto/utils/fetcher.py @@ -50,7 +50,7 @@ async def connect_n_times(*args: InputT.args, **kwargs: InputT.kwargs) -> RetT: return connect_n_times -DEFAULT_PROXIES = None +DEFAULT_PROXY = None DEFAULT_TRUST_ENV = True DEFAULT_HEADERS: dict[str, str] = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", @@ -60,7 +60,7 @@ async def connect_n_times(*args: InputT.args, **kwargs: InputT.kwargs) -> RetT: class Fetcher: - proxies: str | None = DEFAULT_PROXIES + proxy: str | None = DEFAULT_PROXY trust_env: bool = DEFAULT_TRUST_ENV headers: dict[str, str] = DEFAULT_HEADERS cookies: httpx.Cookies = DEFAULT_COOKIES @@ -71,13 +71,13 @@ class Fetcher: @classmethod def set_proxy(cls, proxy: str): if proxy == "auto": - Fetcher.proxies = None + Fetcher.proxy = None Fetcher.trust_env = True elif proxy == "no": - Fetcher.proxies = None + Fetcher.proxy = None Fetcher.trust_env = False else: - Fetcher.proxies = proxy + Fetcher.proxy = proxy Fetcher.trust_env = False @classmethod @@ -237,14 +237,14 @@ def create_client( headers: dict[str, str] = DEFAULT_HEADERS, cookies: httpx.Cookies = DEFAULT_COOKIES, trust_env: bool = DEFAULT_TRUST_ENV, - proxies: str | None = DEFAULT_PROXIES, + proxy: str | None = DEFAULT_PROXY, timeout: int | httpx.Timeout = 5, ) -> AsyncClient: client = httpx.AsyncClient( headers=headers, cookies=cookies, trust_env=trust_env, - proxies=proxies, + proxy=proxy, timeout=timeout, follow_redirects=True, http2=True, diff --git a/yutto/validator.py b/yutto/validator.py index eb2a9ff12..ccd4f6afe 100644 --- a/yutto/validator.py +++ b/yutto/validator.py @@ -150,7 +150,7 @@ async def validate_user_info(check_option: UserInfo) -> bool: async with create_client( cookies=Fetcher.cookies, trust_env=Fetcher.trust_env, - proxies=Fetcher.proxies, + proxy=Fetcher.proxy, ) as client: if check_option["is_login"] or check_option["vip_status"]: # 需要校验