@@ -65,7 +65,9 @@ def __init__(
65
65
treat_as_secure_origin : Union [StrOrURL , List [StrOrURL ], None ] = None
66
66
) -> None :
67
67
self ._loop = asyncio .get_running_loop ()
68
- self ._cookies : DefaultDict [str , SimpleCookie [str ]] = defaultdict (SimpleCookie )
68
+ self ._cookies : DefaultDict [Tuple [str , str ], SimpleCookie [str ]] = defaultdict (
69
+ SimpleCookie
70
+ )
69
71
self ._host_only_cookies : Set [Tuple [str , str ]] = set ()
70
72
self ._unsafe = unsafe
71
73
self ._quote_cookie = quote_cookie
@@ -82,7 +84,7 @@ def __init__(
82
84
]
83
85
self ._treat_as_secure_origin = treat_as_secure_origin
84
86
self ._next_expiration = next_whole_second ()
85
- self ._expirations : Dict [Tuple [str , str ], datetime .datetime ] = {}
87
+ self ._expirations : Dict [Tuple [str , str , str ], datetime .datetime ] = {}
86
88
# #4515: datetime.max may not be representable on 32-bit platforms
87
89
self ._max_time = self .MAX_TIME
88
90
try :
@@ -110,20 +112,20 @@ def clear(self, predicate: Optional[ClearCookiePredicate] = None) -> None:
110
112
111
113
to_del = []
112
114
now = datetime .datetime .now (datetime .timezone .utc )
113
- for domain , cookie in self ._cookies .items ():
115
+ for ( domain , path ) , cookie in self ._cookies .items ():
114
116
for name , morsel in cookie .items ():
115
- key = (domain , name )
117
+ key = (domain , path , name )
116
118
if (
117
119
key in self ._expirations and self ._expirations [key ] <= now
118
120
) or predicate (morsel ):
119
121
to_del .append (key )
120
122
121
- for domain , name in to_del :
122
- key = ( domain , name )
123
- self . _host_only_cookies . discard ( key )
123
+ for domain , path , name in to_del :
124
+ self . _host_only_cookies . discard (( domain , name ) )
125
+ key = ( domain , path , name )
124
126
if key in self ._expirations :
125
- del self ._expirations [(domain , name )]
126
- self ._cookies [domain ].pop (name , None )
127
+ del self ._expirations [(domain , path , name )]
128
+ self ._cookies [( domain , path ) ].pop (name , None )
127
129
128
130
next_expiration = min (self ._expirations .values (), default = self ._max_time )
129
131
try :
@@ -147,9 +149,11 @@ def __len__(self) -> int:
147
149
def _do_expiration (self ) -> None :
148
150
self .clear (lambda x : False )
149
151
150
- def _expire_cookie (self , when : datetime .datetime , domain : str , name : str ) -> None :
152
+ def _expire_cookie (
153
+ self , when : datetime .datetime , domain : str , path : str , name : str
154
+ ) -> None :
151
155
self ._next_expiration = min (self ._next_expiration , when )
152
- self ._expirations [(domain , name )] = when
156
+ self ._expirations [(domain , path , name )] = when
153
157
154
158
def update_cookies (self , cookies : LooseCookies , response_url : URL = URL ()) -> None :
155
159
"""Update cookies."""
@@ -211,7 +215,7 @@ def update_cookies(self, cookies: LooseCookies, response_url: URL = URL()) -> No
211
215
) + datetime .timedelta (seconds = delta_seconds )
212
216
except OverflowError :
213
217
max_age_expiration = self ._max_time
214
- self ._expire_cookie (max_age_expiration , domain , name )
218
+ self ._expire_cookie (max_age_expiration , domain , path , name )
215
219
except ValueError :
216
220
cookie ["max-age" ] = ""
217
221
@@ -220,11 +224,11 @@ def update_cookies(self, cookies: LooseCookies, response_url: URL = URL()) -> No
220
224
if expires :
221
225
expire_time = self ._parse_date (expires )
222
226
if expire_time :
223
- self ._expire_cookie (expire_time , domain , name )
227
+ self ._expire_cookie (expire_time , domain , path , name )
224
228
else :
225
229
cookie ["expires" ] = ""
226
230
227
- self ._cookies [domain ][name ] = cookie
231
+ self ._cookies [( domain , path ) ][name ] = cookie
228
232
229
233
self ._do_expiration ()
230
234
0 commit comments