本文整理汇总了Python中django.contrib.sessions.exceptions.InvalidSessionKey方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.InvalidSessionKey方法的具体用法?Python exceptions.InvalidSessionKey怎么用?Python exceptions.InvalidSessionKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.sessions.exceptions
的用法示例。
在下文中一共展示了exceptions.InvalidSessionKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _key_to_file
# 需要导入模块: from django.contrib.sessions import exceptions [as 别名]
# 或者: from django.contrib.sessions.exceptions import InvalidSessionKey [as 别名]
def _key_to_file(self, session_key=None):
"""
Get the file associated with this session key.
"""
if session_key is None:
session_key = self._get_or_create_session_key()
# Make sure we're not vulnerable to directory traversal. Session keys
# should always be md5s, so they should never contain directory
# components.
if not set(session_key).issubset(set(VALID_KEY_CHARS)):
raise InvalidSessionKey(
"Invalid characters in session key")
return os.path.join(self.storage_path, self.file_prefix + session_key)
示例2: test_invalid_key_backslash
# 需要导入模块: from django.contrib.sessions import exceptions [as 别名]
# 或者: from django.contrib.sessions.exceptions import InvalidSessionKey [as 别名]
def test_invalid_key_backslash(self):
# Ensure we don't allow directory-traversal.
# This is tested directly on _key_to_file, as load() will swallow
# a SuspiciousOperation in the same way as an IOError - by creating
# a new session, making it unclear whether the slashes were detected.
self.assertRaises(InvalidSessionKey,
self.backend()._key_to_file, "a\\b\\c")
示例3: test_invalid_key_forwardslash
# 需要导入模块: from django.contrib.sessions import exceptions [as 别名]
# 或者: from django.contrib.sessions.exceptions import InvalidSessionKey [as 别名]
def test_invalid_key_forwardslash(self):
# Ensure we don't allow directory-traversal
self.assertRaises(InvalidSessionKey,
self.backend()._key_to_file, "a/b/c")