| 80 | return self.childNodes[-1] |
| 81 | |
| 82 | def insertBefore(self, newChild, refChild): |
| 83 | if newChild.nodeType == self.DOCUMENT_FRAGMENT_NODE: |
| 84 | for c in tuple(newChild.childNodes): |
| 85 | self.insertBefore(c, refChild) |
| 86 | ### The DOM does not clearly specify what to return in this case |
| 87 | return newChild |
| 88 | if newChild.nodeType not in self._child_node_types: |
| 89 | raise xml.dom.HierarchyRequestErr( |
| 90 | "%s cannot be child of %s" % (repr(newChild), repr(self))) |
| 91 | if newChild.parentNode is not None: |
| 92 | newChild.parentNode.removeChild(newChild) |
| 93 | if refChild is None: |
| 94 | self.appendChild(newChild) |
| 95 | else: |
| 96 | try: |
| 97 | index = self.childNodes.index(refChild) |
| 98 | except ValueError: |
| 99 | raise xml.dom.NotFoundErr() |
| 100 | if newChild.nodeType in _nodeTypes_with_children: |
| 101 | _clear_id_cache(self) |
| 102 | self.childNodes.insert(index, newChild) |
| 103 | newChild.nextSibling = refChild |
| 104 | refChild.previousSibling = newChild |
| 105 | if index: |
| 106 | node = self.childNodes[index-1] |
| 107 | node.nextSibling = newChild |
| 108 | newChild.previousSibling = node |
| 109 | else: |
| 110 | newChild.previousSibling = None |
| 111 | newChild.parentNode = self |
| 112 | return newChild |
| 113 | |
| 114 | def appendChild(self, node): |
| 115 | if node.nodeType == self.DOCUMENT_FRAGMENT_NODE: |