コード例 #1
0
ファイル: inmemory.py プロジェクト: omit66/ldaptor
 def addChild(self, rdn, attributes):
     """TODO ugly API. Returns the created entry."""
     rdn = distinguishedname.RelativeDistinguishedName(rdn)
     rdn_str = rdn.toWire()
     if rdn_str in self._children:
         raise ldaperrors.LDAPEntryAlreadyExists(self._children[rdn_str].dn)
     dn = distinguishedname.DistinguishedName(listOfRDNs=(rdn, ) +
                                              self.dn.split())
     e = self.__class__(dn, attributes)
     e._parent = self
     self._children[rdn_str] = e
     return e
コード例 #2
0
    def _addChild(self, rdn, attributes):
        rdn = distinguishedname.RelativeDistinguishedName(rdn)
        for c in self._sync_children():
            if c.dn.split()[0] == rdn:
                raise ldaperrors.LDAPEntryAlreadyExists(c.dn.getText())

        dn = distinguishedname.DistinguishedName(listOfRDNs=(rdn, ) +
                                                 self.dn.split())
        e = entry.BaseLDAPEntry(dn, attributes)
        if not os.path.exists(self.path):
            os.mkdir(self.path)
        fileName = os.path.join(self.path, u'%s' % rdn.getText())
        tmp = u'%s.%s.tmp' % (fileName, str(uuid.uuid4()))
        f = open(tmp, 'wb')
        f.write(e.toWire())
        f.close()
        os.rename(tmp, fileName + u'.ldif')
        dirName = os.path.join(self.path, u'%s.dir' % rdn.getText())
        e = self.__class__(dirName, dn)
        return e