当前位置: 首页>>代码示例>>Python>>正文


Python Response.set_cookie方法代码示例

本文整理汇总了Python中webob.response.Response.set_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python Response.set_cookie方法的具体用法?Python Response.set_cookie怎么用?Python Response.set_cookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob.response.Response的用法示例。


在下文中一共展示了Response.set_cookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_set_cookie_expires_is_datetime_tz_and_max_age_is_None

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_expires_is_datetime_tz_and_max_age_is_None():
    import datetime

    res = Response()

    class FixedOffset(datetime.tzinfo):
        def __init__(self, offset, name):
            self.__offset = datetime.timedelta(minutes=offset)
            self.__name = name

        def utcoffset(self, dt):
            return self.__offset

        def tzname(self, dt):
            return self.__name

        def dst(self, dt):
            return datetime.timedelta(0)

    then = datetime.datetime.now(FixedOffset(60, "UTC+1")) + datetime.timedelta(days=1)

    res.set_cookie("a", "1", expires=then)
    assert res.headerlist[-1][0] == "Set-Cookie"
    val = [x.strip() for x in res.headerlist[-1][1].split(";")]
    assert len(val) == 4
    val.sort()
    assert val[0] in ("Max-Age=86399", "Max-Age=86400")
    assert val[1] == "Path=/"
    assert val[2] == "a=1"
    assert val[3].startswith("expires")
开发者ID:Pylons,项目名称:webob,代码行数:32,代码来源:test_response.py

示例2: test_unicode_cookies_error_raised

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_unicode_cookies_error_raised():
    res = Response()
    with pytest.raises(ValueError):
        Response.set_cookie(
            res,
            'x',
            text_(b'\N{BLACK SQUARE}', 'unicode_escape'))
开发者ID:doulbekill,项目名称:webob,代码行数:9,代码来源:test_response.py

示例3: test_cookies

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_cookies():
    res = Response()
    # test unicode value
    res.set_cookie("x", text_(b"\N{BLACK SQUARE}", "unicode_escape"))
    # utf8 encoded
    eq_(res.headers.getall("set-cookie"), ['x="\\342\\226\\240"; Path=/'])
    r2 = res.merge_cookies(simple_app)
    r2 = BaseRequest.blank("/").get_response(r2)
    eq_(r2.headerlist, [("Content-Type", "text/html; charset=utf8"), ("Set-Cookie", 'x="\\342\\226\\240"; Path=/')])
开发者ID:xpahos,项目名称:webob,代码行数:11,代码来源:test_response.py

示例4: test_cookies

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_cookies():
    res = Response()
    # test unicode value
    res.set_cookie("x", "test")
    # utf8 encoded
    eq_(res.headers.getall("set-cookie"), ["x=test; Path=/"])
    r2 = res.merge_cookies(simple_app)
    r2 = BaseRequest.blank("/").get_response(r2)
    eq_(r2.headerlist, [("Content-Type", "text/html; charset=utf8"), ("Set-Cookie", "x=test; Path=/")])
开发者ID:ckey,项目名称:webob,代码行数:11,代码来源:test_response.py

示例5: test_set_cookie_expires_is_None_and_max_age_is_int

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_expires_is_None_and_max_age_is_int():
    res = Response()
    res.set_cookie('a', '1', max_age=100)
    assert res.headerlist[-1][0] == 'Set-Cookie'
    val = [x.strip() for x in res.headerlist[-1][1].split(';')]
    assert len(val) == 4
    val.sort()
    assert val[0] == 'Max-Age=100'
    assert val[1] == 'Path=/'
    assert val[2] == 'a=1'
    assert val[3].startswith('expires')
开发者ID:doulbekill,项目名称:webob,代码行数:13,代码来源:test_response.py

示例6: test_set_cookie_value_is_None

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_value_is_None():
    res = Response()
    res.set_cookie("a", None)
    eq_(res.headerlist[-1][0], "Set-Cookie")
    val = [x.strip() for x in res.headerlist[-1][1].split(";")]
    assert len(val) == 4
    val.sort()
    eq_(val[0], "Max-Age=0")
    eq_(val[1], "Path=/")
    eq_(val[2], "a=")
    assert val[3].startswith("expires")
开发者ID:ckey,项目名称:webob,代码行数:13,代码来源:test_response.py

示例7: test_set_cookie_value_is_None

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_value_is_None():
    res = Response()
    res.set_cookie('a', None)
    eq_(res.headerlist[-1][0], 'Set-Cookie')
    val = [ x.strip() for x in res.headerlist[-1][1].split(';')]
    assert len(val) == 4
    val.sort()
    eq_(val[0], 'Max-Age=0')
    eq_(val[1], 'Path=/')
    eq_(val[2], 'a=')
    assert val[3].startswith('expires')
开发者ID:perey,项目名称:webob,代码行数:13,代码来源:test_response.py

示例8: test_cookies

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_cookies():
    res = Response()
    # test unicode value
    res.set_cookie('x', "test")
    # utf8 encoded
    assert res.headers.getall('set-cookie') == ['x=test; Path=/']
    r2 = res.merge_cookies(simple_app)
    r2 = BaseRequest.blank('/').get_response(r2)
    assert r2.headerlist == [
        ('Content-Type', 'text/html; charset=utf8'),
        ('Set-Cookie', 'x=test; Path=/'),
        ]
开发者ID:doulbekill,项目名称:webob,代码行数:14,代码来源:test_response.py

示例9: test_set_cookie_expires_is_None_and_max_age_is_timedelta

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_expires_is_None_and_max_age_is_timedelta():
    from datetime import timedelta
    res = Response()
    res.set_cookie('a', '1', max_age=timedelta(seconds=100))
    eq_(res.headerlist[-1][0], 'Set-Cookie')
    val = [ x.strip() for x in res.headerlist[-1][1].split(';')]
    assert len(val) == 4
    val.sort()
    eq_(val[0], 'Max-Age=100')
    eq_(val[1], 'Path=/')
    eq_(val[2], 'a=1')
    assert val[3].startswith('expires')
开发者ID:perey,项目名称:webob,代码行数:14,代码来源:test_response.py

示例10: test_response_cookie_ok

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
 def test_response_cookie_ok(self):
     '''Test case that ensures cookies can be correctly set to a response instance.'''
     
     response = Response()
     
     response.set_cookie("fantastico.sid", "12345", max_age=360, path="/", secure=True)
     
     cookie = response.headers["Set-Cookie"]
     
     self.assertGreater(cookie.find("fantastico.sid=12345"), -1)
     self.assertGreater(cookie.find("Max-Age=360"), -1)
     self.assertGreater(cookie.find("secure"), -1)
     self.assertGreater(cookie.find("Path=/"), -1)
开发者ID:rcosnita,项目名称:fantastico,代码行数:15,代码来源:test_response.py

示例11: test_set_cookie_expires_is_timedelta_and_max_age_is_None

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_expires_is_timedelta_and_max_age_is_None():
    import datetime
    res = Response()
    then = datetime.timedelta(days=1)
    res.set_cookie('a', '1', expires=then)
    assert res.headerlist[-1][0] == 'Set-Cookie'
    val = [x.strip() for x in res.headerlist[-1][1].split(';')]
    assert len(val) == 4
    val.sort()
    assert val[0] in ('Max-Age=86399', 'Max-Age=86400')
    assert val[1] == 'Path=/'
    assert val[2] == 'a=1'
    assert val[3].startswith('expires')
开发者ID:doulbekill,项目名称:webob,代码行数:15,代码来源:test_response.py

示例12: test_set_cookie_expires_is_None_and_max_age_is_timedelta

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_expires_is_None_and_max_age_is_timedelta():
    from datetime import timedelta

    res = Response()
    res.set_cookie("a", "1", max_age=timedelta(seconds=100))
    eq_(res.headerlist[-1][0], "Set-Cookie")
    val = [x.strip() for x in res.headerlist[-1][1].split(";")]
    assert len(val) == 4
    val.sort()
    eq_(val[0], "Max-Age=100")
    eq_(val[1], "Path=/")
    eq_(val[2], "a=1")
    assert val[3].startswith("expires")
开发者ID:ckey,项目名称:webob,代码行数:15,代码来源:test_response.py

示例13: test_cookies

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_cookies():
    res = Response()
    # test unicode value
    res.set_cookie('x', text_(b'\N{BLACK SQUARE}', 'unicode_escape'))
    # utf8 encoded
    eq_(res.headers.getall('set-cookie'), ['x="\\342\\226\\240"; Path=/'])
    r2 = res.merge_cookies(simple_app)
    r2 = BaseRequest.blank('/').get_response(r2)
    eq_(r2.headerlist,
        [('Content-Type', 'text/html; charset=utf8'),
        ('Set-Cookie', 'x="\\342\\226\\240"; Path=/'),
        ]
    )
开发者ID:MiCHiLU,项目名称:webob,代码行数:15,代码来源:test_response.py

示例14: test_set_cookie_expires_is_not_None_and_max_age_is_None

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_expires_is_not_None_and_max_age_is_None():
    import datetime
    res = Response()
    then = datetime.datetime.utcnow() + datetime.timedelta(days=1)
    res.set_cookie('a', '1', expires=then)
    eq_(res.headerlist[-1][0], 'Set-Cookie')
    val = [ x.strip() for x in res.headerlist[-1][1].split(';')]
    assert len(val) == 4
    val.sort()
    ok_(val[0] in ('Max-Age=86399', 'Max-Age=86400'))
    eq_(val[1], 'Path=/')
    eq_(val[2], 'a=1')
    assert val[3].startswith('expires')
开发者ID:perey,项目名称:webob,代码行数:15,代码来源:test_response.py

示例15: test_set_cookie_expires_is_not_None_and_max_age_is_None

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import set_cookie [as 别名]
def test_set_cookie_expires_is_not_None_and_max_age_is_None():
    import datetime

    res = Response()
    then = datetime.datetime.utcnow() + datetime.timedelta(days=1)
    res.set_cookie("a", "1", expires=then)
    eq_(res.headerlist[-1][0], "Set-Cookie")
    val = [x.strip() for x in res.headerlist[-1][1].split(";")]
    assert len(val) == 4
    val.sort()
    ok_(val[0] in ("Max-Age=86399", "Max-Age=86400"))
    eq_(val[1], "Path=/")
    eq_(val[2], "a=1")
    assert val[3].startswith("expires")
开发者ID:ckey,项目名称:webob,代码行数:16,代码来源:test_response.py


注:本文中的webob.response.Response.set_cookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。