Destructively rips this element out of the tree.
(self)
| 166 | myParent.insert(myIndex, child) |
| 167 | |
| 168 | def extract(self): |
| 169 | """Destructively rips this element out of the tree.""" |
| 170 | if self.parent: |
| 171 | try: |
| 172 | del self.parent.contents[self.parent.index(self)] |
| 173 | except ValueError: |
| 174 | pass |
| 175 | |
| 176 | #Find the two elements that would be next to each other if |
| 177 | #this element (and any children) hadn't been parsed. Connect |
| 178 | #the two. |
| 179 | lastChild = self._lastRecursiveChild() |
| 180 | nextElement = lastChild.next |
| 181 | |
| 182 | if self.previous: |
| 183 | self.previous.next = nextElement |
| 184 | if nextElement: |
| 185 | nextElement.previous = self.previous |
| 186 | self.previous = None |
| 187 | lastChild.next = None |
| 188 | |
| 189 | self.parent = None |
| 190 | if self.previousSibling: |
| 191 | self.previousSibling.nextSibling = self.nextSibling |
| 192 | if self.nextSibling: |
| 193 | self.nextSibling.previousSibling = self.previousSibling |
| 194 | self.previousSibling = self.nextSibling = None |
| 195 | return self |
| 196 | |
| 197 | def _lastRecursiveChild(self): |
| 198 | "Finds the last element beneath this object to be parsed." |