Пример #1
0
def make_cookie(name,
                value,
                mac_key=None,
                path=None,
                expires=None,
                httponly=True,
                domain=None):
    """
    Create a cookie string, optionally with a MAC, path and
    expires value. If ``expires`` is provided, its value should be
    in seconds.
    """
    cookie = SimpleCookie()

    value = encode_name(value)

    if mac_key:
        secret_string = sha('%s%s' % (value, mac_key)).hexdigest()
        cookie[name] = '%s:%s' % (value, secret_string)
    else:
        cookie[name] = value

    if path:
        cookie[name]['path'] = path

    if expires:
        cookie[name]['max-age'] = expires

    if domain:
        cookie[name]['domain'] = domain

    output = cookie.output(header='').lstrip().rstrip()
    if httponly:
        output += '; httponly'
    return output
Пример #2
0
def make_cookie(name, value, mac_key=None, path=None,
        expires=None, httponly=True, domain=None):
    """
    Create a cookie string, optionally with a MAC, path and
    expires value. If ``expires`` is provided, its value should be
    in seconds.
    """
    cookie = SimpleCookie()

    # XXX: backwards to 2.x?
    #value = value.encode('utf-8')

    if mac_key:
        secret_string = sha('%s%s' % (value, mac_key)).hexdigest()
        cookie[name] = '%s:%s' % (value, secret_string)
    else:
        cookie[name] = value

    if path:
        cookie[name]['path'] = path

    if expires:
        cookie[name]['max-age'] = expires

    if domain:
        cookie[name]['domain'] = domain

    output = cookie.output(header='').lstrip().rstrip()
    if httponly:
        output += '; httponly'
    return output
Пример #3
0
def make_cookie(name, value, mac_key=None, path=None, expires=None, httponly=True, domain=None):
    """
    Create a cookie string, optionally with a MAC, path and
    expires value. If ``expires`` is provided, its value should be
    in seconds.
    """
    cookie = SimpleCookie()

    value = encode_name(value)

    if mac_key:
        secret_string = sha("%s%s" % (value, mac_key)).hexdigest()
        cookie[name] = "%s:%s" % (value, secret_string)
    else:
        cookie[name] = value

    if path:
        cookie[name]["path"] = path

    if expires:
        cookie[name]["max-age"] = expires

    if domain:
        cookie[name]["domain"] = domain

    output = cookie.output(header="").lstrip().rstrip()
    if httponly:
        output += "; httponly"
    return output