| 162 | self.previousSibling.nextSibling = self |
| 163 | |
| 164 | def replaceWith(self, replaceWith): |
| 165 | oldParent = self.parent |
| 166 | myIndex = self.parent.index(self) |
| 167 | if hasattr(replaceWith, "parent")\ |
| 168 | and replaceWith.parent is self.parent: |
| 169 | # We're replacing this element with one of its siblings. |
| 170 | index = replaceWith.parent.index(replaceWith) |
| 171 | if index and index < myIndex: |
| 172 | # Furthermore, it comes before this element. That |
| 173 | # means that when we extract it, the index of this |
| 174 | # element will change. |
| 175 | myIndex = myIndex - 1 |
| 176 | self.extract() |
| 177 | oldParent.insert(myIndex, replaceWith) |
| 178 | |
| 179 | def replaceWithChildren(self): |
| 180 | myParent = self.parent |