mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 01:36:42 +00:00
36 lines
829 B
Python
36 lines
829 B
Python
from http.cookiejar import Cookie
|
|
|
|
from dateutil.parser import parse
|
|
|
|
|
|
def cookie_from_string(text: str, domain: str) -> Cookie:
|
|
|
|
tokens = [t.strip() for t in text.split(";")]
|
|
|
|
name, value = tokens[0].split("=")
|
|
|
|
path = None
|
|
expires = None
|
|
|
|
for tok in tokens[1:]:
|
|
k, v = tok.split("=")
|
|
if k == "path":
|
|
path = v
|
|
if k == "expires":
|
|
expires = parse(v).timestamp()
|
|
|
|
return Cookie(
|
|
version=0,
|
|
name=name, value=value,
|
|
port=None, port_specified=False,
|
|
domain=domain, domain_specified=True, domain_initial_dot=False,
|
|
path=path, path_specified=path is not None,
|
|
secure=False,
|
|
expires=expires,
|
|
discard=None,
|
|
comment=None,
|
|
comment_url=None,
|
|
rest=None,
|
|
rfc2109=False
|
|
)
|