How to use the thug.DOM.W3C.Core.DOMException.DOMException function in thug

To help you get started, we’ve selected a few thug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buffer / thug / thug / DOM / W3C / Core / Text.py View on Github external
def splitText(self, offset):
        raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
github buffer / thug / thug / DOM / W3C / HTML / HTMLTableRowElement.py View on Github external
def deleteCell(self, index):
        if index < -1 or index >= len(self.cells.nodes):
            raise DOMException(DOMException.INDEX_SIZE_ERR)

        del self.cells.nodes[index]
github buffer / thug / thug / DOM / W3C / Core / CharacterData.py View on Github external
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:]
github buffer / thug / thug / DOM / W3C / Core / Node.py View on Github external
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
github buffer / thug / thug / DOM / W3C / HTML / HTMLTableElement.py View on Github external
def deleteRow(self, index):
        if index < -1 or index >= len(self.rows.nodes):
            raise DOMException(DOMException.INDEX_SIZE_ERR)

        del self.rows.nodes[index]
github buffer / thug / thug / DOM / W3C / Core / Node.py View on Github external
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
github buffer / thug / thug / DOM / W3C / Core / Node.py View on Github external
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)
github buffer / thug / thug / DOM / W3C / HTML / HTMLSelectElement.py View on Github external
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)
github buffer / thug / thug / DOM / W3C / HTML / HTMLElement.py View on Github external
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)