watson.http.cookies

class watson.http.cookies.CookieDict(input=None)[source]

A dictionary containing cookies.

A basic extension of the SimpleCookie class from the standard library, but designed to work better with wsgi.

Example:

cd = CookieDict()
cookie = cd.add('my_cookie', 'some value')
print(cookie)  # my_cookie=some value
print(cd['my_cookie'])  # my_cookie=some value
add(name, value='', expires=0, path='/', domain=None, secure=False, httponly=False, comment=None)[source]

Convenience method to add cookies to the dict.

Parameters:
  • name – the name of the cookie
  • value – the value of the cookie
  • expires – the expiration date for the cookie in seconds
  • path – the path in which the cookie is valid
  • domain – the domain in which the cookie is valid
  • secure – only send cookies over https
  • httponly – only send over http requests, not accessible via JavaScript
  • comment – the associated comment with the cookie
Returns:

The morsel that was added to the CookieDict

delete(name)[source]

Expire a cookie the next time it is sent to the browser.

Parameters:name – the name of the cookie
expire()[source]

Expire all the cookies in the dictionary.

merge(cookie_dict)[source]

Merges an existing cookie dict into another cookie dict.

Parameters:cookie_dict (CookieDict) – The cookie dict to merge
watson.http.cookies.cookies_from_environ(environ)[source]

Converts a HTTP_COOKIE from an environ dict into a CookieDict.