本文整理匯總了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)
示例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)
示例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)
示例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]
示例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
示例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
示例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_
示例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
示例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)