mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-25 07:36:28 +00:00
🎨 Improve the Cookie
class to allow it to accept more types of parameters
This commit is contained in:
parent
0161ec695c
commit
0354fe7aa5
@ -8,7 +8,6 @@ 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, NotSupported
|
||||
from simnet.utils.cookies import parse_cookie
|
||||
from simnet.utils.ds import generate_dynamic_secret, DSType, hex_digest
|
||||
from simnet.utils.enum_ import Region, Game
|
||||
from simnet.utils.types import (
|
||||
@ -72,7 +71,6 @@ class BaseClient(AsyncContextManager["BaseClient"]):
|
||||
write=5.0,
|
||||
pool=1.0,
|
||||
)
|
||||
cookies = parse_cookie(cookies) if isinstance(cookies, str) else cookies
|
||||
cookies = Cookies(cookies)
|
||||
self.headers = Headers(headers)
|
||||
self.player_id = player_id
|
||||
|
@ -1,12 +1,40 @@
|
||||
from http.cookiejar import CookieJar
|
||||
from http.cookies import SimpleCookie
|
||||
from typing import Optional
|
||||
|
||||
from httpx import Cookies as _Cookies
|
||||
|
||||
from simnet.utils.types import CookieTypes
|
||||
|
||||
__all__ = ("Cookies",)
|
||||
|
||||
|
||||
class Cookies(_Cookies):
|
||||
"""An extension of the `httpx.Cookies` class that includes additional functionality."""
|
||||
"""A wrapper around `httpx.Cookies` that provides additional functionality."""
|
||||
|
||||
def __init__(self, cookies: Optional[CookieTypes] = None): # skipcq: PYL-W0231
|
||||
if cookies is None or isinstance(cookies, dict):
|
||||
self.jar = CookieJar()
|
||||
if isinstance(cookies, dict):
|
||||
for key, value in cookies.items():
|
||||
if isinstance(value, str):
|
||||
self.set(key, value)
|
||||
else:
|
||||
self.set(key, str(value))
|
||||
elif isinstance(cookies, list):
|
||||
self.jar = CookieJar()
|
||||
for key, value in cookies:
|
||||
self.set(key, value)
|
||||
elif isinstance(cookies, Cookies):
|
||||
self.jar = CookieJar()
|
||||
for cookie in cookies.jar:
|
||||
self.jar.set_cookie(cookie)
|
||||
elif isinstance(cookies, str):
|
||||
cookie = SimpleCookie(cookies)
|
||||
for key, value in cookie.items():
|
||||
self.set(key, value.value)
|
||||
else:
|
||||
self.jar = cookies
|
||||
|
||||
COOKIE_USER_ID_NAMES = ("ltuid", "account_id", "stuid", "ltuid_v2", "account_id_v2")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user