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


Python SimpleCookie.update方法代码示例

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


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

示例1: StatefulClient

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import update [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)
开发者ID:AspenWeb,项目名称:pando.py,代码行数:39,代码来源:client.py

示例2: hit

# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import update [as 别名]
    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)
开发者ID:AspenWeb,项目名称:pando.py,代码行数:26,代码来源:client.py


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