MCPcopy Index your code
hub / github.com/pyload/pyload / insert

Method insert

module/lib/BeautifulSoup.py:189–246  ·  view source on GitHub ↗
(self, position, newChild)

Source from the content-addressed store, hash-verified

187 return lastChild
188
189 def insert(self, position, newChild):
190 if isinstance(newChild, basestring) \
191 and not isinstance(newChild, NavigableString):
192 newChild = NavigableString(newChild)
193
194 position = min(position, len(self.contents))
195 if hasattr(newChild, 'parent') and newChild.parent is not None:
196 # We're 'inserting' an element that's already one
197 # of this object's children.
198 if newChild.parent is self:
199 index = self.index(newChild)
200 if index > position:
201 # Furthermore we're moving it further down the
202 # list of this object's children. That means that
203 # when we extract this element, our target index
204 # will jump down one.
205 position = position - 1
206 newChild.extract()
207
208 newChild.parent = self
209 previousChild = None
210 if position == 0:
211 newChild.previousSibling = None
212 newChild.previous = self
213 else:
214 previousChild = self.contents[position-1]
215 newChild.previousSibling = previousChild
216 newChild.previousSibling.nextSibling = newChild
217 newChild.previous = previousChild._lastRecursiveChild()
218 if newChild.previous:
219 newChild.previous.next = newChild
220
221 newChildsLastElement = newChild._lastRecursiveChild()
222
223 if position >= len(self.contents):
224 newChild.nextSibling = None
225
226 parent = self
227 parentsNextSibling = None
228 while not parentsNextSibling:
229 parentsNextSibling = parent.nextSibling
230 parent = parent.parent
231 if not parent: # This is the last element in the document.
232 break
233 if parentsNextSibling:
234 newChildsLastElement.next = parentsNextSibling
235 else:
236 newChildsLastElement.next = None
237 else:
238 nextChild = self.contents[position]
239 newChild.nextSibling = nextChild
240 if newChild.nextSibling:
241 newChild.nextSibling.previousSibling = newChild
242 newChildsLastElement.next = nextChild
243
244 if newChildsLastElement.next:
245 newChildsLastElement.next.previous = newChildsLastElement
246 self.contents.insert(position, newChild)

Callers 9

appendMethod · 0.95
registerDateHandlerFunction · 0.45
replaceWithMethod · 0.45
replaceWithChildrenMethod · 0.45
bottle.pyFile · 0.45
do_closeMethod · 0.45
do_closeMethod · 0.45
as_constMethod · 0.45
as_constMethod · 0.45

Calls 4

NavigableStringClass · 0.85
_lastRecursiveChildMethod · 0.80
indexMethod · 0.45
extractMethod · 0.45

Tested by

no test coverage detected