'Replace `self` node with `new`, where `new` is a node or a
list of nodes.'

def replace_self(self, new):

    update = new
    if (not isinstance(new, Node)):
        try:
            update = new[0]
        except IndexError:
            update = None
    if isinstance(update, Element):
        update.update_basic_atts(self)
    else:
        for att in ('ids', 'names', 'classes', 'dupnames'):
            assert (not self[att]), ('Losing    "%s"    attribute:    %s' % (att, self[att]))
    self.parent.replace(self, new)
