當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。