-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add load and save support for cookie_jar #1317
Conversation
Please fix PEP8 blames first. |
The checking bot blames that |
So sorry for that I didn't response these days. I've re committed my fixes. |
Current coverage is 98.48% (diff: 84.61%)
|
Please add a test for missing case: https://codecov.io/gh/KeepSafe/aiohttp/compare/2013dc4b33abb4c932d5f56f9abb878dd882d99a...a11386475d721f9a2efd8784f464cec376c8c396#61696F687474702F636F6F6B69656A61722E7079-49 I would have 100% coverage someday. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea looks pretty good but please fix my comments first.
@@ -37,6 +39,17 @@ def __init__(self, *, unsafe=False, loop=None): | |||
self._next_expiration = ceil(self._loop.time()) | |||
self._expirations = {} | |||
|
|||
def load(self, file_path): | |||
f = open(file_path, 'rb') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please support both str
and pathlib.Path
types.
Just add file_path = pathlib.Path(file_path)
and use Path.open API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the pickle do not support pathlib.Path
, I choose to use file_path = str(file_path) if isinstance(file_path, pathlib.Path) else file_path
or file_path = str(file_path)
instead.
@@ -37,6 +39,17 @@ def __init__(self, *, unsafe=False, loop=None): | |||
self._next_expiration = ceil(self._loop.time()) | |||
self._expirations = {} | |||
|
|||
def load(self, file_path): | |||
f = open(file_path, 'rb') | |||
self._cookies = pickle.load(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line should be wrapped by with
statement for sake of managed resource usage.
self._cookies = pickle.load(f) | ||
|
||
def save(self, file_path): | ||
file_dir = os.path.dirname(file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as above: please support both str
and pathlib.Path
.
if file_dir and not os.path.exists(file_dir): | ||
os.makedirs(file_dir) | ||
f = open(file_path, 'wb') | ||
pickle.dump(self._cookies, f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use with
context manager.
Sorry, #1326 was finished first. |
What do these changes do?
Are there changes in behavior for the user?
No.
Related issue number
Checklist
CONTRIBUTORS.txt
CHANGES.rst