本文整理汇总了Python中six.moves.http_cookies.SimpleCookie.values方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleCookie.values方法的具体用法?Python SimpleCookie.values怎么用?Python SimpleCookie.values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.http_cookies.SimpleCookie
的用法示例。
在下文中一共展示了SimpleCookie.values方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CookieHandler
# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import values [as 别名]
class CookieHandler(object):
def __init__(self, *args, **kw):
# Somewhere to store cookies between consecutive requests
self.cookies = SimpleCookie()
super(CookieHandler, self).__init__(*args, **kw)
def httpCookie(self, path):
"""Return self.cookies as an HTTP_COOKIE environment value."""
l = [m.OutputString().split(';')[0] for m in self.cookies.values()
if path.startswith(m['path'])]
return '; '.join(l)
def loadCookies(self, envstring):
self.cookies.load(envstring)
def saveCookies(self, response):
"""Save cookies from the response."""
# Urgh - need to play with the response's privates to extract
# cookies that have been set
# TODO: extend the IHTTPRequest interface to allow access to all
# cookies
# TODO: handle cookie expirations
for k, v in response._cookies.items():
k = k.encode('utf8') if bytes is str else k
val = v['value']
val = val.encode('utf8') if bytes is str else val
self.cookies[k] = val
if 'path' in v:
self.cookies[k]['path'] = v['path']
示例2: cookies
# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import values [as 别名]
def cookies(self):
if self._cookies is None:
parser = SimpleCookie(self.headers("Cookie"))
cookies = {}
for morsel in parser.values():
cookies[morsel.key] = morsel.value
self._cookies = cookies
return self._cookies.copy()
示例3: cookies
# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import values [as 别名]
def cookies(self):
if self._cookies is None:
# NOTE(tbug): We might want to look into parsing
# cookies ourselves. The SimpleCookie is doing a
# lot if stuff only required to SEND cookies.
parser = SimpleCookie(self.get_header("Cookie"))
cookies = {}
for morsel in parser.values():
cookies[morsel.key] = morsel.value
self._cookies = cookies
return self._cookies.copy()
示例4: Response
# 需要导入模块: from six.moves.http_cookies import SimpleCookie [as 别名]
# 或者: from six.moves.http_cookies.SimpleCookie import values [as 别名]
#.........这里部分代码省略.........
if expires.tzinfo is None:
# naive
self._cookies[name]["expires"] = expires.strftime(fmt)
else:
# aware
gmt_expires = expires.astimezone(GMT_TIMEZONE)
self._cookies[name]["expires"] = gmt_expires.strftime(fmt)
if max_age:
self._cookies[name]["max-age"] = max_age
if domain:
self._cookies[name]["domain"] = domain
if path:
self._cookies[name]["path"] = path
if secure:
self._cookies[name]["secure"] = secure
if http_only:
self._cookies[name]["httponly"] = http_only
def unset_cookie(self, name):
"""Unset a cookie in the response."""
if self._cookies is not None and name in self._cookies:
del self._cookies[name]
def get_header(self, name):
"""Retrieve the raw string value for the given header.
Args:
name (str): Header name, case-insensitive. Must be of type ``str``
or ``StringType``, and only character values 0x00 through 0xFF
may be used on platforms that use wide characters.
Returns:
str: The header's value if set, otherwise ``None``.
"""
return self._headers.get(name.lower(), None)
def set_header(self, name, value):
"""Set a header for this response to a given value.
Warning:
Calling this method overwrites the existing value, if any.
Warning:
For setting cookies, see instead :meth:`~.set_cookie`
Args:
name (str): Header name to set (case-insensitive). Must be of
type ``str`` or ``StringType``, and only character values 0x00
through 0xFF may be used on platforms that use wide
characters.
value (str): Value for the header. Must be of type ``str`` or
``StringType``, and only character values 0x00 through 0xFF
may be used on platforms that use wide characters.
"""
# NOTE(kgriffs): normalize name by lowercasing it
self._headers[name.lower()] = value
def append_header(self, name, value):
"""Set or append a header for this response.