conftypes: Use special SYSTEM_PROXY object instead of 0.

This commit is contained in:
Florian Bruhin 2014-08-05 21:04:37 +02:00
parent c94ff7b946
commit 309ecb95c8
2 changed files with 6 additions and 4 deletions

View File

@ -31,6 +31,9 @@ from PyQt5.QtNetwork import QNetworkProxy
import qutebrowser.commands.utils as cmdutils
SYSTEM_PROXY = object() # Return value for Proxy type
class ValidationError(ValueError):
"""Exception raised when a value for a config type was invalid.
@ -997,7 +1000,7 @@ class Proxy(BaseType):
if not value:
return None
elif value == 'system':
return None
return SYSTEM_PROXY
elif value == 'none':
return QNetworkProxy(QNetworkProxy.NoProxy)
url = QUrl(value)

View File

@ -20,6 +20,7 @@
"""Handling of proxies."""
import qutebrowser.config.config as config
from qutebrowser.config.conftypes import SYSTEM_PROXY
from PyQt5.QtNetwork import QNetworkProxyFactory
@ -43,9 +44,7 @@ class ProxyFactory(QNetworkProxyFactory):
A list of QNetworkProxy objects in order of preference.
"""
proxy = config.get('network', 'proxy')
if proxy is None:
# config.get returns a QNetworkProxy for all cases, except when we
# should use the system proxy -- then it returns None.
if proxy is SYSTEM_PROXY:
return QNetworkProxyFactory.systemProxyForQuery(query)
else:
return [proxy]