feat: add cookies and host_only_cookies properties to CookieJar#12174
Conversation
Add read-only properties to expose stored cookies with their full attributes (expires, domain, path, etc.). The cookies property returns a MappingProxyType for immutability, and host_only_cookies returns a frozenset. Fixes aio-libs#3951
for more information, see https://pre-commit.ci
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12174 +/- ##
=======================================
Coverage 98.95% 98.95%
=======================================
Files 131 131
Lines 46627 46688 +61
Branches 2418 2421 +3
=======================================
+ Hits 46139 46200 +61
Misses 366 366
Partials 122 122
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Dreamsorcerer
left a comment
There was a problem hiding this comment.
Based on @bdraco's proposal, this looks good to me. I'll let him give it final sign-off.
Co-authored-by: J. Nick Koston <nick+github@koston.org>
…ejar-cookies # Conflicts: # tests/test_client_session.py
|
Thanks @Br1an67 |
Backport to 3.14: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply ca9d73d on top of patchback/backports/3.14/ca9d73ddf1e2a182e058641561b7766186b30485/pr-12174 Backporting merged PR #12174 into master
🤖 @patchback |
What do these changes do?
Add read-only
cookiesandhost_only_cookiesproperties toCookieJar(andAbstractCookieJar/DummyCookieJar) so users can access stored cookies with their full attributes (expires, domain, path, etc.) without relying on private_cookies/_host_only_cookies.cookiesreturnsMappingProxyType[tuple[str, str], SimpleCookie]— an immutable view of the internal cookie storagehost_only_cookiesreturnsfrozenset[tuple[str, str]]— a frozen copy of the host-only cookie setThis addresses the long-standing request to expose cookie metadata that
filter_cookies()intentionally strips (since the HTTPCookieheader does not include attributes likeexpires).Are there changes in behavior for the user?
Two new public read-only properties are available on
CookieJarandDummyCookieJar:jar.cookies— read-only mapping of(domain, path) -> SimpleCookiejar.host_only_cookies— frozen set of(domain, name)tuplesNo existing behavior is changed.
Is it a substantial burden for the maintainers to support this?
Minimal. The properties are thin wrappers (
MappingProxyType/frozenset) over existing internal state with no new data structures. TheMappingProxyTypeprevents direct mutation of the mapping, though the underlyingSimpleCookievalues are still mutable — this matches the trade-off discussed in the issue.Related issue number
Fixes #3951
Checklist
CONTRIBUTORS.txtCHANGES/folder