本文整理汇总了Python中grab.cookie.CookieManager.from_cookie_list方法的典型用法代码示例。如果您正苦于以下问题:Python CookieManager.from_cookie_list方法的具体用法?Python CookieManager.from_cookie_list怎么用?Python CookieManager.from_cookie_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grab.cookie.CookieManager
的用法示例。
在下文中一共展示了CookieManager.from_cookie_list方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_cookie_list
# 需要导入模块: from grab.cookie import CookieManager [as 别名]
# 或者: from grab.cookie.CookieManager import from_cookie_list [as 别名]
def test_from_cookie_list(self):
cookie = create_cookie("foo", "bar", self.server.address)
mgr = CookieManager.from_cookie_list([cookie])
test_cookie = [x for x in mgr.cookiejar if x.name == "foo"][0]
self.assertEqual(cookie.name, test_cookie.name)
mgr = CookieManager.from_cookie_list([])
self.assertEqual(0, len(list(mgr.cookiejar)))
示例2: test_from_cookie_list
# 需要导入模块: from grab.cookie import CookieManager [as 别名]
# 或者: from grab.cookie.CookieManager import from_cookie_list [as 别名]
def test_from_cookie_list(self):
cookie = create_cookie('foo', 'bar')
mgr = CookieManager.from_cookie_list([cookie])
test_cookie = [x for x in mgr.cookiejar if x.name == 'foo'][0]
self.assertEqual(cookie.name, test_cookie.name)
mgr = CookieManager.from_cookie_list([])
self.assertEqual(0, len(list(mgr.cookiejar)))
示例3: test_pickle_serialization
# 需要导入模块: from grab.cookie import CookieManager [as 别名]
# 或者: from grab.cookie.CookieManager import from_cookie_list [as 别名]
def test_pickle_serialization(self):
cookie = create_cookie('foo', 'bar')
mgr = CookieManager.from_cookie_list([cookie])
dump = pickle.dumps(mgr)
mgr2 = pickle.loads(dump)
self.assertEqual(list(mgr.cookiejar)[0].value,
list(mgr2.cookiejar)[0].value)
示例4: load_config
# 需要导入模块: from grab.cookie import CookieManager [as 别名]
# 或者: from grab.cookie.CookieManager import from_cookie_list [as 别名]
def load_config(self, config):
"""
Configure grab instance with external config object.
"""
self.config = copy_config(config, self.mutable_config_keys)
if 'cookiejar_cookies' in config['state']:
self.cookies = CookieManager.from_cookie_list(config['state']['cookiejar_cookies'])
示例5: test_get_item
# 需要导入模块: from grab.cookie import CookieManager [as 别名]
# 或者: from grab.cookie.CookieManager import from_cookie_list [as 别名]
def test_get_item(self):
cookie = create_cookie("foo", "bar", self.server.address)
mgr = CookieManager.from_cookie_list([cookie])
self.assertEqual("bar", mgr["foo"])
self.assertRaises(KeyError, lambda: mgr["zzz"])
示例6: test_get_item
# 需要导入模块: from grab.cookie import CookieManager [as 别名]
# 或者: from grab.cookie.CookieManager import from_cookie_list [as 别名]
def test_get_item(self):
cookie = create_cookie('foo', 'bar')
mgr = CookieManager.from_cookie_list([cookie])
self.assertEqual('bar', mgr['foo'])
self.assertRaises(KeyError, lambda: mgr['zzz'])