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

Method insertBefore

Lib/xml/dom/minidom.py:82–112  ·  view source on GitHub ↗
(self, newChild, refChild)

Source from the content-addressed store, hash-verified

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:

Callers 15

replaceChildMethod · 0.95
_updateBarsMethod · 0.45
qnFunction · 0.45
OnFunction · 0.45
BnFunction · 0.45
d3.min.jsFile · 0.45
ZFunction · 0.45
otFunction · 0.45
utFunction · 0.45
QFunction · 0.45

Calls 5

appendChildMethod · 0.95
_clear_id_cacheFunction · 0.85
removeChildMethod · 0.45
indexMethod · 0.45
insertMethod · 0.45

Tested by 4

testInsertBeforeMethod · 0.36
testWholeTextMethod · 0.36
setupMethod · 0.36