本文整理匯總了Python中gluon.utils.secure_loads方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.secure_loads方法的具體用法?Python utils.secure_loads怎麽用?Python utils.secure_loads使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gluon.utils
的用法示例。
在下文中一共展示了utils.secure_loads方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_secure_dumps_and_loads
# 需要導入模塊: from gluon import utils [as 別名]
# 或者: from gluon.utils import secure_loads [as 別名]
def test_secure_dumps_and_loads(self):
""" Tests secure_dumps and secure_loads"""
testobj = {'a': 1, 'b': 2}
testkey = 'mysecret'
secured = secure_dumps(testobj, testkey)
original = secure_loads(secured, testkey)
self.assertEqual(testobj, original)
self.assertTrue(isinstance(secured, bytes))
self.assertTrue(secured.count(b':') == 2)
secured_deprecated = gluon.utils.secure_dumps_deprecated(testobj, testkey)
original_deprecated = secure_loads(secured_deprecated, testkey)
self.assertEqual(testobj, original_deprecated)
self.assertTrue(isinstance(secured_deprecated, bytes))
self.assertTrue(secured_deprecated.count(b':') == 1)
large_testobj = [x for x in range(1000)]
secured_comp = secure_dumps(large_testobj, testkey, compression_level=9)
original_comp = secure_loads(secured_comp, testkey, compression_level=9)
self.assertEqual(large_testobj, original_comp)
secured = secure_dumps(large_testobj, testkey)
self.assertTrue(len(secured_comp) < len(secured))
testhash = 'myhash'
secured = secure_dumps(testobj, testkey, testhash)
original = secure_loads(secured, testkey, testhash)
self.assertEqual(testobj, original)
wrong1 = secure_loads(secured, testkey, 'wronghash')
self.assertEqual(wrong1, None)
wrong2 = secure_loads(secured, 'wrongkey', testhash)
self.assertEqual(wrong2, None)
wrong3 = secure_loads(secured, 'wrongkey', 'wronghash')
self.assertEqual(wrong3, None)
wrong4 = secure_loads(b'abc', 'a', 'b')
self.assertEqual(wrong4, None)
# TODO: def test_initialize_urandom(self):
# TODO: def test_fast_urandom16(self):