當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。