本文整理汇总了Python中six.moves.http_cookies.SimpleCookie.clear方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleCookie.clear方法的具体用法?Python SimpleCookie.clear怎么用?Python SimpleCookie.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.http_cookies.SimpleCookie
的用法示例。
在下文中一共展示了SimpleCookie.clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StatefulClient
# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import clear [as 别名]
class StatefulClient(Client):
"""This is a Client subclass that keeps cookies between calls."""
def __init__(self, *a, **kw):
super(StatefulClient, self).__init__(*a, **kw)
self.cookie = SimpleCookie()
def __enter__(self):
return self
def __exit__(self, *a):
self.cookie.clear()
def hit(self, *a, **kw):
cookies = kw.pop('cookies', None)
if cookies:
cookie = SimpleCookie()
# session cookies first
cookie.update(self.cookie)
# request cookies second
if isinstance(cookies, SimpleCookie):
cookie.update(cookies)
else:
for k, v in cookies.items():
cookie[str(k)] = str(v)
else:
cookie = self.cookie
kw['cookies'] = cookie
want = kw.pop('want', 'response')
kw['want'] = 'state'
state = super(StatefulClient, self).hit(*a, **kw)
r = state.get('response')
if isinstance(r, Response) and r.headers.cookie:
self.cookie.update(r.headers.cookie)
return self.resolve_want(state, want)