How to use the qutebrowser.utils.utils function in qutebrowser

To help you get started, we’ve selected a few qutebrowser 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 qutebrowser / qutebrowser / qutebrowser / utils / urlmatch.py View on Github external
# self._match_subdomains, as we want to return True here for e.g.
        # file:// as well.
        if self.host is None:
            return True

        # If the hosts are exactly equal, we have a match.
        if host == self.host:
            return True

        # Otherwise, we can only match if our match pattern matches subdomains.
        if not self._match_subdomains:
            return False

        # We don't do subdomain matching against IP addresses, so we can give
        # up now if the test host is an IP address.
        if not utils.raises(ValueError, ipaddress.ip_address, host):
            return False

        # Check if the test host is a subdomain of our host.
        if len(host) <= (len(self.host) + 1):
            return False

        if not host.endswith(self.host):
            return False

        return host[len(host) - len(self.host) - 1] == '.'
github qutebrowser / qutebrowser / qutebrowser / browser / qutescheme.py View on Github external
def qute_javascript(url):
    """Handler for qute://javascript.

    Return content of file given as query parameter.
    """
    path = url.path()
    if path:
        path = "javascript" + os.sep.join(path.split('/'))
        return 'text/html', utils.read_file(path, binary=False)
    else:
        raise UrlInvalidError("No file specified")
github qutebrowser / qutebrowser / qutebrowser / browser / webkit / certificateerror.py View on Github external
def __repr__(self):
        return utils.get_repr(
            self, error=debug.qenum_key(QSslError, self._error.error()),
            string=str(self))
github qutebrowser / qutebrowser / qutebrowser / commands / runners.py View on Github external
def repl_cb(matchobj):
        """Return replacement for given match."""
        var = matchobj.group("var")
        if var not in values:
            values[var] = variables[var]()
        return values[var]
    repl_pattern = re.compile("{(?P<var>" + "|".join(variables.keys()) + ")}")

    try:
        for arg in arglist:
            # using re.sub with callback function replaces all variables in a
            # single pass and avoids expansion of nested variables (e.g.
            # "{url}" from clipboard is not expanded)
            args.append(repl_pattern.sub(repl_cb, arg))
    except utils.ClipboardError as e:
        raise cmdutils.CommandError(e)
    return args
</var>
github qutebrowser / qutebrowser / qutebrowser / browser / shared.py View on Github external
if ignore is None:
            # prompt aborted
            ignore = False
        return ignore
    elif ssl_strict is False:
        log.webview.debug("ssl_strict is False, only warning about errors")
        for err in errors:
            # FIXME we might want to use warn here (non-fatal error)
            # https://github.com/qutebrowser/qutebrowser/issues/114
            message.error('Certificate error: {}'.format(err))
        return True
    elif ssl_strict is True:
        return False
    else:
        raise ValueError("Invalid ssl_strict value {!r}".format(ssl_strict))
    raise utils.Unreachable
github qutebrowser / qutebrowser / qutebrowser / completion / completionwidget.py View on Github external
return self.model().first_item()

        while True:
            idx = self.indexAbove(idx) if upwards else self.indexBelow(idx)
            # wrap around if we arrived at beginning/end
            if not idx.isValid() and upwards:
                return self.model().last_item()
            elif not idx.isValid() and not upwards:
                idx = self.model().first_item()
                self.scrollTo(idx.parent())
                return idx
            elif idx.parent().isValid():
                # Item is a real item, not a category header -> success
                return idx

        raise utils.Unreachable
github qutebrowser / qutebrowser / qutebrowser / browser / browsertab.py View on Github external
def __repr__(self) -&gt; str:
        try:
            qurl = self.url()
            url = qurl.toDisplayString(QUrl.EncodeUnicode)  # type: ignore
        except (AttributeError, RuntimeError) as exc:
            url = '&lt;{}&gt;'.format(exc.__class__.__name__)
        else:
            url = utils.elide(url, 100)
        return utils.get_repr(self, tab_id=self.tab_id, url=url)
github qutebrowser / qutebrowser / qutebrowser / commands / argparser.py View on Github external
types: The allowed type
        value: The value to convert
        str_choices: The allowed choices if the type ends up being a string

    Return:
        The converted value
    """
    if isinstance(typ, str):
        raise TypeError("{}: Legacy string type!".format(param.name))

    if value is param.default:
        return value

    assert isinstance(value, str), repr(value)

    if utils.is_enum(typ):
        _check_choices(param, value, [arg_name(e.name) for e in typ])
        return typ[value.replace('-', '_')]
    elif typ is str:
        if str_choices is not None:
            _check_choices(param, value, str_choices)
        return value
    elif callable(typ):
        # int, float, etc.
        try:
            return typ(value)
        except (TypeError, ValueError):
            msg = '{}: Invalid {} value {}'.format(
                param.name, typ.__name__, value)
            raise cmdexc.ArgumentTypeError(msg)
    else:
        raise ValueError("{}: Unknown type {!r}!".format(param.name, typ))
github qutebrowser / qutebrowser / qutebrowser / config / newconfig.py View on Github external
def __repr__(self):
        return utils.get_repr(self, constructor=True, manager=self._manager,
                              prefix=self._prefix)
github qutebrowser / qutebrowser / qutebrowser / browser / webelem.py View on Github external
def __repr__(self) -> str:
        try:
            html = utils.compact_text(
                self.outer_xml(), 500)  # type: typing.Optional[str]
        except Error:
            html = None
        return utils.get_repr(self, html=html)