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