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) pos += 1
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 deleteCell(self, index): if index < -1 or index >= len(self.cells.nodes): raise DOMException(DOMException.INDEX_SIZE_ERR) del self.cells.nodes[index]
def setLength(self): raise DOMException(DOMException.NOT_SUPPORTED_ERR)
def createEvent(self, eventType): if eventType not in EventMap: raise DOMException(DOMException.NOT_SUPPORTED_ERR) return EventMap[eventType]()
def createEvent(self, eventType): raise DOMException(DOMException.NOT_SUPPORTED_ERR)