Merge branch 'Konubinix-netrc'
This commit is contained in:
commit
cdb6c6b3a3
@ -182,6 +182,7 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* zwarag
|
* zwarag
|
||||||
* Tim Harder
|
* Tim Harder
|
||||||
* Thiago Barroso Perrotta
|
* Thiago Barroso Perrotta
|
||||||
|
* Samuel Loury
|
||||||
* Matthias Lisin
|
* Matthias Lisin
|
||||||
* Jean-Christophe Petkovich
|
* Jean-Christophe Petkovich
|
||||||
* Helen Sherwood-Taylor
|
* Helen Sherwood-Taylor
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
"""Our own QNetworkAccessManager."""
|
"""Our own QNetworkAccessManager."""
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import netrc
|
||||||
|
|
||||||
from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, QCoreApplication,
|
from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, QCoreApplication,
|
||||||
QUrl, QByteArray)
|
QUrl, QByteArray)
|
||||||
@ -241,12 +242,33 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
@pyqtSlot('QNetworkReply', 'QAuthenticator')
|
@pyqtSlot('QNetworkReply', 'QAuthenticator')
|
||||||
def on_authentication_required(self, reply, authenticator):
|
def on_authentication_required(self, reply, authenticator):
|
||||||
"""Called when a website needs authentication."""
|
"""Called when a website needs authentication."""
|
||||||
answer = self._ask("Username ({}):".format(authenticator.realm()),
|
user, password = None, None
|
||||||
mode=usertypes.PromptMode.user_pwd,
|
if not hasattr(reply, "netrc_used"):
|
||||||
owner=reply)
|
reply.netrc_used = True
|
||||||
if answer is not None:
|
try:
|
||||||
authenticator.setUser(answer.user)
|
net = netrc.netrc()
|
||||||
authenticator.setPassword(answer.password)
|
authenticators = net.authenticators(reply.url().host())
|
||||||
|
if authenticators is not None:
|
||||||
|
# pylint: disable=unpacking-non-sequence
|
||||||
|
(user, _account, password) = authenticators
|
||||||
|
except FileNotFoundError:
|
||||||
|
log.misc.debug("No .netrc file found")
|
||||||
|
except OSError:
|
||||||
|
log.misc.exception("Unable to read the netrc file")
|
||||||
|
except netrc.NetrcParseError:
|
||||||
|
log.misc.exception("Error when parsing the netrc file")
|
||||||
|
|
||||||
|
if user is None:
|
||||||
|
# netrc check failed
|
||||||
|
answer = self._ask(
|
||||||
|
"Username ({}):".format(authenticator.realm()),
|
||||||
|
mode=usertypes.PromptMode.user_pwd,
|
||||||
|
owner=reply)
|
||||||
|
if answer is not None:
|
||||||
|
user, password = answer.user, answer.password
|
||||||
|
if user is not None:
|
||||||
|
authenticator.setUser(user)
|
||||||
|
authenticator.setPassword(password)
|
||||||
|
|
||||||
@pyqtSlot('QNetworkProxy', 'QAuthenticator')
|
@pyqtSlot('QNetworkProxy', 'QAuthenticator')
|
||||||
def on_proxy_authentication_required(self, proxy, authenticator):
|
def on_proxy_authentication_required(self, proxy, authenticator):
|
||||||
|
3
scripts/dev/run_vulture.py
Normal file → Executable file
3
scripts/dev/run_vulture.py
Normal file → Executable file
@ -88,6 +88,9 @@ def whitelist_generator():
|
|||||||
yield 'qutebrowser.utils.log.VDEBUG'
|
yield 'qutebrowser.utils.log.VDEBUG'
|
||||||
yield 'qutebrowser.utils.log.QtWarningFilter.filter'
|
yield 'qutebrowser.utils.log.QtWarningFilter.filter'
|
||||||
yield 'logging.LogRecord.log_color'
|
yield 'logging.LogRecord.log_color'
|
||||||
|
# vulture doesn't notice the hasattr() and thus thinks netrc_used is unused
|
||||||
|
# in NetworkManager.on_authentication_required
|
||||||
|
yield 'PyQt5.QtNetwork.QNetworkReply.netrc_used'
|
||||||
|
|
||||||
for attr in ('fileno', 'truncate', 'closed', 'readable'):
|
for attr in ('fileno', 'truncate', 'closed', 'readable'):
|
||||||
yield 'qutebrowser.utils.qtutils.PyQIODevice.' + attr
|
yield 'qutebrowser.utils.qtutils.PyQIODevice.' + attr
|
||||||
|
Loading…
Reference in New Issue
Block a user