mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-10 14:06:43 +00:00
Add encode/decode cj
This commit is contained in:
parent
51a4c7854d
commit
595fbc71be
@ -1,14 +1,14 @@
|
||||
from http.cookiejar import Cookie
|
||||
import pickle
|
||||
import re
|
||||
from base64 import b64encode, b64decode
|
||||
from http.cookiejar import Cookie
|
||||
from io import BytesIO
|
||||
|
||||
from dateutil.parser import parse
|
||||
import pickle
|
||||
|
||||
from requests.cookies import RequestsCookieJar
|
||||
|
||||
|
||||
def cookie_from_string(text: str, domain: str) -> Cookie:
|
||||
|
||||
tokens = [t.strip() for t in text.split(";")]
|
||||
|
||||
name, value = tokens[0].split("=")
|
||||
@ -39,6 +39,16 @@ def cookie_from_string(text: str, domain: str) -> Cookie:
|
||||
)
|
||||
|
||||
|
||||
def encode_cookiejar(cj):
|
||||
return b64encode(pickle.dumps(cj._cookies)).decode()
|
||||
|
||||
|
||||
def decode_cookiejar(data):
|
||||
cj = RequestsCookieJar()
|
||||
cj._cookies = pickle.loads(b64decode(data))
|
||||
return cj
|
||||
|
||||
|
||||
def save_cookiejar(cj, filename):
|
||||
with open(filename, "wb") as f:
|
||||
f.truncate()
|
||||
|
Loading…
x
Reference in New Issue
Block a user