Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def splitText(self, offset):
raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
def deleteCell(self, index):
if index < -1 or index >= len(self.cells.nodes):
raise DOMException(DOMException.INDEX_SIZE_ERR)
del self.cells.nodes[index]
def insertData(self, offset, arg):
if offset > len(self.data):
raise DOMException(DOMException.INDEX_SIZE_ERR)
self.data = self.data[:offset] + arg + self.data[offset:]
def insertBefore(self, newChild, refChild):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_insertbefore_count()
if not newChild:
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
if not isinstance(newChild, Node):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
# If refChild is null, insert newChild at the end of the list
# of children
if not refChild:
return self.appendChild(newChild)
if not isinstance(refChild, Node):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
# If the newChild is already in the tree, it is first removed
if getattr(newChild, 'tag', None) and newChild.tag in self.tag.contents:
newChildHash = hash(newChild.tag._node)
for p in self.tag.contents:
if getattr(p, '_node', None) is None:
continue
def deleteRow(self, index):
if index < -1 or index >= len(self.rows.nodes):
raise DOMException(DOMException.INDEX_SIZE_ERR)
del self.rows.nodes[index]
def removeChild(self, oldChild):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_removechild_count()
# NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
if self.is_readonly(self):
raise DOMException(DOMException.NO_MODIFICATION_ALLOWED)
if not oldChild:
raise DOMException(DOMException.NOT_FOUND_ERR)
if not isinstance(oldChild, Node):
raise DOMException(DOMException.NOT_FOUND_ERR)
index = self.findChild(oldChild)
if index < 0 and not self.is_text(oldChild):
raise DOMException(DOMException.NOT_FOUND_ERR)
if getattr(oldChild, 'tag', None) and oldChild.tag in self.tag.contents:
oldChildHash = hash(oldChild.tag._node)
for p in self.tag.contents:
if getattr(p, '_node', None) is None:
continue
if oldChildHash == hash(p._node):
p.extract()
return oldChild
def insertBefore(self, newChild, refChild):
if log.ThugOpts.features_logging:
log.ThugLogging.Features.increase_insertbefore_count()
if not newChild:
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
if not isinstance(newChild, Node):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
# If refChild is null, insert newChild at the end of the list
# of children
if not refChild:
return self.appendChild(newChild)
if not isinstance(refChild, Node):
raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)
# If the newChild is already in the tree, it is first removed
if getattr(newChild, 'tag', None) and newChild.tag in self.tag.contents:
newChildHash = hash(newChild.tag._node)
def add(self, element, before):
if not before:
self._options.append(element)
return
index = None
for opt in self._options:
if before.value in (opt.value, ):
index = self._options.index(opt)
if index is None:
raise DOMException(DOMException.NOT_FOUND_ERR)
self._options.insert(index, element)
def insertAdjacentHTML(self, position, text):
if position not in ('beforebegin', 'afterbegin', 'beforeend', 'afterend', ):
raise DOMException(DOMException.NOT_SUPPORTED_ERR)
if position in ('beforebegin', ):
target = self.tag.parent if self.tag.parent else self.doc.find('body')
pos = target.index(self.tag) - 1
if position in ('afterbegin', ):
target = self.tag
pos = 0
if position in ('beforeend', ):
target = self.tag
pos = len(list(self.tag.children))
if position in ('afterend', ):
target = self.tag.parent if self.tag.parent else self.doc.find('body')
pos = target.index(self.tag) + 1
for node in bs4.BeautifulSoup(text, "html.parser").contents:
target.insert(pos, node)