(self, new)
Replace this node with a new one in the parent.
Replace this node with a new one in the parent.
Replace this node with a new one in the parent .
def replace(self, new):
        """Replace this node with a new one in the parent."""
        assert self.parent is not None, str(self)
        assert new is not None
        if not isinstance(new, list):
            new = [new]
        l_children = []
        found = False
        for ch in self.parent.children:
            if ch is self:
                assert not found, (self.parent.children, self, new)
                if new is not None:
                    l_children.extend(new)
                found = True
            else:
                l_children.append(ch)
        assert found, (self.children, self, new)
        self.parent.changed()
        self.parent.children = l_children
        for x in new:
            x.parent = self.parent
        self.parent = None
def replace ( self , new ) : assert self . parent is not None , str ( self ) assert new is not None if not isinstance ( new , list ) : new = [ new ] l_children = [ ] found = False for ch in self . parent . children : if ch is self : assert not found , ( self . parent . children , self , new ) if new is not None : l_children . extend ( new ) found = True else : l_children . append ( ch ) assert found , ( self . children , self , new ) self . parent . changed ( ) self . parent . children = l_children for x in new : x . parent = self . parent self . parent = None