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


Python CookieJar.set_policy方法代码示例

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


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

示例1: test_length

# 需要导入模块: from http.cookiejar import CookieJar [as 别名]
# 或者: from http.cookiejar.CookieJar import set_policy [as 别名]
    def test_length(self):
        cookie_jar = CookieJar()
        policy = DeFactoCookiePolicy(cookie_jar=cookie_jar)
        cookie_jar.set_policy(policy)

        request = urllib.request.Request('http://example.com/')
        response = FakeResponse(
            [
                'Set-Cookie: k={0}'.format('a' * 400)
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)

        print(cookie_jar._cookies)

        self.assertTrue(cookie_jar._cookies['example.com']['/'].get('k'))

        request = urllib.request.Request('http://example.com/')
        response = FakeResponse(
            [
                'Set-Cookie: k={0}'.format('a' * 5000)
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)

        self.assertFalse(cookie_jar._cookies['example.com']['/'].get('k2'))
开发者ID:mback2k,项目名称:wpull,代码行数:32,代码来源:cookie_test.py

示例2: test_empty_value

# 需要导入模块: from http.cookiejar import CookieJar [as 别名]
# 或者: from http.cookiejar.CookieJar import set_policy [as 别名]
    def test_empty_value(self):
        cookie_jar = CookieJar()
        policy = DeFactoCookiePolicy(cookie_jar=cookie_jar)
        cookie_jar.set_policy(policy)

        request = urllib.request.Request('http://example.com/')
        response = FakeResponse(
            [
                'Set-Cookie: k'
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)

        print(cookie_jar._cookies)

        self.assertTrue(cookie_jar._cookies.get('example.com'))
开发者ID:Super-Rad,项目名称:wpull,代码行数:20,代码来源:cookie_test.py

示例3: test_ascii

# 需要导入模块: from http.cookiejar import CookieJar [as 别名]
# 或者: from http.cookiejar.CookieJar import set_policy [as 别名]
    def test_ascii(self):
        # Differences with FakeResponse:
        # On Python 3, MIME encoded-word syntax is used
        # On Python 2, U backslash syntax is used but it's not decoded back.
        cookie_jar = CookieJar()
        policy = DeFactoCookiePolicy(cookie_jar=cookie_jar)
        cookie_jar.set_policy(policy)

        request = urllib.request.Request('http://example.com/')
        response = FakeResponse(
            [
                'Set-Cookie: k=�'
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)

        print(cookie_jar._cookies)

        self.assertFalse(cookie_jar._cookies.get('example.com'))
开发者ID:mback2k,项目名称:wpull,代码行数:23,代码来源:cookie_test.py

示例4: test_domain_limit

# 需要导入模块: from http.cookiejar import CookieJar [as 别名]
# 或者: from http.cookiejar.CookieJar import set_policy [as 别名]
    def test_domain_limit(self):
        cookie_jar = CookieJar()
        policy = DeFactoCookiePolicy(cookie_jar=cookie_jar)
        cookie_jar.set_policy(policy)

        request = urllib.request.Request('http://example.com/')

        for key in range(55):
            response = FakeResponse(
                [
                    'Set-Cookie: k{0}=a'.format(key)
                ],
                'http://example.com/'
            )

            cookie_jar.extract_cookies(response, request)

            if key < 50:
                self.assertTrue(
                    cookie_jar._cookies['example.com']['/']
                    .get('k{0}'.format(key))
                )
            else:
                self.assertFalse(
                    cookie_jar._cookies['example.com']['/']
                    .get('k{0}'.format(key))
                )

        response = FakeResponse(
            [
                'Set-Cookie: k3=b'
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)
        self.assertEqual(
            'b',
            cookie_jar._cookies['example.com']['/']['k3'].value
        )
开发者ID:mback2k,项目名称:wpull,代码行数:42,代码来源:cookie_test.py


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