本文整理汇总了Python中passlib.context.CryptPolicy.from_path方法的典型用法代码示例。如果您正苦于以下问题:Python CryptPolicy.from_path方法的具体用法?Python CryptPolicy.from_path怎么用?Python CryptPolicy.from_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类passlib.context.CryptPolicy
的用法示例。
在下文中一共展示了CryptPolicy.from_path方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_01_from_path
# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_path [as 别名]
def test_01_from_path(self):
"test CryptPolicy.from_path() constructor with encodings"
path = self.mktemp()
#test "\n" linesep
set_file(path, self.sample_config_1s)
policy = CryptPolicy.from_path(path)
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
#test "\r\n" linesep
set_file(path, self.sample_config_1s.replace("\n","\r\n"))
policy = CryptPolicy.from_path(path)
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
#test with custom encoding
uc2 = to_bytes(self.sample_config_1s, "utf-16", source_encoding="utf-8")
set_file(path, uc2)
policy = CryptPolicy.from_path(path, encoding="utf-16")
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
示例2: test_01_from_path_simple
# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_path [as 别名]
def test_01_from_path_simple(self):
"test CryptPolicy.from_path() constructor"
#NOTE: this is separate so it can also run under GAE
#test preset stored in existing file
path = self.sample_config_1s_path
policy = CryptPolicy.from_path(path)
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
#test if path missing
self.assertRaises(EnvironmentError, CryptPolicy.from_path, path + 'xxx')
示例3: test_01_from_path
# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_path [as 别名]
def test_01_from_path(self):
"test CryptPolicy.from_path() constructor with encodings"
if gae_env:
return self.skipTest("GAE doesn't offer read/write filesystem access")
path = mktemp()
#test "\n" linesep
set_file(path, self.sample_config_1s)
policy = CryptPolicy.from_path(path)
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
#test "\r\n" linesep
set_file(path, self.sample_config_1s.replace("\n","\r\n"))
policy = CryptPolicy.from_path(path)
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
#test with custom encoding
uc2 = to_bytes(self.sample_config_1s, "utf-16", source_encoding="utf-8")
set_file(path, uc2)
policy = CryptPolicy.from_path(path, encoding="utf-16")
self.assertEqual(policy.to_dict(), self.sample_config_1pd)
示例4: test_context_update
# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_path [as 别名]
def test_context_update():
"""test speed of CryptContext.update()"""
kwds = dict(
schemes = [ "sha512_crypt", "sha256_crypt", "md5_crypt",
"des_crypt", "unix_disabled" ],
deprecated = [ "des_crypt" ],
sha512_crypt__min_rounds=4000,
)
if CryptPolicy:
policy=CryptPolicy.from_path(sample_config_1p)
def helper():
policy.replace(**kwds)
else:
ctx = CryptContext.from_path(sample_config_1p)
def helper():
ctx.copy(**kwds)
return helper
示例5: helper
# 需要导入模块: from passlib.context import CryptPolicy [as 别名]
# 或者: from passlib.context.CryptPolicy import from_path [as 别名]
def helper():
CryptPolicy.from_path(path)