| 177 | return oldChild |
| 178 | |
| 179 | def normalize(self): |
| 180 | L = [] |
| 181 | for child in self.childNodes: |
| 182 | if child.nodeType == Node.TEXT_NODE: |
| 183 | if not child.data: |
| 184 | # empty text node; discard |
| 185 | if L: |
| 186 | L[-1].nextSibling = child.nextSibling |
| 187 | if child.nextSibling: |
| 188 | child.nextSibling.previousSibling = child.previousSibling |
| 189 | child.unlink() |
| 190 | elif L and L[-1].nodeType == child.nodeType: |
| 191 | # collapse text node |
| 192 | node = L[-1] |
| 193 | node.data = node.data + child.data |
| 194 | node.nextSibling = child.nextSibling |
| 195 | if child.nextSibling: |
| 196 | child.nextSibling.previousSibling = node |
| 197 | child.unlink() |
| 198 | else: |
| 199 | L.append(child) |
| 200 | else: |
| 201 | L.append(child) |
| 202 | if child.nodeType == Node.ELEMENT_NODE: |
| 203 | child.normalize() |
| 204 | self.childNodes[:] = L |
| 205 | |
| 206 | def cloneNode(self, deep): |
| 207 | return _clone_node(self, deep, self.ownerDocument or self) |