Skip to content
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

Closed
wants to merge 20 commits into from
Closed

Add load and save support for cookie_jar #1317

wants to merge 20 commits into from

Conversation

ahuigo
Copy link
Contributor

@ahuigo ahuigo commented Oct 17, 2016

What do these changes do?

  1. Add load and save support for cookie_jar
  2. Add test case for the support above.

Are there changes in behavior for the user?

No.

Related issue number

Checklist

  • I think the code is well written
  • [x ] Unit tests for the changes exist
  • Documentation reflects the changes
  • Add yourself to CONTRIBUTORS.txt
  • Add a new entry to CHANGES.rst

@asvetlov
Copy link
Member

Please fix PEP8 blames first.

@asvetlov
Copy link
Member

The checking bot blames that cookieJar is misspelled word.
Changing it to CookieJar will fix the problem.
Please do it.

@ahuigo
Copy link
Contributor Author

ahuigo commented Oct 20, 2016

So sorry for that I didn't response these days. I've re committed my fixes.

@codecov-io
Copy link

codecov-io commented Oct 20, 2016

Current coverage is 98.48% (diff: 84.61%)

No coverage report found for master at 0f74eae.

Powered by Codecov. Last update 0f74eae...eeecbfc

@asvetlov
Copy link
Member

Please add a test for missing case: https://codecov.io/gh/KeepSafe/aiohttp/compare/2013dc4b33abb4c932d5f56f9abb878dd882d99a...a11386475d721f9a2efd8784f464cec376c8c396#61696F687474702F636F6F6B69656A61722E7079-49

I would have 100% coverage someday.
Adding not covered lines definitely goes in wrong direction.

Copy link
Member

@asvetlov asvetlov left a 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')
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use with context manager.

@asvetlov
Copy link
Member

Sorry, #1326 was finished first.

@asvetlov asvetlov closed this Oct 22, 2016
@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants