MCPcopy Index your code
hub / github.com/python/cpython / replaceChild

Method replaceChild

Lib/xml/dom/minidom.py:131–161  ·  view source on GitHub ↗
(self, newChild, oldChild)

Source from the content-addressed store, hash-verified

129 return node
130
131 def replaceChild(self, newChild, oldChild):
132 if newChild.nodeType == self.DOCUMENT_FRAGMENT_NODE:
133 refChild = oldChild.nextSibling
134 self.removeChild(oldChild)
135 return self.insertBefore(newChild, refChild)
136 if newChild.nodeType not in self._child_node_types:
137 raise xml.dom.HierarchyRequestErr(
138 "%s cannot be child of %s" % (repr(newChild), repr(self)))
139 if newChild is oldChild:
140 return
141 if newChild.parentNode is not None:
142 newChild.parentNode.removeChild(newChild)
143 try:
144 index = self.childNodes.index(oldChild)
145 except ValueError:
146 raise xml.dom.NotFoundErr()
147 self.childNodes[index] = newChild
148 newChild.parentNode = self
149 oldChild.parentNode = None
150 if (newChild.nodeType in _nodeTypes_with_children
151 or oldChild.nodeType in _nodeTypes_with_children):
152 _clear_id_cache(self)
153 newChild.nextSibling = oldChild.nextSibling
154 newChild.previousSibling = oldChild.previousSibling
155 oldChild.nextSibling = None
156 oldChild.previousSibling = None
157 if newChild.previousSibling:
158 newChild.previousSibling.nextSibling = newChild
159 if newChild.nextSibling:
160 newChild.nextSibling.previousSibling = newChild
161 return oldChild
162
163 def removeChild(self, oldChild):
164 try:

Callers 3

testWholeTextMethod · 0.45
testPatch1094164Method · 0.45

Calls 4

removeChildMethod · 0.95
insertBeforeMethod · 0.95
_clear_id_cacheFunction · 0.85
indexMethod · 0.45

Tested by 3

testWholeTextMethod · 0.36
testPatch1094164Method · 0.36