本文整理汇总了Python中werkzeug.contrib.securecookie.SecureCookie.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python SecureCookie.serialize方法的具体用法?Python SecureCookie.serialize怎么用?Python SecureCookie.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.contrib.securecookie.SecureCookie
的用法示例。
在下文中一共展示了SecureCookie.serialize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_support
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def test_basic_support():
c = SecureCookie(secret_key=b'foo')
assert c.new
assert not c.modified
assert not c.should_save
c['x'] = 42
assert c.modified
assert c.should_save
s = c.serialize()
c2 = SecureCookie.unserialize(s, b'foo')
assert c is not c2
assert not c2.new
assert not c2.modified
assert not c2.should_save
assert c2 == c
c3 = SecureCookie.unserialize(s, b'wrong foo')
assert not c3.modified
assert not c3.new
assert c3 == {}
c4 = SecureCookie({'x': 42}, 'foo')
c4_serialized = c4.serialize()
assert SecureCookie.unserialize(c4_serialized, 'foo') == c4
示例2: fake_login
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def fake_login(request):
if request.method == 'GET':
return Response("FAKE LOGIN", mimetype="text/html")
elif request.method == 'POST':
response = Response("LOGGED IN", mimetype="text/html")
cookie = SecureCookie({"logged_in": True}, SECRET_KEY)
response.set_cookie('session_data', cookie.serialize())
return response
示例3: set_gaema_user
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def set_gaema_user(service, user):
gaema_user_key = GAEMA_USER_KEY_FORMAT % service
if hasattr(settings, "GAEMA_STORAGE") and settings.GAEMA_STORAGE == "cookie":
secure_cookie = SecureCookie(user, secret_key=settings.SECRET_KEY)
user_data = secure_cookie.serialize()
set_cookie(gaema_user_key, user_data)
else:
from kay.sessions import renew_session
renew_session(local.request)
local.request.session[gaema_user_key] = user
local.request.session.modified = True
示例4: post_process
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def post_process(self, environ, headers):
user = User.get_current()
if not user:
cookies = http.parse_cookie(environ)
if self.name in cookies:
raw = http.dump_cookie(self.name, '', expires=1)
headers.append((utils.to_native('Set-Cookie'), raw))
return
cookie = SecureCookie({
'uid': user.id,
'session_token': user.get_session_token(),
}, self.secret)
raw = http.dump_cookie(self.name, cookie.serialize(),
expires=self.expires, max_age=self.max_age)
headers.append((utils.to_native('Set-Cookie'), raw))
示例5: test_basic_support
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def test_basic_support(self):
c = SecureCookie(secret_key='foo')
assert c.new
assert not c.modified
assert not c.should_save
c['x'] = 42
assert c.modified
assert c.should_save
s = c.serialize()
c2 = SecureCookie.unserialize(s, 'foo')
assert c is not c2
assert not c2.new
assert not c2.modified
assert not c2.should_save
assert c2 == c
c3 = SecureCookie.unserialize(s, 'wrong foo')
assert not c3.modified
assert not c3.new
assert c3 == {}
示例6: test_basic_support
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def test_basic_support(self):
c = SecureCookie(secret_key=b'foo')
assert c.new
assert not c.modified
assert not c.should_save
c['x'] = 42
assert c.modified
assert c.should_save
s = c.serialize()
c2 = SecureCookie.unserialize(s, b'foo')
assert c is not c2
assert not c2.new
assert not c2.modified
assert not c2.should_save
self.assert_equal(c2, c)
c3 = SecureCookie.unserialize(s, b'wrong foo')
assert not c3.modified
assert not c3.new
self.assert_equal(c3, {})
示例7: test_basic_support
# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def test_basic_support(self):
c = SecureCookie(secret_key="foo")
assert c.new
print c.modified, c.should_save
assert not c.modified
assert not c.should_save
c["x"] = 42
assert c.modified
assert c.should_save
s = c.serialize()
c2 = SecureCookie.unserialize(s, "foo")
assert c is not c2
assert not c2.new
assert not c2.modified
assert not c2.should_save
assert c2 == c
c3 = SecureCookie.unserialize(s, "wrong foo")
assert not c3.modified
assert not c3.new
assert c3 == {}