Use a namedtuple for authentication prompts.

This commit is contained in:
Florian Bruhin 2015-05-06 11:05:17 +02:00
parent 842c69dfdd
commit 024549e3b0
2 changed files with 6 additions and 8 deletions

View File

@ -248,9 +248,8 @@ class NetworkManager(QNetworkAccessManager):
mode=usertypes.PromptMode.user_pwd,
owner=reply)
if answer is not None:
user, password = answer # pylint: disable=unpacking-non-sequence
authenticator.setUser(user)
authenticator.setPassword(password)
authenticator.setUser(answer.user)
authenticator.setPassword(answer.password)
@pyqtSlot('QNetworkProxy', 'QAuthenticator')
def on_proxy_authentication_required(self, proxy, authenticator):
@ -264,10 +263,8 @@ class NetworkManager(QNetworkAccessManager):
answer = self._ask("Proxy username ({}):".format(
authenticator.realm()), mode=usertypes.PromptMode.user_pwd)
if answer is not None:
# pylint: disable=unpacking-non-sequence
user, password = answer
authenticator.setUser(user)
authenticator.setPassword(password)
authenticator.setUser(answer.user)
authenticator.setPassword(answer.password)
_proxy_auth_cache[proxy_id] = answer
@config.change_filter('general', 'private-browsing')

View File

@ -33,6 +33,7 @@ from qutebrowser.utils import usertypes, log, qtutils, objreg, utils
PromptContext = collections.namedtuple('PromptContext',
['question', 'text', 'input_text',
'echo_mode', 'input_visible'])
AuthTuple = collections.namedtuple('AuthTuple', ['user', 'password'])
class Prompter(QObject):
@ -237,7 +238,7 @@ class Prompter(QObject):
elif self._question.mode == usertypes.PromptMode.user_pwd:
# User just entered a password
password = prompt.lineedit.text()
self._question.answer = (self._question.user, password)
self._question.answer = AuthTuple(self._question.user, password)
modeman.maybe_leave(self._win_id, usertypes.KeyMode.prompt,
'prompt accept')
self._question.done()