def exists(self): '''Does this object exist in the LDAP tree?''' try: lc.search(self.get_dn(), ldap.SCOPE_BASE, None, []) return True except ldap.NO_SUCH_OBJECT: return False
def check_all(cls): '''Perform consistency checks. Each LDAP class may define a method check(). When this method is run, all of the check() methods appropriate to each object in the tree are run. If any "assert"s fail, a detailed error message is given''' try: lc.search(cls.cls_dn_str, ldap.SCOPE_BASE, None, []) except Exception,e: lerr("LDAP object of class %s does not exist: %s" % (cls, e))
def check_all(cls): '''Perform consistency checks. Each LDAP class may define a method check(). When this method is run, all of the check() methods appropriate to each object in the tree are run. If any "assert"s fail, a detailed error message is given''' try: lc.search(cls.cls_dn_str, ldap.SCOPE_BASE, None, []) except Exception, e: lerr("LDAP object of class %s does not exist: %s" % (cls, e))
def results(): for (dn, _) in lc.search(cls.cls_dn_str, ldap.SCOPE_SUBTREE, filter.filterstr, []): if dn_to_tuple(dn) not in LDAPClass._classmap: subcls = LDAPClass.get_class_by_dn(dn) assert(issubclass(subcls, cls)) yield subcls(obj_dn=dn)
def results(): for (dn, _) in lc.search(cls.cls_dn_str, ldap.SCOPE_SUBTREE, filter.filterstr, []): if dn_to_tuple(dn) not in LDAPClass._classmap: subcls = LDAPClass.get_class_by_dn(dn) assert (issubclass(subcls, cls)) yield subcls(obj_dn=dn)
def __init__(self, id=None, obj_dn=None): '''Construct an object, given either obj_dn (the string DN of the object) or id (a value for the RDN of the object)''' if obj_dn is None: obj_dn = tuple_to_dn(((type(self).rdn_attr, id),) + self.cls_dn_tuple) self._dn = obj_dn try: # If the case of the dn is wrong, some methods will fail # This will fix it. self._dn = lc.search(obj_dn, 0, None, ['dn'])[0][0] except: # This object is "no such object" pass
def __init__(self, id=None, obj_dn=None): '''Construct an object, given either obj_dn (the string DN of the object) or id (a value for the RDN of the object)''' if obj_dn is None: obj_dn = tuple_to_dn(((type(self).rdn_attr, id), ) + self.cls_dn_tuple) self._dn = obj_dn try: # If the case of the dn is wrong, some methods will fail # This will fix it. self._dn = lc.search(obj_dn, 0, None, ['dn'])[0][0] except: # This object is "no such object" pass
def _raw_readattrs(self, attrlist): res = lc.search(self.get_dn(), ldap.SCOPE_BASE, None, attrlist)[0][1] for a in attrlist: if a not in res: res[a] = [] return res