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


Python SimpleCookie.iterkeys方法代码示例

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


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

示例1: Response

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import iterkeys [as 别名]
class Response(object):
    """
        wsgi Response, has a Request object attribute,
    """
    def __init__(self, request, ctype=None):
        self.__request = request
        if ctype:
            self.__ctype = ctype
        else:
            self.__ctype = 'text/html; charset=UTF-8'
        self.__body = []
        from Cookie import SimpleCookie
        self.__cookie = SimpleCookie()
        # add default headers
        self.__header = ('200 OK', [('Content-Type', self.__ctype)])

    @property
    def body(self):
        if self.__request.method == 'HEAD':
            return ""
        else:
            return "".join(self.__body)
            
    @property
    def status(self):
        return self.__header[0]

    @property
    def header(self):
        return self.__header[1]

    def add(self, *args):
        from types import StringTypes, FunctionType
        for response in args:
            if type(response) is FunctionType:
                self.add(response())
            if type(response) is StringTypes:
                self.__body.append(response)
            else:
                self.__body.append(str(response))

    def cookie(self, key, value):
        """
           add Set-Cookie headers
        """
        self.__cookie[key] = value
        self.__cookie[key]['path'] = '/'
        for key in self.__cookie.iterkeys():
            self.__header[1].append(('Set-Cookie', self.__cookie[key].OutputString()))

    def redirect(self, url_append, code=None):
        if not code:
            code = '303 SEE OTHER'
        self.response.header.state(code)
        self.response.header.add('Location', self.__request.base_url + url_append)
开发者ID:herrymon,项目名称:pykaboo,代码行数:57,代码来源:pyka.py

示例2: _get_cookies

# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import iterkeys [as 别名]
 def _get_cookies(self):
     if self._cookies is None:
         self._cookies = {}
         cookie = self.META.get('HTTP_COOKIE', '')
         if cookie:
             try:
                 cookie = SimpleCookie(cookie)
             except CookieError:
                 pass
             else:
                 for key in cookie.iterkeys():
                     self._cookies[key] = cookie[key].value
     return self._cookies
开发者ID:fluxid,项目名称:fpyf,代码行数:15,代码来源:fpyf.py


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