本文整理汇总了Python中ldap.NO_SUCH_ATTRIBUTE属性的典型用法代码示例。如果您正苦于以下问题:Python ldap.NO_SUCH_ATTRIBUTE属性的具体用法?Python ldap.NO_SUCH_ATTRIBUTE怎么用?Python ldap.NO_SUCH_ATTRIBUTE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ldap
的用法示例。
在下文中一共展示了ldap.NO_SUCH_ATTRIBUTE属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _remove_pubkey
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 别名]
def _remove_pubkey(self, dn, pubkey):
conf = self.conf
modlist = [(ldap.MOD_DELETE, conf.pubkey_attr, _encode(pubkey))]
try:
self._conn.modify_s(dn, modlist)
except ldap.OBJECT_CLASS_VIOLATION:
modlist += [(ldap.MOD_DELETE, 'objectClass', _encode(conf.pubkey_class))]
self._conn.modify_s(dn, modlist)
except ldap.NO_SUCH_ATTRIBUTE:
raise NoPubKeyFoundError("No such public key exists: %s." % keyname(pubkey), 1)
except ldap.INSUFFICIENT_ACCESS:
raise InsufficientAccessError("No rights to remove key for %s " % dn, 2)
示例2: is_member
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 别名]
def is_member(self, ldap_user, group_dn):
"""
Returns True if the group is the user's primary group or if the user is
listed in the group's memberUid attribute.
"""
try:
user_uid = ldap_user.attrs["uid"][0]
try:
is_member = ldap_user.connection.compare_s(
group_dn, "memberUid", user_uid.encode()
)
except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
is_member = False
if not is_member:
try:
user_gid = ldap_user.attrs["gidNumber"][0]
is_member = ldap_user.connection.compare_s(
group_dn, "gidNumber", user_gid.encode()
)
except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
is_member = False
except (KeyError, IndexError):
is_member = False
return is_member
示例3: _is_value_present
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 别名]
def _is_value_present(self, value):
""" True if the target attribute has the given value. """
try:
is_present = bool(
self.connection.compare_s(self.dn, self.name, value))
except ldap.NO_SUCH_ATTRIBUTE:
is_present = False
return is_present
示例4: del_from_groups
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 别名]
def del_from_groups(self, username, groups):
"""Delete user from groups"""
# it follows the same logic than add_to_groups
# but with MOD_DELETE
ldap_client = self._bind()
tmp = self._get_user(self._byte_p2(username), ALL_ATTRS)
if tmp is None:
raise UserDoesntExist(username, self.backend_name)
dn = tmp[0]
attrs = tmp[1]
attrs['dn'] = dn
self._normalize_group_attrs(attrs)
dn = self._byte_p2(tmp[0])
for group in groups:
group = self._byte_p2(group)
for attr in self.group_attrs:
content = self._byte_p2(self.group_attrs[attr] % attrs)
ldif = [(ldap.MOD_DELETE, attr, self._byte_p3(content))]
try:
ldap_client.modify_s(group, ldif)
except ldap.NO_SUCH_ATTRIBUTE as e:
self._logger(
severity=logging.INFO,
msg="%(backend)s: user '%(user)s'"
" wasn't member of group '%(group)s'"
" (attribute '%(attr)s')" % {
'user': username,
'group': self._uni(group),
'attr': attr,
'backend': self.backend_name
}
)
except Exception as e:
ldap_client.unbind_s()
self._exception_handler(e)
ldap_client.unbind_s()
示例5: increment_attr
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 别名]
def increment_attr(self, dn, attr, incr=1, use_increment=True):
import random
import time
if use_increment and \
self.has_control(OID_LDAP_CONTROL_POSTREAD) and \
self.has_feature(OID_LDAP_FEATURE_MODIFY_INCREMENT):
incr = str(incr).encode()
ctrl = ldap.controls.readentry.PostReadControl(attrList=[attr])
res = self.conn.modify_ext_s(dn,
[(ldap.MOD_INCREMENT, attr, incr)],
serverctrls=[ctrl])
for outctrl in res[3]:
if outctrl.controlType == ctrl.controlType:
values = CaseInsensitiveDict(outctrl.entry)[attr]
return int(values[0])
wait = 0
while True:
old_val = self.read_attr(dn, attr, raw=True)[0]
new_val = str(int(old_val) + incr).encode()
try:
self.conn.modify_s(dn,
[(ldap.MOD_DELETE, attr, old_val),
(ldap.MOD_ADD, attr, new_val)])
done = True
except ldap.NO_SUCH_ATTRIBUTE as e:
Core.debug("swap (%r, %r) failed: %r", old_val, new_val, e)
wait += 1
time.sleep(0.05 * 2**random.randint(0, wait))
else:
break
return int(new_val)