def _perform(self, function, *args, **kwargs): """Try to perform the given function with the given argument. If LDAP directory is down, bind again and retry given function. XXX: * Improve retry logic in LDAPSession * Extend LDAPSession object to handle Fallback server(s) """ args = encode(args) kwargs = encode(kwargs) if self._communicator._con is None: self._communicator.bind() try: return decode(function(*args, **kwargs)) except ldap.SERVER_DOWN: self._communicator.bind() return decode(function(*args, **kwargs))
def _calculate_key(self, dn, attrs): if self._key_attr == 'rdn': # explode_dn is ldap world key = decode(explode_dn(encode(dn))[0]) else: key = attrs[self._key_attr] if isinstance(key, list): if len(key) != 1: raise KeyError(u"Expected one value for '%s' "+ u"not %s: '%s'." % \ (self._key_attr, len(key), key)) key = key[0] return key
def _set_baseDN(self, baseDN): if isinstance(baseDN, str): # make sure its utf8 baseDN = decode(baseDN) baseDN = encode(baseDN) self._communicator.baseDN = baseDN