本文整理汇总了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)