Example #1
0
    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
Example #2
0
    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)
Example #3
0
    def deleteCell(self, index):
        if index < -1 or index >= len(self.cells.nodes):
            raise DOMException(DOMException.INDEX_SIZE_ERR)

        del self.cells.nodes[index]
Example #4
0
 def setLength(self):
     raise DOMException(DOMException.NOT_SUPPORTED_ERR)
Example #5
0
    def createEvent(self, eventType):
        if eventType not in EventMap:
            raise DOMException(DOMException.NOT_SUPPORTED_ERR)

        return EventMap[eventType]()
Example #6
0
 def createEvent(self, eventType):
     raise DOMException(DOMException.NOT_SUPPORTED_ERR)