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


Python Cookie.max_age方法代码示例

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


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

示例1: test_attributes

# 需要导入模块: from ipapython.cookie import Cookie [as 别名]
# 或者: from ipapython.cookie.Cookie import max_age [as 别名]
    def test_attributes(self):
        cookie = Cookie('color', 'blue')
        self.assertEqual(cookie.key, 'color')
        self.assertEqual(cookie.value, 'blue')
        self.assertEqual(cookie.domain, None)
        self.assertEqual(cookie.path, None)
        self.assertEqual(cookie.max_age, None)
        self.assertEqual(cookie.expires, None)
        self.assertEqual(cookie.secure, None)
        self.assertEqual(cookie.httponly, None)

        cookie.domain = 'example.com'
        self.assertEqual(cookie.domain, 'example.com')
        cookie.domain = None
        self.assertEqual(cookie.domain, None)

        cookie.path = '/toplevel'
        self.assertEqual(cookie.path, '/toplevel')
        cookie.path = None
        self.assertEqual(cookie.path, None)

        cookie.max_age = 400
        self.assertEqual(cookie.max_age, 400)
        cookie.max_age = None
        self.assertEqual(cookie.max_age, None)

        cookie.expires = 'Sun, 06 Nov 1994 08:49:37 GMT'
        self.assertEqual(cookie.expires, datetime.datetime(1994, 11, 6, 8, 49, 37))
        cookie.expires = None
        self.assertEqual(cookie.expires, None)

        cookie.secure = True
        self.assertEqual(cookie.secure, True)
        self.assertEqual(str(cookie), "color=blue; Secure")
        cookie.secure = False
        self.assertEqual(cookie.secure, False)
        self.assertEqual(str(cookie), "color=blue")
        cookie.secure = None
        self.assertEqual(cookie.secure, None)
        self.assertEqual(str(cookie), "color=blue")

        cookie.httponly = True
        self.assertEqual(cookie.httponly, True)
        self.assertEqual(str(cookie), "color=blue; HttpOnly")
        cookie.httponly = False
        self.assertEqual(cookie.httponly, False)
        self.assertEqual(str(cookie), "color=blue")
        cookie.httponly = None
        self.assertEqual(cookie.httponly, None)
        self.assertEqual(str(cookie), "color=blue")
开发者ID:guanwei,项目名称:freeipa,代码行数:52,代码来源:test_cookie.py

示例2: test_invalid

# 需要导入模块: from ipapython.cookie import Cookie [as 别名]
# 或者: from ipapython.cookie.Cookie import max_age [as 别名]
    def test_invalid(self):
        # Invalid Max-Age
        s = 'color=blue; Max-Age=over-the-hill'
        with self.assertRaises(ValueError):
            cookies = Cookie.parse(s)

        cookie = Cookie('color', 'blue')
        with self.assertRaises(ValueError):
            cookie.max_age = 'over-the-hill'

        # Invalid Expires
        s = 'color=blue; Expires=Sun, 06 Xxx 1994 08:49:37 GMT'
        with self.assertRaises(ValueError):
            cookies = Cookie.parse(s)

        cookie = Cookie('color', 'blue')
        with self.assertRaises(ValueError):
            cookie.expires = 'Sun, 06 Xxx 1994 08:49:37 GMT'
开发者ID:guanwei,项目名称:freeipa,代码行数:20,代码来源:test_cookie.py

示例3: test_invalid

# 需要导入模块: from ipapython.cookie import Cookie [as 别名]
# 或者: from ipapython.cookie.Cookie import max_age [as 别名]
    def test_invalid(self):
        # Invalid Max-Age
        s = "color=blue; Max-Age=over-the-hill"
        with self.assertRaises(ValueError):
            Cookie.parse(s)

        cookie = Cookie("color", "blue")
        with self.assertRaises(ValueError):
            cookie.max_age = "over-the-hill"

        # Invalid Expires
        s = "color=blue; Expires=Sun, 06 Xxx 1994 08:49:37 GMT"
        with self.assertRaises(ValueError):
            Cookie.parse(s)

        cookie = Cookie("color", "blue")
        with self.assertRaises(ValueError):
            cookie.expires = "Sun, 06 Xxx 1994 08:49:37 GMT"
开发者ID:apophys,项目名称:freeipa,代码行数:20,代码来源:test_cookie.py


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