def add(self, dn):
        """Add node to tree.

        dn --- distinguished name of node.
        """

        if dn in self.dn_set:
            raise ValueError('A record with dn=%s already exists!' % dn)

        parent_dn = self.get_parent_dn(dn)
        fake_parent = self.get_fake_parent_dn(dn)

        if parent_dn != fake_parent:
            try:
                self.fake_parent[fake_parent].append(dn)
            except KeyError:
                self.fake_parent[fake_parent] = [dn]

        self.parent[dn] = parent_dn
        try:
            self.childs[parent_dn].append(dn)
        except KeyError:
            self.childs[parent_dn] = [dn]

        try:
            for i in self.fake_parent.pop(dn):
                self.childs[""].remove(i)
                self.parent[i] = dn
                try:
                    self.childs[dn].append(i)
                except KeyError:
                    self.childs[dn] = [i]
        except KeyError:
            pass

        self.dn_set.add(dn)
Add node to tree.

        dn --- distinguished name of node.
        
recipes/Python/576966_DnTree/recipe-576966.py