(self, new_parent)
Move all of this tag's children into another tag.
Move all of this tag's children into another tag.
Move all of this tag s children into another tag .
def reparentChildren(self, new_parent):
        """Move all of this tag's children into another tag."""
        element = self.element
        new_parent_element = new_parent.element
        # Determine what this tag's next_element will be once all the children
        # are removed.
        final_next_element = element.next_sibling

        new_parents_last_descendant = new_parent_element._last_descendant(False, False)
        if len(new_parent_element.contents) > 0:
            # The new parent already contains children. We will be
            # appending this tag's children to the end.
            new_parents_last_child = new_parent_element.contents[-1]
            new_parents_last_descendant_next_element = new_parents_last_descendant.next_element
        else:
            # The new parent contains no children.
            new_parents_last_child = None
            new_parents_last_descendant_next_element = new_parent_element.next_element

        to_append = element.contents
        append_after = new_parent.element.contents
        if len(to_append) > 0:
            # Set the first child's previous_element and previous_sibling
            # to elements within the new parent
            first_child = to_append[0]
            first_child.previous_element = new_parents_last_descendant
            first_child.previous_sibling = new_parents_last_child

            # Fix the last child's next_element and next_sibling
            last_child = to_append[-1]
            last_child.next_element = new_parents_last_descendant_next_element
            last_child.next_sibling = None

        for child in to_append:
            child.parent = new_parent_element
            new_parent_element.contents.append(child)

        # Now that this element has no children, change its .next_element.
        element.contents = []
        element.next_element = final_next_element
def reparentChildren ( self , new_parent ) : element = self . element new_parent_element = new_parent . element # Determine what this tag's next_element will be once all the children # are removed. final_next_element = element . next_sibling new_parents_last_descendant = new_parent_element . _last_descendant ( False , False ) if len ( new_parent_element . contents ) > 0 : # The new parent already contains children. We will be # appending this tag's children to the end. new_parents_last_child = new_parent_element . contents [ - 1 ] new_parents_last_descendant_next_element = new_parents_last_descendant . next_element else : # The new parent contains no children. new_parents_last_child = None new_parents_last_descendant_next_element = new_parent_element . next_element to_append = element . contents append_after = new_parent . element . contents if len ( to_append ) > 0 : # Set the first child's previous_element and previous_sibling # to elements within the new parent first_child = to_append [ 0 ] first_child . previous_element = new_parents_last_descendant first_child . previous_sibling = new_parents_last_child # Fix the last child's next_element and next_sibling last_child = to_append [ - 1 ] last_child . next_element = new_parents_last_descendant_next_element last_child . next_sibling = None for child in to_append : child . parent = new_parent_element new_parent_element . contents . append ( child ) # Now that this element has no children, change its .next_element. element . contents = [ ] element . next_element = final_next_element