MCPcopy
hub / github.com/csev/py4e / replaceWith

Method replaceWith

old/old-code/BeautifulSoup.py:129–142  ·  view source on GitHub ↗
(self, replaceWith)

Source from the content-addressed store, hash-verified

127 self.previousSibling.nextSibling = self
128
129 def replaceWith(self, replaceWith):
130 oldParent = self.parent
131 myIndex = self.parent.index(self)
132 if hasattr(replaceWith, "parent")\
133 and replaceWith.parent is self.parent:
134 # We're replacing this element with one of its siblings.
135 index = replaceWith.parent.index(replaceWith)
136 if index and index < myIndex:
137 # Furthermore, it comes before this element. That
138 # means that when we extract it, the index of this
139 # element will change.
140 myIndex = myIndex - 1
141 self.extract()
142 oldParent.insert(myIndex, replaceWith)
143
144 def replaceWithChildren(self):
145 myParent = self.parent

Callers

nothing calls this directly

Calls 3

extractMethod · 0.95
indexMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected