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


Python exceptions.SuspiciousSession方法代码示例

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


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

示例1: decode

# 需要导入模块: from django.contrib.sessions import exceptions [as 别名]
# 或者: from django.contrib.sessions.exceptions import SuspiciousSession [as 别名]
def decode(self, session_data):
        encoded_data = base64.b64decode(force_bytes(session_data))
        try:
            # could produce ValueError if there is no ':'
            hash, serialized = encoded_data.split(b':', 1)
            expected_hash = self._hash(serialized)
            if not constant_time_compare(hash.decode(), expected_hash):
                raise SuspiciousSession("Session data corrupted")
            else:
                return self.serializer().loads(serialized)
        except Exception as e:
            # ValueError, SuspiciousOperation, unpickling exceptions. If any of
            # these happen, just return an empty dictionary (an empty session).
            if isinstance(e, SuspiciousOperation):
                logger = logging.getLogger('django.security.%s' %
                        e.__class__.__name__)
                logger.warning(force_text(e))
            return {} 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:20,代码来源:base.py

示例2: decode

# 需要导入模块: from django.contrib.sessions import exceptions [as 别名]
# 或者: from django.contrib.sessions.exceptions import SuspiciousSession [as 别名]
def decode(self, session_data):
        encoded_data = base64.b64decode(force_bytes(session_data))
        try:
            # could produce ValueError if there is no ':'
            hash, serialized = encoded_data.split(b':', 1)
            expected_hash = self._hash(serialized)
            if not constant_time_compare(hash.decode(), expected_hash):
                raise SuspiciousSession("Session data corrupted")
            else:
                return self.serializer().loads(serialized)
        except Exception as e:
            # ValueError, SuspiciousOperation, unpickling exceptions. If any of
            # these happen, just return an empty dictionary (an empty session).
            if isinstance(e, SuspiciousOperation):
                logger = logging.getLogger('django.security.%s' % e.__class__.__name__)
                logger.warning(force_text(e))
            return {} 
开发者ID:KimJangHyeon,项目名称:NarshaTech,代码行数:19,代码来源:base.py


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