本文整理汇总了Python中Cookie.SimpleCookie.iterkeys方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleCookie.iterkeys方法的具体用法?Python SimpleCookie.iterkeys怎么用?Python SimpleCookie.iterkeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie.SimpleCookie
的用法示例。
在下文中一共展示了SimpleCookie.iterkeys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Response
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import iterkeys [as 别名]
class Response(object):
"""
wsgi Response, has a Request object attribute,
"""
def __init__(self, request, ctype=None):
self.__request = request
if ctype:
self.__ctype = ctype
else:
self.__ctype = 'text/html; charset=UTF-8'
self.__body = []
from Cookie import SimpleCookie
self.__cookie = SimpleCookie()
# add default headers
self.__header = ('200 OK', [('Content-Type', self.__ctype)])
@property
def body(self):
if self.__request.method == 'HEAD':
return ""
else:
return "".join(self.__body)
@property
def status(self):
return self.__header[0]
@property
def header(self):
return self.__header[1]
def add(self, *args):
from types import StringTypes, FunctionType
for response in args:
if type(response) is FunctionType:
self.add(response())
if type(response) is StringTypes:
self.__body.append(response)
else:
self.__body.append(str(response))
def cookie(self, key, value):
"""
add Set-Cookie headers
"""
self.__cookie[key] = value
self.__cookie[key]['path'] = '/'
for key in self.__cookie.iterkeys():
self.__header[1].append(('Set-Cookie', self.__cookie[key].OutputString()))
def redirect(self, url_append, code=None):
if not code:
code = '303 SEE OTHER'
self.response.header.state(code)
self.response.header.add('Location', self.__request.base_url + url_append)
示例2: _get_cookies
# 需要导入模块: from Cookie import SimpleCookie [as 别名]
# 或者: from Cookie.SimpleCookie import iterkeys [as 别名]
def _get_cookies(self):
if self._cookies is None:
self._cookies = {}
cookie = self.META.get('HTTP_COOKIE', '')
if cookie:
try:
cookie = SimpleCookie(cookie)
except CookieError:
pass
else:
for key in cookie.iterkeys():
self._cookies[key] = cookie[key].value
return self._cookies