本文整理汇总了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'))
示例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'))
示例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'))
示例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
)