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 Cookie to dict #231

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions curl_cffi/requests/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ def delete(
for cookie in remove:
self.jar.clear(cookie.domain, cookie.path, cookie.name)

def get_dict(self, domain: Optional[str] = None, path: Optional[str] = None) -> dict:
"""Takes as an argument an optional domain and path and returns a plain
old Python dict of name-value pairs of cookies that meet the
requirements.

"""
dictionary = {}
for cookie in self.jar:
if (domain is None or cookie.domain == domain) and (
path is None or cookie.path == path
):
dictionary[cookie.name] = cookie.value
return dictionary
Copy link

@jjsaunier jjsaunier Feb 24, 2024

Choose a reason for hiding this comment

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

I don't really understand the purpose here, may be it's expected, but cookie matching is not working like that. You can check official RFC:


def clear(
self, domain: typing.Optional[str] = None, path: typing.Optional[str] = None
) -> None:
Expand Down
Loading