当前位置: 首页>>代码示例>>Python>>正文


Python utils.secure_dumps方法代码示例

本文整理汇总了Python中gluon.utils.secure_dumps方法的典型用法代码示例。如果您正苦于以下问题:Python utils.secure_dumps方法的具体用法?Python utils.secure_dumps怎么用?Python utils.secure_dumps使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gluon.utils的用法示例。


在下文中一共展示了utils.secure_dumps方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _try_store_in_cookie

# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import secure_dumps [as 别名]
def _try_store_in_cookie(self, request, response):
        if self._forget or self._unchanged(response):
            # self.clear_session_cookies()
            self.save_session_id_cookie()
            return False
        name = response.session_data_name
        compression_level = response.session_cookie_compression_level
        value = secure_dumps(dict(self),
                             current._session_cookie_key,
                             compression_level=compression_level)
        rcookies = response.cookies
        rcookies.pop(name, None)
        rcookies[name] = value
        rcookies[name]['path'] = '/'
        expires = response.session_cookie_expires
        if isinstance(expires, datetime.datetime):
            expires = expires.strftime(FMT)
        if expires:
            rcookies[name]['expires'] = expires
        return True 
开发者ID:HackPucBemobi,项目名称:touch-pay-client,代码行数:22,代码来源:globals.py

示例2: _try_store_in_cookie

# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import secure_dumps [as 别名]
def _try_store_in_cookie(self, request, response):
        if self._forget or self._unchanged(response):
            # self.clear_session_cookies()
            self.save_session_id_cookie()
            return False
        name = response.session_data_name
        compression_level = response.session_cookie_compression_level
        value = secure_dumps(dict(self),
                             response.session_cookie_key,
                             compression_level=compression_level)
        rcookies = response.cookies
        rcookies.pop(name, None)
        rcookies[name] = value
        rcookies[name]['path'] = '/'
        expires = response.session_cookie_expires
        if isinstance(expires, datetime.datetime):
            expires = expires.strftime(FMT)
        if expires:
            rcookies[name]['expires'] = expires
        return True 
开发者ID:lucadealfaro,项目名称:true_review_web2py,代码行数:22,代码来源:globals.py

示例3: test_secure_dumps_and_loads

# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import secure_dumps [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): 
开发者ID:HackPucBemobi,项目名称:touch-pay-client,代码行数:42,代码来源:test_utils.py


注:本文中的gluon.utils.secure_dumps方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。