5.2.11 draco.cookie -- the Cookies object

Managing cookies is very easy in Draco. The Cookies object implements a namespace that lets you get, set and remove cookies on the remote client. The global instance is stored under the name cookies in the current module.

Cookie values are always strings. If you set a cookie to a value that is not a string, it will be converted to a string first. A small example:

from draco.cookie import cookies

cookies['parrot'] = 'dead'
del cookies['parrot']

class Cookies( )
Global Draco object that implements a namespace to access cookies.

The public methods of Cookies are:

setPath( name, path)
Set the "Path" attribute of cookie name to path. This attribute is used by browsers to determine when the cookie should be sent. If the cookie name is not found, a KeyError is raised.

setDefaultPath( path)
Set the default "Path" attribute to path. The initial default value is set to '/'.

setDomain( name, domain)
Set the "Domain" attribute of cookie name to domain. This attribute determines the domain to which the cookie applies. If the cookie name is not found, a KeyError is raised.

setDefaultDomain( domain)
Set the default "Domain" attribute to domain. The initial default domain is set to None which means not to set such an attribute.

setExpires( name, expires)
Set the "Expires" attribute of cookie name to expires, which must be a DateTime instance. This attribute determines when the browser should expire a cookie5.3. If the cookie cookie is not found, a KeyError is raised.

setDefaultExpires( expires)
Set the default "Expires" attribute to expires, which must be a DateTime instance. The initial default expiration is set to None which means not to set such an attribute.

setSecure( name, secure)
Set the "Secure" flag for cookie name if secure is nonzero. If this flag is set, browser will only send this cookie over a secure connection.

setDefaultSecure( secure)
Set the default "Secure" flag to secure. The initial default secure flag is set to None.



Footnotes

... cookie5.3
The latest RFC (RFC2965) does not define this attribute. Instead it defines a "Max-Age" attribute that specifies a relative expiration date. Unfortunately this attribute is poorly support amongst browsers.