'Set an outgoing HTTP cookie.
In general, you should consider using sessions instead of cookies, see
L{twisted.web.server.Request.getSession} and the
L{twisted.web.server.Session} class for details.
@param k: cookie name
@type k: L{bytes} or L{unicode}
@param v: cookie value
@type v: L{bytes} or L{unicode}
@param expires: cookie expire attribute value in
"Wdy, DD Mon YYYY HH:MM:SS GMT" format
@type expires: L{bytes} or L{unicode}
@param domain: cookie domain
@type domain: L{bytes} or L{unicode}
@param path: cookie path
@type path: L{bytes} or L{unicode}
@param max_age: cookie expiration in seconds from reception
@type max_age: L{bytes} or L{unicode}
@param comment: cookie comment
@type comment: L{bytes} or L{unicode}
@param secure: direct browser to send the cookie on encrypted
connections only
@type secure: L{bool}
@param httpOnly: direct browser not to expose cookies through channels
other than HTTP (and HTTPS) requests
@type httpOnly: L{bool}
@raises: L{DeprecationWarning} if an argument is not L{bytes} or
L{unicode}.'

def addCookie(self, k, v, expires=None, domain=None, path=None, max_age=None, comment=None, secure=None, httpOnly=False):

    def _ensureBytes(val):
        '\n                                                Ensure    that    C{val}    is    bytes,    encoding    using    UTF-8    if    needed.\n                                                '
        if (val is None):
            return val
        if isinstance(val, bytes):
            return val
        elif isinstance(val, unicode):
            return val.encode('utf8')
        warnings.warn('Passing    non-bytes    or    non-unicode    cookie    arguments    is    deprecated    since    Twisted    16.1.', category=DeprecationWarning, stacklevel=3)
        return str(val).encode('utf8')
    cookie = ((_ensureBytes(k) + '=') + _ensureBytes(v))
    if (expires is not None):
        cookie = ((cookie + ';    Expires=') + _ensureBytes(expires))
    if (domain is not None):
        cookie = ((cookie + ';    Domain=') + _ensureBytes(domain))
    if (path is not None):
        cookie = ((cookie + ';    Path=') + _ensureBytes(path))
    if (max_age is not None):
        cookie = ((cookie + ';    Max-Age=') + _ensureBytes(max_age))
    if (comment is not None):
        cookie = ((cookie + ';    Comment=') + _ensureBytes(comment))
    if secure:
        cookie = (cookie + ';    Secure')
    if httpOnly:
        cookie = (cookie + ';    HttpOnly')
    self.cookies.append(cookie)
