本文整理汇总了Python中werkzeug.contrib.securecookie.SecureCookie.load_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python SecureCookie.load_cookie方法的具体用法?Python SecureCookie.load_cookie怎么用?Python SecureCookie.load_cookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.contrib.securecookie.SecureCookie
的用法示例。
在下文中一共展示了SecureCookie.load_cookie方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_cookie
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import load_cookie [as 别名]
def load_cookie(cls, request, key="session", secret_key=None):
"""Loads a :class:`SecureCookie` from a cookie in request. If the
cookie is not set, a new :class:`SecureCookie` instanced is
returned.
:param request: a request object that has a `cookies` attribute
which is a dict of all cookie values.
:param key: the name of the cookie.
:param secret_key: the secret key used to unquote the cookie.
Always provide the value even though it has
no default!
"""
data = request.cookies.get(key)
if not data:
return cls(secret_key=secret_key)
return cls.unserialize(data, secret_key)
示例2: load_cookie
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import load_cookie [as 别名]
def load_cookie(cls, request, key='session', secret_key=None):
"""Loads a :class:`SecureCookie` from a cookie in request. If the
cookie is not set, a new :class:`SecureCookie` instanced is
returned.
:param request: a request object that has a `cookies` attribute
which is a dict of all cookie values.
:param key: the name of the cookie.
:param secret_key: the secret key used to unquote the cookie.
Always provide the value even though it has
no default!
"""
data = request.cookies.get(key)
if not data:
return cls(secret_key=secret_key)
return cls.unserialize(data, secret_key)
示例3: open_session
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import load_cookie [as 别名]
def open_session(self, request):
"""Creates or opens a new session.
Default implementation stores all session data in a signed cookie.
This requires that the :attr:`secret_key` is set.
:param request: an instance of :attr:`request_class`.
"""
key = self.secret_key
if key is not None:
return SecureCookie.load_cookie(request, self.session_cookie_name,
secret_key=key)
#
# 关键接口: 更新session
#
示例4: test_wrapper_support
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import load_cookie [as 别名]
def test_wrapper_support(self):
req = Request.from_values()
resp = Response()
c = SecureCookie.load_cookie(req, secret_key=b'foo')
assert c.new
c['foo'] = 42
self.assert_equal(c.secret_key, b'foo')
c.save_cookie(resp)
req = Request.from_values(headers={
'Cookie': 'session="%s"' % parse_cookie(resp.headers['set-cookie'])['session']
})
c2 = SecureCookie.load_cookie(req, secret_key=b'foo')
assert not c2.new
self.assert_equal(c2, c)