mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 09:46:42 +00:00
save and load cookie
This commit is contained in:
parent
3357da764c
commit
37257f11eb
@ -1,6 +1,10 @@
|
|||||||
from http.cookiejar import Cookie
|
from http.cookiejar import Cookie
|
||||||
|
import re
|
||||||
|
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
from requests.cookies import RequestsCookieJar
|
||||||
|
|
||||||
|
|
||||||
def cookie_from_string(text: str, domain: str) -> Cookie:
|
def cookie_from_string(text: str, domain: str) -> Cookie:
|
||||||
@ -33,3 +37,25 @@ def cookie_from_string(text: str, domain: str) -> Cookie:
|
|||||||
rest=None,
|
rest=None,
|
||||||
rfc2109=False
|
rfc2109=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def save_cookiejar(cj, filename):
|
||||||
|
with open(filename, "wb") as f:
|
||||||
|
f.truncate()
|
||||||
|
pickle.dump(cj._cookies, f)
|
||||||
|
|
||||||
|
|
||||||
|
def load_cookiejar(filename):
|
||||||
|
with open(filename, "rb") as f:
|
||||||
|
cookies = pickle.load(f)
|
||||||
|
cj = RequestsCookieJar()
|
||||||
|
cj._cookies = cookies
|
||||||
|
return cj
|
||||||
|
|
||||||
|
|
||||||
|
def cookiejar_filter(cj, pattern):
|
||||||
|
filtered_cj = RequestsCookieJar()
|
||||||
|
for c in cj:
|
||||||
|
if re.match(pattern, c.domain):
|
||||||
|
filtered_cj.set_cookie(c)
|
||||||
|
return filtered_cj
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.4",
|
version="1.5",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user