Skip to content

Commit

Permalink
👽️ refactor: replace proxies with proxy (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
SigureMo authored Jan 26, 2024
1 parent 8b313b3 commit 5b44047
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion yutto/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)} 项")
Expand Down
14 changes: 7 additions & 7 deletions yutto/utils/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion yutto/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
# 需要校验
Expand Down

0 comments on commit 5b44047

Please sign in to comment.