Пример #1
0
 def __setitem__(self, key, val):
     if isinstance(key, str):
         key = decode(key)
     if isinstance(val, str):
         val = decode(val)
     super(LDAPNodeAttributes, self).__setitem__(key, val)
     self._set_attrs_modified()
Пример #2
0
    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))
Пример #3
0
 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
Пример #4
0
 def __delitem__(self, key):
     """Do not delete immediately. Just mark LDAPNode to be deleted and
     remove key from self._keys.
     """
     if isinstance(key, str):
         key = decode(key)
     val = self[key]
     val._action = ACTION_DELETE
     # this will also trigger the changed chain
     val.changed = True
     del self._keys[key]
     try:
         self._deleted.append(val)
     except AttributeError:
         self._deleted = list()
         self._deleted.append(val)
Пример #5
0
 def __setitem__(self, key, val):
     if isinstance(key, str):
         key = decode(key)
     if self._child_scope is not ONELEVEL:
         # XXX: this would require a default location for new entries
         raise NotImplementedError(
                 u"Adding with scope != ONELEVEL not supported.")
     if self._key_attr != 'rdn' and self._rdn_attr is None:
         raise RuntimeError(u"Adding with key != rdn needs _rdn_attr "
                 u"to be set.")
     if not isinstance(val, LDAPNode):
         # create one from whatever we got
         val = self._create_suitable_node(val)
     # At this point we need to have an LDAPNode as val
     if self._key_attr != 'rdn' and \
             val.attrs.get(self._rdn_attr) is None:
         raise ValueError(u"'%s' needed in node attributes for rdn." % \
                 (self._rdn_attr,))
     val._session = self._session
     if self._keys is None:
         self._load_keys()
     try:
         # a value with key is already in the directory
         self._keys[key]
     except KeyError:
         # the value is not yet in the directory 
         val._action = ACTION_ADD
         val.changed = True
         self.changed = True 
     self._notify_suppress = True
     super(LDAPNode, self).__setitem__(key, val)
     self._notify_suppress = False
     self._keys[key] = val    
     if self._key_attr == 'rdn':
         rdn = key
     else:
         rdn = '%s=%s' % (self._rdn_attr, val.attrs[self._rdn_attr])
     self._child_dns[key] = ','.join((rdn, self.DN))
     if self._child_objectClasses:
         current_ocs = val.attrs.get('objectClass', [])
         needed_ocs = self._child_objectClasses
         val.attrs['objectClass'] = [
                 x for x in current_ocs + needed_ocs if x not in current_ocs
                 ]
     if val._action == ACTION_ADD:
         objectEventNotify(self.events['added'](val, newParent=self, 
                                                newName=key))
Пример #6
0
 def __getitem__(self, key):
     """Here nodes are created for keys, iff they do not exist already
     """
     if isinstance(key, str):
         key = decode(key)
     if not key in self:
         raise KeyError(u"Entry not existent: %s" % key)
     if self._keys[key] is not None:
         return super(LDAPNode, self).__getitem__(key)
     val = self._ChildClass()
     val._session = self._session
     # We are suppressing notification, as val is not really added to us,
     # rather, it is activated.
     self._notify_suppress = True
     super(LDAPNode, self).__setitem__(key, val)
     self._notify_suppress = False
     self._keys[key] = val
     return val
Пример #7
0
 def __setitem__(self, key, val):
     if isinstance(key, str):
         key = decode(key)
     if self._child_scope is not ONELEVEL:
         raise NotImplementedError(
                 u"Adding with scope != ONELEVEL not supported.")
     if self._key_attr != 'rdn':
         raise NotImplementedError(u"Adding with key != rdn not supported.")
     val._session = self._session
     if self._keys is None:
         self._keys = odict()
     try:
         # a value with key is already in the directory
         self._keys[key]
     except KeyError, e:
         # the value is not yet in the directory 
         val._action = ACTION_ADD
         val.changed = True
         self.changed = True 
Пример #8
0
 def __delitem__(self, key):
     if isinstance(key, str):
         key = decode(key)
     super(LDAPNodeAttributes, self).__delitem__(key)
     self._set_attrs_modified()
Пример #9
0
 def _set_baseDN(self, baseDN):
     if isinstance(baseDN, str):
         # make sure its utf8
         baseDN = decode(baseDN)
     baseDN = encode(baseDN)
     self._communicator.baseDN = baseDN
Пример #10
0
 def _get_baseDN(self):
     baseDN = self._communicator.baseDN
     baseDN = decode(baseDN)
     return baseDN