Work around QUrl::query() not being available with PyQt 5.9.1
See https://www.riverbankcomputing.com/pipermail/pyqt/2017-November/039702.html
This commit is contained in:
parent
2514b009af
commit
b55bb5dc6f
@ -64,6 +64,8 @@ Fixed
|
|||||||
- Sites like `qute://help` now redirect to `qute://help/` to make sure links
|
- Sites like `qute://help` now redirect to `qute://help/` to make sure links
|
||||||
work properly.
|
work properly.
|
||||||
- Fixes for the size calculation of pinned tabs in the tab bar.
|
- Fixes for the size calculation of pinned tabs in the tab bar.
|
||||||
|
- Worked around a crash with PyQt 5.9.1 compiled against Qt < 5.9.1 when using
|
||||||
|
:yank or qute:// URLs.
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
@ -814,7 +814,7 @@ class CommandDispatcher:
|
|||||||
flags |= QUrl.FullyEncoded
|
flags |= QUrl.FullyEncoded
|
||||||
url = QUrl(self._current_url())
|
url = QUrl(self._current_url())
|
||||||
url_query = QUrlQuery()
|
url_query = QUrlQuery()
|
||||||
url_query_str = url.query()
|
url_query_str = urlutils.query_string(url)
|
||||||
if '&' not in url_query_str and ';' in url_query_str:
|
if '&' not in url_query_str and ';' in url_query_str:
|
||||||
url_query.setQueryDelimiters('=', ';')
|
url_query.setQueryDelimiters('=', ';')
|
||||||
url_query.setQuery(url_query_str)
|
url_query.setQuery(url_query_str)
|
||||||
|
@ -36,7 +36,7 @@ from PyQt5.QtCore import QUrlQuery, QUrl
|
|||||||
import qutebrowser
|
import qutebrowser
|
||||||
from qutebrowser.config import config, configdata, configexc, configdiff
|
from qutebrowser.config import config, configdata, configexc, configdiff
|
||||||
from qutebrowser.utils import (version, utils, jinja, log, message, docutils,
|
from qutebrowser.utils import (version, utils, jinja, log, message, docutils,
|
||||||
objreg)
|
objreg, urlutils)
|
||||||
from qutebrowser.misc import objects
|
from qutebrowser.misc import objects
|
||||||
|
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ def data_for_url(url):
|
|||||||
"""
|
"""
|
||||||
path = url.path()
|
path = url.path()
|
||||||
host = url.host()
|
host = url.host()
|
||||||
query = url.query()
|
query = urlutils.query_string(url)
|
||||||
# A url like "qute:foo" is split as "scheme:path", not "scheme:host".
|
# A url like "qute:foo" is split as "scheme:path", not "scheme:host".
|
||||||
log.misc.debug("url: {}, path: {}, host {}".format(
|
log.misc.debug("url: {}, path: {}, host {}".format(
|
||||||
url.toDisplayString(), path, host))
|
url.toDisplayString(), path, host))
|
||||||
|
@ -26,7 +26,7 @@ import ipaddress
|
|||||||
import posixpath
|
import posixpath
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl, QUrlQuery
|
||||||
from PyQt5.QtNetwork import QHostInfo, QHostAddress, QNetworkProxy
|
from PyQt5.QtNetwork import QHostInfo, QHostAddress, QNetworkProxy
|
||||||
|
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
@ -615,6 +615,18 @@ def safe_display_string(qurl):
|
|||||||
return qurl.toDisplayString()
|
return qurl.toDisplayString()
|
||||||
|
|
||||||
|
|
||||||
|
def query_string(qurl):
|
||||||
|
"""Get a query string for the given URL.
|
||||||
|
|
||||||
|
This is a WORKAROUND for:
|
||||||
|
https://www.riverbankcomputing.com/pipermail/pyqt/2017-November/039702.html
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return qurl.query()
|
||||||
|
except AttributeError: # pragma: no cover
|
||||||
|
return QUrlQuery(qurl).query()
|
||||||
|
|
||||||
|
|
||||||
class InvalidProxyTypeError(Exception):
|
class InvalidProxyTypeError(Exception):
|
||||||
|
|
||||||
"""Error raised when proxy_from_url gets an unknown proxy type."""
|
"""Error raised when proxy_from_url gets an unknown proxy type."""
|
||||||
|
@ -758,6 +758,11 @@ def test_safe_display_string_invalid():
|
|||||||
urlutils.safe_display_string(QUrl())
|
urlutils.safe_display_string(QUrl())
|
||||||
|
|
||||||
|
|
||||||
|
def test_query_string():
|
||||||
|
url = QUrl('https://www.example.com/?foo=bar')
|
||||||
|
assert urlutils.query_string(url) == 'foo=bar'
|
||||||
|
|
||||||
|
|
||||||
class TestProxyFromUrl:
|
class TestProxyFromUrl:
|
||||||
|
|
||||||
@pytest.mark.parametrize('url, expected', [
|
@pytest.mark.parametrize('url, expected', [
|
||||||
|
Loading…
Reference in New Issue
Block a user