Destructively rips this element out of the tree.
(self)
| 253 | return wrap_inside |
| 254 | |
| 255 | def extract(self): |
| 256 | """Destructively rips this element out of the tree.""" |
| 257 | if self.parent is not None: |
| 258 | del self.parent.contents[self.parent.index(self)] |
| 259 | |
| 260 | #Find the two elements that would be next to each other if |
| 261 | #this element (and any children) hadn't been parsed. Connect |
| 262 | #the two. |
| 263 | last_child = self._last_descendant() |
| 264 | next_element = last_child.next_element |
| 265 | |
| 266 | if (self.previous_element is not None and |
| 267 | self.previous_element is not next_element): |
| 268 | self.previous_element.next_element = next_element |
| 269 | if next_element is not None and next_element is not self.previous_element: |
| 270 | next_element.previous_element = self.previous_element |
| 271 | self.previous_element = None |
| 272 | last_child.next_element = None |
| 273 | |
| 274 | self.parent = None |
| 275 | if (self.previous_sibling is not None |
| 276 | and self.previous_sibling is not self.next_sibling): |
| 277 | self.previous_sibling.next_sibling = self.next_sibling |
| 278 | if (self.next_sibling is not None |
| 279 | and self.next_sibling is not self.previous_sibling): |
| 280 | self.next_sibling.previous_sibling = self.previous_sibling |
| 281 | self.previous_sibling = self.next_sibling = None |
| 282 | return self |
| 283 | |
| 284 | def _last_descendant(self, is_initialized=True, accept_self=True): |
| 285 | "Finds the last element beneath this object to be parsed." |