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


Python BaseCookie.load方法代码示例

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


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

示例1: unset_cookie

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
 def unset_cookie(self, key):
   """ Unset a cookie with the given name (remove from the response).
   
   If there are multiple cookies (e.g., two cookies with the same name and
   different paths or domains), all such cookies will be deleted.
     
   Args:
     key: string that is the cookie's name (mandatory)
   Side effects:
     delete from self.response.headers all cookies with that name
   Raises:
     KeyError if the response had no such cookies (or, none at all)
   """
   existing = self.response.headers.getall('Set-Cookie')
   if not existing: raise KeyError("No cookies at all had been set")
   # remove all set-cookie headers, then put back those (if any) that
   # should not be removed
   del self.response.headers['Set-Cookie']
   found = False
   for header in existing:
     cookies = BaseCookie()
     cookies.load(header)
     if key in cookies:
       found = True
       del cookies[key]
       header = cookies.output(header='').lstrip()
     if header:
       self.response.headers.add_header('Set-Cookie', header)
   if not found: raise KeyError("No cookie had been set with name %r" % key)
开发者ID:Nette22,项目名称:Affect-Sampler,代码行数:31,代码来源:cookutil.py

示例2: unset_cookie

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
 def unset_cookie(self, key):
     """
     Unset a cookie with the given name (remove it from the
     response).  If there are multiple cookies (e.g., two cookies
     with the same name and different paths or domains), all such
     cookies will be deleted.
     """
     existing = self.response.headers.get_all('Set-Cookie')
     if not existing:
         raise KeyError(
             "No cookies at all have been set")
     del self.response.headers['Set-Cookie']
     found = False
     for header in existing:
         cookies = BaseCookie()
         cookies.load(header)
         if key in cookies:
             found = True
             del cookies[key]
         header = cookies.output(header='').lstrip()
         if header:
             self.response.headers.add('Set-Cookie', header)
     if not found:
         raise KeyError(
             "No cookie has been set with the name %r" % key)
开发者ID:garciaclaudio,项目名称:askthecrowd,代码行数:27,代码来源:util.py

示例3: unset_cookie

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
 def unset_cookie(self, key, strict=True):
     """
     Unset a cookie with the given name (remove it from the
     response).  If there are multiple cookies (e.g., two cookies
     with the same name and different paths or domains), all such
     cookies will be deleted.
     """
     existing = self.headers.getall('Set-Cookie')
     if not existing:
         if not strict:
             return
         raise KeyError("No cookies at all have been set")
     del self.headers['Set-Cookie']
     found = False
     for header in existing:
         cookies = BaseCookie()
         cookies.load(header)
         if key in cookies:
             found = True
             del cookies[key]
             self._add_cookie(cookies)
         else:
             # this branching is required because Cookie.Morsel.output()
             # strips quotes from expires= parameter, so better use
             # it as is, if it hasn't changed
             self._add_cookie(header)
     if strict and not found:
         raise KeyError(
             "No cookie has been set with the name %r" % key)
开发者ID:dchristian,项目名称:karacos-wsgi,代码行数:31,代码来源:response.py

示例4: load

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
 def load(self, rawdata):
     self.bad_cookies = []
     self._BaseCookie__set = self._loose_set
     BaseCookie.load(self, rawdata)
     self._BaseCookie__set = self._strict_set
     for key in self.bad_cookies:
         del self[key]
开发者ID:hhru,项目名称:hh-tornado-old,代码行数:9,代码来源:httputil.py

示例5: parse_cookies

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
def parse_cookies(response):
    """
    Return a ``Cookie.BaseCookie`` object populated from cookies parsed from
    the response object
    """
    base_cookie = BaseCookie()
    for item in response.headers.get_all('Set-Cookie'):
        base_cookie.load(item)
    return base_cookie
开发者ID:,项目名称:,代码行数:11,代码来源:

示例6: _parse_cookies

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
 def _parse_cookies(self, environ)   :
     _QUOTES_RE = re.compile('"(.*)"')
     source=environ.get('HTTP_COOKIE', '')
     vars = {}
     if source:
         cookies = BaseCookie()
         cookies.load(source)
         for name in cookies:
             value = cookies[name].value
             unquote_match = _QUOTES_RE.match(value)
             if unquote_match is not None:
                 value = unquote_match.group(1)
             vars[name] = value
     return vars
开发者ID:Stultus2,项目名称:silpa,代码行数:16,代码来源:silparequest.py

示例7: _get_cookies

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
def _get_cookies(environ):
    """
    Return a *plain* dictionary of cookies as found in the request.
    """
    source = environ.get('HTTP_COOKIE', '')
    if 'webob._parsed_cookies' in environ:
        vars_, var_source = environ['webob._parsed_cookies']
        if var_source == source:
            return vars_
    vars_ = {}
    if source:
        cookies = BaseCookie()
        cookies.load(source)
        for name in cookies:
            vars_[name] = cookies[name].value
    environ['webob._parsed_cookies'] = (vars_, source)
    return vars_
开发者ID:our-city-app,项目名称:gae-plugin-framework,代码行数:19,代码来源:wsgi.py

示例8: str_cookies

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
 def str_cookies(self):
     """
     Return a *plain* dictionary of cookies as found in the request.
     """
     env = self.environ
     source = env.get('HTTP_COOKIE', '')
     if 'webob._parsed_cookies' in env:
         vars, var_source = env['webob._parsed_cookies']
         if var_source == source:
             return vars
     vars = {}
     if source:
         cookies = BaseCookie()
         cookies.load(source)
         for name in cookies:
             value = cookies[name].value
             unquote_match = QUOTES_RE.match(value)
             if unquote_match is not None:
                 value = unquote_match.group(1)
             vars[name] = value
     env['webob._parsed_cookies'] = (vars, source)
     return vars
开发者ID:cozi,项目名称:webob,代码行数:24,代码来源:request.py

示例9: unset_cookie

# 需要导入模块: from Cookie import BaseCookie [as 别名]
# 或者: from Cookie.BaseCookie import load [as 别名]
    def unset_cookie(self, key):
        existing = self.headers.get_all('Set-Cookie')
        if not existing:
            raise KeyError('No cookies have been set')

        del self.headers['Set-Cookie']
        found = False

        for header in existing:
            cookies = BaseCookie()
            cookies.load(header)
            if key in cookies:
                found = True
                del cookies[key]
                header = cookies.output(header='').lstrip()
            if header:
                if header.endswith(';'):
                    header = header[:-1]
                self.headers.add_header('Set-Cookie', header)

        if not found:
            raise KeyError('No cookie has been set with the name %r' % key)
开发者ID:davidreynolds,项目名称:blueberrypy,代码行数:24,代码来源:util.py


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