A class to hold ONE (key, value) pair. In a cookie, each such pair may have several attributes, so this class is used to keep the attributes associated with the appropriate key,value pair. This class also includes a coded_value attribute, which is used to hold the network representa
| 243 | |
| 244 | |
| 245 | class Morsel(dict): |
| 246 | """A class to hold ONE (key, value) pair. |
| 247 | |
| 248 | In a cookie, each such pair may have several attributes, so this class is |
| 249 | used to keep the attributes associated with the appropriate key,value pair. |
| 250 | This class also includes a coded_value attribute, which is used to hold |
| 251 | the network representation of the value. |
| 252 | """ |
| 253 | # RFC 2109 lists these attributes as reserved: |
| 254 | # path comment domain |
| 255 | # max-age secure version |
| 256 | # |
| 257 | # For historical reasons, these attributes are also reserved: |
| 258 | # expires |
| 259 | # |
| 260 | # This is an extension from Microsoft: |
| 261 | # httponly |
| 262 | # |
| 263 | # This dictionary provides a mapping from the lowercase |
| 264 | # variant on the left to the appropriate traditional |
| 265 | # formatting on the right. |
| 266 | _reserved = { |
| 267 | "expires" : "expires", |
| 268 | "path" : "Path", |
| 269 | "comment" : "Comment", |
| 270 | "domain" : "Domain", |
| 271 | "max-age" : "Max-Age", |
| 272 | "secure" : "Secure", |
| 273 | "httponly" : "HttpOnly", |
| 274 | "version" : "Version", |
| 275 | "samesite" : "SameSite", |
| 276 | "partitioned": "Partitioned", |
| 277 | } |
| 278 | |
| 279 | _reserved_defaults = dict.fromkeys(_reserved, "") |
| 280 | |
| 281 | _flags = {'secure', 'httponly', 'partitioned'} |
| 282 | |
| 283 | def __init__(self): |
| 284 | # Set defaults |
| 285 | self._key = self._value = self._coded_value = None |
| 286 | |
| 287 | # Set default attributes |
| 288 | dict.update(self, self._reserved_defaults) |
| 289 | |
| 290 | @property |
| 291 | def key(self): |
| 292 | return self._key |
| 293 | |
| 294 | @property |
| 295 | def value(self): |
| 296 | return self._value |
| 297 | |
| 298 | @property |
| 299 | def coded_value(self): |
| 300 | return self._coded_value |
| 301 | |
| 302 | def __setitem__(self, K, V): |