本文整理汇总了Python中pymongo.helpers._password_digest函数的典型用法代码示例。如果您正苦于以下问题:Python _password_digest函数的具体用法?Python _password_digest怎么用?Python _password_digest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_password_digest函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_password_digest
def test_password_digest(self):
self.assertRaises(TypeError, helpers._password_digest, 5)
self.assertRaises(TypeError, helpers._password_digest, True)
self.assertRaises(TypeError, helpers._password_digest, None)
self.assert_(isinstance(helpers._password_digest("mike", "password"), unicode))
self.assertEqual(helpers._password_digest("mike", "password"), u"cd7e45b3b2767dc2fa9b6b548457ed00")
self.assertEqual(helpers._password_digest("mike", "password"), helpers._password_digest(u"mike", u"password"))
self.assertEqual(helpers._password_digest("Gustave", u"Dor\xe9"), u"81e0e2364499209f466e75926a162d73")
示例2: add_user
def add_user(self, name, password, read_only=False):
"""Create user `name` with password `password`.
Add a new user with permissions for this :class:`Database`.
.. note:: Will change the password if user `name` already exists.
:Parameters:
- `name`: the name of the user to create
- `password`: the password of the user to create
- `read_only` (optional): if ``True`` it will make user read only
.. versionchanged:: 2.2
Added support for read only users
.. versionadded:: 1.4
"""
user = self.system.users.find_one({"user": name}) or {"user": name}
user["pwd"] = helpers._password_digest(name, password)
user["readOnly"] = common.validate_boolean("read_only", read_only)
try:
self.system.users.save(user, safe=True)
except OperationFailure, e:
# First admin user add fails gle in MongoDB >= 2.1.2
# See SERVER-4225 for more information.
if "login" in str(e):
pass
else:
raise
示例3: add_user
def add_user(self, name, password):
#pymongo中的加了角色缺少readOnly属性
#self._db.add_user(name, password)
from pymongo import common, helpers
pwd = helpers._password_digest(name, password)
self._db.system.users.update({"user": name},
{"user": name,
"pwd": pwd,
"readOnly": False},
upsert=True, safe=True)
示例4: add_user
def add_user(self, name, password):
"""Create user `name` with password `password`.
Add a new user with permissions for this :class:`Database`.
.. note:: Will change the password if user `name` already exists.
:Parameters:
- `name`: the name of the user to create
- `password`: the password of the user to create
.. versionadded:: 1.4
"""
pwd = helpers._password_digest(name, password)
self.system.users.update({"user": name}, {"user": name, "pwd": pwd}, upsert=True, safe=True)
示例5: add_user
def add_user(self, name, password, read_only=False):
"""Create user `name` with password `password`.
Add a new user with permissions for this :class:`Database`.
.. note:: Will change the password if user `name` already exists.
:Parameters:
- `name`: the name of the user to create
- `password`: the password of the user to create
- `read_only` (optional): if ``True`` it will make user read only
.. versionchanged:: 2.2
Added support for read only users
.. versionadded:: 1.4
"""
pwd = helpers._password_digest(name, password)
self.system.users.update(
{"user": name}, {"user": name, "pwd": pwd, "readOnly": read_only}, upsert=True, safe=True
)