BaseClient supports parsing cookies in str format

Co-authored-by: xtaodada <xtao@xtaolink.cn>
This commit is contained in:
luoshuijs 2023-05-17 16:07:11 +08:00 committed by GitHub
parent dea36a405f
commit 7671198c0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ from httpx import AsyncClient, TimeoutException, Response, HTTPError, Timeout
from simnet.client.cookies import Cookies
from simnet.client.headers import Headers
from simnet.errors import TimedOut, NetworkError, BadRequest, raise_for_ret_code
from simnet.utils.cookies import parse_cookie
from simnet.utils.ds import generate_dynamic_secret, DSType
from simnet.utils.enum_ import Region, Game
from simnet.utils.types import (
@ -29,7 +30,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
This is the base class for simnet clients. It provides common methods and properties for simnet clients.
Args:
cookies (Optional[CookieTypes], optional): The cookies used for the client.
cookies (Optional[str, CookieTypes], optional): The cookies used for the client.
headers (Optional[HeaderTypes], optional): The headers used for the client.
account_id (Optional[int], optional): The account id used for the client.
player_id (Optional[int], optional): The player id used for the client.
@ -52,7 +53,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
def __init__(
self,
cookies: Optional[CookieTypes] = None,
cookies: Optional[str, CookieTypes] = None,
headers: Optional[HeaderTypes] = None,
account_id: Optional[int] = None,
player_id: Optional[int] = None,
@ -68,8 +69,7 @@ class BaseClient(AsyncContextManager["BaseClient"]):
write=5.0,
pool=1.0,
)
cookies = Cookies(cookies)
cookies = Cookies(parse_cookie(cookies)) if isinstance(cookies, str) else cookies
self.headers = Headers(headers)
self.player_id = player_id
self.account_id = account_id or cookies.account_id