in a cookie name (as :attr:`~Morsel.key`).
.. versionchanged:: 3.3
- Allowed '``:``' as a valid cookie name character.
+ Allowed ':' as a valid cookie name character.
-.. versionchanged:: 3.15
- Allowed '``"``' as a valid cookie value character.
.. note::
>>> print(C)
Set-Cookie: number=7
Set-Cookie: string=seven
- >>> import json
- >>> C = cookies.SimpleCookie()
- >>> C.load(f'cookies=7; mixins="{json.dumps({"chips": "dark chocolate"})}"; state=gooey')
- >>> print(C)
- Set-Cookie: cookies=7
- Set-Cookie: mixins="{"chips": "dark chocolate"}"
- Set-Cookie: state=gooey
(Contributed by Alexander Enrique Urieles Nieto in :gh:`131724`.)
-http.cookies
-------------
-
-* Allow '``"``' double quotes in cookie values.
- (Contributed by Nick Burns and Senthil Kumaran in :gh:`92936`.)
-
-
http.server
-----------
( # Optional group: there may not be a value.
\s*=\s* # Equal Sign
(?P<val> # Start of group 'val'
- "(?:\\"|.)*?" # Any double-quoted string
+ "(?:[^\\"]|\\.)*" # Any double-quoted string
| # or
# Special case for "expires" attr
(\w{3,6}day|\w{3}),\s # Day of the week or abbreviated day
'Set-Cookie: d=r',
'Set-Cookie: f=h'
))
- },
-
- # gh-92936: allow double quote in cookie values
- {
- 'data': 'cookie="{"key": "value"}"',
- 'dict': {'cookie': '{"key": "value"}'},
- 'repr': "<SimpleCookie: cookie='{\"key\": \"value\"}'>",
- 'output': 'Set-Cookie: cookie="{"key": "value"}"',
- },
- {
- 'data': 'key="some value; surrounded by quotes"',
- 'dict': {'key': 'some value; surrounded by quotes'},
- 'repr': "<SimpleCookie: key='some value; surrounded by quotes'>",
- 'output': 'Set-Cookie: key="some value; surrounded by quotes"',
- },
- {
- 'data': 'session="user123"; preferences="{"theme": "dark"}"',
- 'dict': {'session': 'user123', 'preferences': '{"theme": "dark"}'},
- 'repr': "<SimpleCookie: preferences='{\"theme\": \"dark\"}' session='user123'>",
- 'output': '\n'.join((
- 'Set-Cookie: preferences="{"theme": "dark"}"',
- 'Set-Cookie: session="user123"',
- ))
}
]