Destructively rips this element out of the tree.
(self)
| 151 | myParent.insert(myIndex, child) |
| 152 | |
| 153 | def extract(self): |
| 154 | """Destructively rips this element out of the tree.""" |
| 155 | if self.parent: |
| 156 | try: |
| 157 | del self.parent.contents[self.parent.index(self)] |
| 158 | except ValueError: |
| 159 | pass |
| 160 | |
| 161 | #Find the two elements that would be next to each other if |
| 162 | #this element (and any children) hadn't been parsed. Connect |
| 163 | #the two. |
| 164 | lastChild = self._lastRecursiveChild() |
| 165 | nextElement = lastChild.next |
| 166 | |
| 167 | if self.previous: |
| 168 | self.previous.next = nextElement |
| 169 | if nextElement: |
| 170 | nextElement.previous = self.previous |
| 171 | self.previous = None |
| 172 | lastChild.next = None |
| 173 | |
| 174 | self.parent = None |
| 175 | if self.previousSibling: |
| 176 | self.previousSibling.nextSibling = self.nextSibling |
| 177 | if self.nextSibling: |
| 178 | self.nextSibling.previousSibling = self.previousSibling |
| 179 | self.previousSibling = self.nextSibling = None |
| 180 | return self |
| 181 | |
| 182 | def _lastRecursiveChild(self): |
| 183 | "Finds the last element beneath this object to be parsed." |
no test coverage detected