'Set (add) a cookie for the response'

def set_cookie(self, key, value='', max_age=None, path='/', domain=None, secure=None, httponly=False, version=None, comment=None):

    cookies = BaseCookie()
    cookies[key] = value
    for (var_name, var_value) in [('max-age', max_age), ('path', path), ('domain', domain), ('secure', secure), ('HttpOnly', httponly), ('version', version), ('comment', comment)]:
        if ((var_value is not None) and (var_value is not False)):
            cookies[key][var_name] = str(var_value)
        if (max_age is not None):
            cookies[key]['expires'] = max_age
    header_value = cookies[key].output(header='').lstrip()
    self.response.headers._headers.append(('Set-Cookie', header_value))
