August 2018
Intermediate to advanced
366 pages
10h 14m
English
The SimpleCookie class represents a cookie, as a set of one or more values.
Each value can be set into the cookie as if it was a dictionary:
cookie = SimpleCookie()
cookie['identity'] = 'USER: {}'.format(identity)
If the cookie morsel has to accept more options, those can be set with dictionary syntax too:
cookie['identity']['Path'] = '/'
Each cookie can contain multiple values and each one of them should be set with a Set-Cookie HTTP header.
Iterating over the cookie will retrieve all the key/value pairs that constitute the cookie, and then calling OutputString() on them will return the cookie value encoded as expected by the Set-Cookie header, with all the additional attributes:
for set_cookie in cookie.values(): resp.headers.add_header('Set-Cookie', ...