本文整理汇总了Python中tornado.web.create_signed_value方法的典型用法代码示例。如果您正苦于以下问题:Python web.create_signed_value方法的具体用法?Python web.create_signed_value怎么用?Python web.create_signed_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.web
的用法示例。
在下文中一共展示了web.create_signed_value方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_types
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_types(self):
cookie_value = to_unicode(create_signed_value(self.COOKIE_SECRET,
"asdf", "qwer"))
response = self.fetch("/typecheck/asdf?foo=bar",
headers={"Cookie": "asdf=" + cookie_value})
data = json_decode(response.body)
self.assertEqual(data, {})
response = self.fetch("/typecheck/asdf?foo=bar", method="POST",
headers={"Cookie": "asdf=" + cookie_value},
body="foo=bar")
示例2: test_known_values
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_known_values(self):
signed_v1 = create_signed_value(SignedValueTest.SECRET, "key", "value",
version=1, clock=self.present)
self.assertEqual(
signed_v1,
b"dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4f")
signed_v2 = create_signed_value(SignedValueTest.SECRET, "key", "value",
version=2, clock=self.present)
self.assertEqual(
signed_v2,
b"2|1:0|10:1300000000|3:key|8:dmFsdWU=|"
b"3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152")
signed_default = create_signed_value(SignedValueTest.SECRET,
"key", "value", clock=self.present)
self.assertEqual(signed_default, signed_v2)
decoded_v1 = decode_signed_value(SignedValueTest.SECRET, "key",
signed_v1, min_version=1,
clock=self.present)
self.assertEqual(decoded_v1, b"value")
decoded_v2 = decode_signed_value(SignedValueTest.SECRET, "key",
signed_v2, min_version=2,
clock=self.present)
self.assertEqual(decoded_v2, b"value")
示例3: test_name_swap
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_name_swap(self):
signed1 = create_signed_value(SignedValueTest.SECRET, "key1", "value",
clock=self.present)
signed2 = create_signed_value(SignedValueTest.SECRET, "key2", "value",
clock=self.present)
# Try decoding each string with the other's "name"
decoded1 = decode_signed_value(SignedValueTest.SECRET, "key2", signed1,
clock=self.present)
self.assertIs(decoded1, None)
decoded2 = decode_signed_value(SignedValueTest.SECRET, "key1", signed2,
clock=self.present)
self.assertIs(decoded2, None)
示例4: test_expired
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_expired(self):
signed = create_signed_value(SignedValueTest.SECRET, "key1", "value",
clock=self.past)
decoded_past = decode_signed_value(SignedValueTest.SECRET, "key1",
signed, clock=self.past)
self.assertEqual(decoded_past, b"value")
decoded_present = decode_signed_value(SignedValueTest.SECRET, "key1",
signed, clock=self.present)
self.assertIs(decoded_present, None)
示例5: test_non_ascii
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_non_ascii(self):
value = b"\xe9"
signed = create_signed_value(SignedValueTest.SECRET, "key", value,
clock=self.present)
decoded = decode_signed_value(SignedValueTest.SECRET, "key", signed,
clock=self.present)
self.assertEqual(value, decoded)
示例6: test_key_versioning_read_write_non_default_key
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_key_versioning_read_write_non_default_key(self):
value = b"\xe9"
signed = create_signed_value(SignedValueTest.SECRET_DICT,
"key", value, clock=self.present,
key_version=1)
decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
"key", signed, clock=self.present)
self.assertEqual(value, decoded)
示例7: test_key_versioning_invalid_key
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_key_versioning_invalid_key(self):
value = b"\xe9"
signed = create_signed_value(SignedValueTest.SECRET_DICT,
"key", value, clock=self.present,
key_version=0)
newkeys = SignedValueTest.SECRET_DICT.copy()
newkeys.pop(0)
decoded = decode_signed_value(newkeys,
"key", signed, clock=self.present)
self.assertEqual(None, decoded)
示例8: test_key_version_retrieval
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_key_version_retrieval(self):
value = b"\xe9"
signed = create_signed_value(SignedValueTest.SECRET_DICT,
"key", value, clock=self.present,
key_version=1)
key_version = get_signature_key_version(signed)
self.assertEqual(1, key_version)
示例9: test_key_versioning_read_write_default_key
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def test_key_versioning_read_write_default_key(self):
value = b"\xe9"
signed = create_signed_value(SignedValueTest.SECRET_DICT,
"key", value, clock=self.present,
key_version=0)
decoded = decode_signed_value(SignedValueTest.SECRET_DICT,
"key", signed, clock=self.present)
self.assertEqual(value, decoded)
示例10: set_cookie
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import create_signed_value [as 别名]
def set_cookie(self, name, value, expires_days=30, version=None,
domain=None, expires=None, path="/", **kwargs):
""" Sets the given cookie name/value with the given options. Set value
to None to clear. The cookie value is secured using
`flexx.config.cookie_secret`; don't forget to set that config
value in your server. Additional keyword arguments are set on
the Cookie.Morsel directly.
"""
# This code is taken (in modified form) from the Tornado project
# Copyright 2009 Facebook
# Licensed under the Apache License, Version 2.0
# Assume tornado is available ...
from tornado.escape import native_str
from tornado.httputil import format_timestamp
from tornado.web import create_signed_value
# Clear cookie?
if value is None:
value = ""
expires = datetime.datetime.utcnow() - datetime.timedelta(days=365)
else:
secret = config.cookie_secret
value = create_signed_value(secret, name, value, version=version,
key_version=None)
# The cookie library only accepts type str, in both python 2 and 3
name = native_str(name)
value = native_str(value)
if re.search(r"[\x00-\x20]", name + value):
# Don't let us accidentally inject bad stuff
raise ValueError("Invalid cookie %r: %r" % (name, value))
if name in self._cookies:
del self._cookies[name]
self._cookies[name] = value
morsel = self._cookies[name]
if domain:
morsel["domain"] = domain
if expires_days is not None and not expires:
expires = datetime.datetime.utcnow() + datetime.timedelta(
days=expires_days)
if expires:
morsel["expires"] = format_timestamp(expires)
if path:
morsel["path"] = path
for k, v in kwargs.items():
if k == 'max_age':
k = 'max-age'
# skip falsy values for httponly and secure flags because
# SimpleCookie sets them regardless
if k in ['httponly', 'secure'] and not v:
continue
morsel[k] = v
self.send_command('EXEC', 'document.cookie = "%s";' %
morsel.OutputString().replace('"', '\\"'))
## Data