'Create a new cookie or replace an old one. If the `secret` parameter is
set, create a `Signed Cookie` (described below).
:param name: the name of the cookie.
:param value: the value of the cookie.
:param secret: a signature key required for signed cookies.
Additionally, this method accepts all RFC 2109 attributes that are
supported by :class:`cookie.Morsel`, including:
:param max_age: maximum age in seconds. (default: None)
:param expires: a datetime object or UNIX timestamp. (default: None)
:param domain: the domain that is allowed to read the cookie.
(default: current domain)
:param path: limits the cookie to a given path (default: current path)
:param secure: limit the cookie to HTTPS connections (default: off).
:param httponly: prevents client-side javascript to read this cookie
(default: off, requires Python 2.6 or newer).
If neither `expires` nor `max_age` is set (default), the cookie will
expire at the end of the browser session (as soon as the browser
window is closed).
Signed cookies may store any pickle-able object and are
cryptographically signed to prevent manipulation. Keep in mind that
cookies are limited to 4kb in most browsers.
Warning: Signed cookies are not encrypted (the client can still see
the content) and not copy-protected (the client can restore an old
cookie). The main intention is to make pickling and unpickling
save, not to store secret information at client side.'

def set_cookie(self, name, value, secret=None, **options):

    if (not self._cookies):
        self._cookies = SimpleCookie()
    if secret:
        value = touni(cookie_encode((name, value), secret))
    elif (not isinstance(value, basestring)):
        raise TypeError('Secret    key    missing    for    non-string    Cookie.')
    if ((len(name) + len(value)) > 3800):
        raise ValueError('Content    does    not    fit    into    a    cookie.')
    self._cookies[name] = value
    for (key, value) in options.items():
        if (key == 'max_age'):
            if isinstance(value, timedelta):
                value = (value.seconds + ((value.days * 24) * 3600))
        if (key == 'expires'):
            if isinstance(value, (datedate, datetime)):
                value = value.timetuple()
            elif isinstance(value, (int, float)):
                value = time.gmtime(value)
            value = time.strftime('%a,    %d    %b    %Y    %H:%M:%S    GMT', value)
        if ((key in ('secure', 'httponly')) and (not value)):
            continue
        self._cookies[name][key.replace('_', '-')] = value
