How to use the qutebrowser.utils.qtutils.version_check 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 / browser / webengine / webenginequtescheme.py View on Github external
def install(self, profile):
        """Install the handler for qute:// URLs on the given profile."""
        if QWebEngineUrlScheme is not None:
            assert QWebEngineUrlScheme.schemeByName(b'qute') is not None

        profile.installUrlSchemeHandler(b'qute', self)
        if (qtutils.version_check('5.11', compiled=False) and
                not qtutils.version_check('5.12', compiled=False)):
            # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378
            profile.installUrlSchemeHandler(b'chrome-error', self)
            profile.installUrlSchemeHandler(b'chrome-extension', self)
github qutebrowser / qutebrowser / tests / helpers / utils.py View on Github external
import os.path
import contextlib

import pytest

from qutebrowser.utils import qtutils, log


qt58 = pytest.mark.skipif(
    qtutils.version_check('5.9'), reason="Needs Qt 5.8 or earlier")
qt59 = pytest.mark.skipif(
    not qtutils.version_check('5.9'), reason="Needs Qt 5.9 or newer")
qt510 = pytest.mark.skipif(
    not qtutils.version_check('5.10'), reason="Needs Qt 5.10 or newer")
skip_qt511 = pytest.mark.skipif(
    qtutils.version_check('5.11'), reason="Needs Qt 5.10 or earlier")


class PartialCompareOutcome:

    """Storage for a partial_compare error.

    Evaluates to False if an error was found.

    Attributes:
        error: A string describing an error or None.
    """

    def __init__(self, error=None):
        self.error = error

    def __bool__(self):
github qutebrowser / qutebrowser / tests / unit / utils / test_version.py View on Github external
@pytest.mark.skipif(not qtutils.version_check('5.4'),
                    reason="Needs Qt >= 5.4.")
def test_opengl_vendor():
    """Simply call version.opengl_vendor() and see if it doesn't crash."""
    pytest.importorskip("PyQt5.QtOpenGL")
    return version.opengl_vendor()
github qutebrowser / qutebrowser / qutebrowser / browser / webengine / webenginetab.py View on Github external
error.ignore, url, self.url(requested=True)))

        # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-56207
        show_cert_error = (
            not qtutils.version_check('5.9') and
            not error.ignore
        )
        # WORKAROUND for https://codereview.qt-project.org/c/qt/qtwebengine/+/270556
        show_non_overr_cert_error = (
            not error.is_overridable() and (
                # Affected Qt versions:
                # 5.13 before 5.13.2
                # 5.12 before 5.12.6
                # < 5.12
                (qtutils.version_check('5.13') and
                 not qtutils.version_check('5.13.2')) or
                (qtutils.version_check('5.12') and
                 not qtutils.version_check('5.12.6')) or
                not qtutils.version_check('5.12')
            )
        )

        # We can't really know when to show an error page, as the error might
        # have happened when loading some resource.
        # However, self.url() is not available yet and the requested URL
        # might not match the URL we get from the error - so we just apply a
        # heuristic here.
        if ((show_cert_error or show_non_overr_cert_error) and
                url.matches(self.url(requested=True), QUrl.RemoveScheme)):
            self._show_error_page(url, str(error))
github qutebrowser / qutebrowser / qutebrowser / browser / webkit / cache.py View on Github external
def _set_cache_size(self):
        """Set the cache size based on the config."""
        size = config.val.content.cache.size
        if size is None:
            size = 1024 * 1024 * 50  # default from QNetworkDiskCachePrivate
        # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-59909
        if not qtutils.version_check('5.9', compiled=False):
            size = 0  # pragma: no cover
        self.setMaximumCacheSize(size)
github qutebrowser / qutebrowser / qutebrowser / browser / webengine / webenginetab.py View on Github external
def _on_before_load_started(self, url):
        """If we know we're going to visit a URL soon, change the settings.

        This is a WORKAROUND for https://bugreports.qt.io/browse/QTBUG-66656
        """
        super()._on_before_load_started(url)
        if not qtutils.version_check('5.11.1', compiled=False):
            self.settings.update_for_url(url)
github qutebrowser / qutebrowser / qutebrowser / browser / webengine / webenginetab.py View on Github external
def _on_load_progress(self, perc: int) -> None:
        """QtWebEngine-specific loadProgress workarounds.

        WORKAROUND for https://bugreports.qt.io/browse/QTBUG-65223
        """
        super()._on_load_progress(perc)
        if (perc == 100 and
                qtutils.version_check('5.10', compiled=False) and
                self.load_status() != usertypes.LoadStatus.error):
            self._update_load_status(ok=True)
github qutebrowser / qutebrowser / qutebrowser / browser / webengine / webenginedownloads.py View on Github external
def _get_suggested_filename(path):
    """Convert a path we got from chromium to a suggested filename.

    Chromium thinks we want to download stuff to ~/Download, so even if we
    don't, we get downloads with a suffix like (1) for files existing there.

    We simply strip the suffix off via regex.

    See https://bugreports.qt.io/browse/QTBUG-56978
    """
    filename = os.path.basename(path)
    filename = re.sub(r'\([0-9]+\)(?=\.|$)', '', filename)
    if not qtutils.version_check('5.9', compiled=False):
        # https://bugreports.qt.io/browse/QTBUG-58155
        filename = urllib.parse.unquote(filename)
        # Doing basename a *second* time because there could be a %2F in
        # there...
        filename = os.path.basename(filename)
    return filename
github qutebrowser / qutebrowser / qutebrowser / browser / webengine / webview.py View on Github external
def __init__(self, *, tabdata, win_id, private, parent=None):
        super().__init__(parent)
        self._win_id = win_id
        self._tabdata = tabdata

        theme_color = self.style().standardPalette().color(QPalette.Base)
        if private:
            profile = webenginesettings.private_profile
            assert profile.isOffTheRecord()
        else:
            profile = webenginesettings.default_profile
        page = WebEnginePage(theme_color=theme_color, profile=profile,
                             parent=self)
        self.setPage(page)

        if qtutils.version_check('5.11', compiled=False):
            # Set a PseudoLayout as a WORKAROUND for
            # https://bugreports.qt.io/browse/QTBUG-68224
            # and other related issues.
            sip.delete(self.layout())
            self._layout = miscwidgets.PseudoLayout(self)
github qutebrowser / qutebrowser / qutebrowser / browser / webengine / webenginetab.py View on Github external
def _connect_signals(self):
        view = self._widget
        page = view.page()

        page.windowCloseRequested.connect(self.window_close_requested)
        page.linkHovered.connect(self.link_hovered)
        page.loadProgress.connect(self._on_load_progress)
        page.loadStarted.connect(self._on_load_started)
        page.certificate_error.connect(self._on_ssl_errors)
        page.authenticationRequired.connect(self._on_authentication_required)
        page.proxyAuthenticationRequired.connect(
            self._on_proxy_authentication_required)
        page.contentsSizeChanged.connect(self.contents_size_changed)
        page.navigation_request.connect(self._on_navigation_request)

        if qtutils.version_check('5.12'):
            page.printRequested.connect(self._on_print_requested)

        try:
            # pylint: disable=unused-import
            from PyQt5.QtWebEngineWidgets import (  # type: ignore
                QWebEngineClientCertificateSelection)
        except ImportError:
            pass
        else:
            page.selectClientCertificate.connect(
                self._on_select_client_certificate)

        view.titleChanged.connect(self.title_changed)
        view.urlChanged.connect(self._on_url_changed)
        view.renderProcessTerminated.connect(
            self._on_render_process_terminated)