Fix ALL the lint

This commit is contained in:
Florian Bruhin 2014-05-21 17:29:09 +02:00
parent 1f4ca39e53
commit ecc838d02c
8 changed files with 29 additions and 37 deletions

View File

@ -23,7 +23,7 @@ disable=no-self-use,
[BASIC] [BASIC]
module-rgx=[a-z_]*$ module-rgx=[a-z_]*$
const-rgx=[A-Za-z_][A-Za-z0-9_]{0,30}$ const-rgx=[A-Za-z_][A-Za-z0-9_]{0,30}$
method-rgx=[a-z_][A-Za-z0-9_]{2,30}$ method-rgx=[a-z_][A-Za-z0-9_]{2,40}$
attr-rgx=[a-z_][a-z0-9_]{0,30}$ attr-rgx=[a-z_][a-z0-9_]{0,30}$
argument-rgx=[a-z_][a-z0-9_]{0,30}$ argument-rgx=[a-z_][a-z0-9_]{0,30}$
variable-rgx=[a-z_][a-z0-9_]{0,30}$ variable-rgx=[a-z_][a-z0-9_]{0,30}$

View File

@ -20,11 +20,10 @@
import os import os
import logging import logging
import subprocess import subprocess
from tempfile import mkstemp
from functools import partial from functools import partial
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt, QObject, QProcess from PyQt5.QtCore import Qt, QObject
from PyQt5.QtGui import QClipboard from PyQt5.QtGui import QClipboard
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog
@ -607,7 +606,8 @@ class CommandDispatcher(QObject):
return return
text = elem.evaluateJavaScript('this.value') text = elem.evaluateJavaScript('this.value')
self._editor = ExternalEditor() self._editor = ExternalEditor()
self._editor.editing_finished.connect(partial(self.on_editing_finished, elem)) self._editor.editing_finished.connect(
partial(self.on_editing_finished, elem))
self._editor.edit(text) self._editor.edit(text)
def on_editing_finished(self, elem, text): def on_editing_finished(self, elem, text):

View File

@ -49,6 +49,16 @@ class NetworkManager(QNetworkAccessManager):
self.proxyAuthenticationRequired.connect( self.proxyAuthenticationRequired.connect(
self.on_proxy_authentication_required) self.on_proxy_authentication_required)
def _fill_authenticator(self, authenticator, answer):
"""Fill a given QAuthenticator object with an answer."""
if answer is not None:
# Since the answer could be something else than (user, password)
# pylint seems to think we're unpacking a non-sequence. However we
# *did* explicitely ask for a tuple, so it *will* always be one.
user, password = answer # pylint: disable=unpacking-non-sequence
authenticator.setUser(user)
authenticator.setPassword(password)
def abort_requests(self): def abort_requests(self):
"""Abort all running requests.""" """Abort all running requests."""
for request in self._requests.values(): for request in self._requests.values():
@ -73,25 +83,20 @@ class NetworkManager(QNetworkAccessManager):
reply.ignoreSslErrors() reply.ignoreSslErrors()
@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 = message.modular_question( answer = message.modular_question(
text="Username ({}):".format(authenticator.realm()), "Username ({}):".format(authenticator.realm()),
mode=PromptMode.user_pwd) mode=PromptMode.user_pwd)
if answer is not None: self._fill_authenticator(authenticator, answer)
user, password = answer
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):
"""Called when a proxy needs authentication."""
answer = message.modular_question( answer = message.modular_question(
text="Proxy username ({}):".format(authenticator.realm()), "Proxy username ({}):".format(authenticator.realm()),
mode=PromptMode.user_pwd) mode=PromptMode.user_pwd)
if answer is not None: self._fill_authenticator(authenticator, answer)
user, password = answer
authenticator.setUser(user)
authenticator.setPassword(password)
def createRequest(self, op, req, outgoing_data): def createRequest(self, op, req, outgoing_data):
"""Return a new QNetworkReply object. """Return a new QNetworkReply object.

View File

@ -24,6 +24,7 @@ from tempfile import mkstemp
from PyQt5.QtCore import pyqtSignal, QProcess, QObject from PyQt5.QtCore import pyqtSignal, QProcess, QObject
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.utils.message as message
class ExternalEditor(QObject): class ExternalEditor(QObject):
@ -40,6 +41,7 @@ class ExternalEditor(QObject):
self.proc = None self.proc = None
def _cleanup(self): def _cleanup(self):
"""Clean up temporary files after the editor closed."""
os.close(self.oshandle) os.close(self.oshandle)
try: try:
os.remove(self.filename) os.remove(self.filename)
@ -81,7 +83,7 @@ class ExternalEditor(QObject):
QProcess.WriteError: ("An error occurred when attempting to write " QProcess.WriteError: ("An error occurred when attempting to write "
"to the process."), "to the process."),
QProcess.ReadError: ("An error occurred when attempting to read " QProcess.ReadError: ("An error occurred when attempting to read "
"from the process."), "from the process."),
QProcess.UnknownError: "An unknown error occurred.", QProcess.UnknownError: "An unknown error occurred.",
} }
message.error("Error while calling editor: {}".format(messages[error])) message.error("Error while calling editor: {}".format(messages[error]))

View File

@ -62,11 +62,11 @@ def text(message):
instance().text.emit(message) instance().text.emit(message)
def modular_question(text, mode, default=None): def modular_question(message, mode, default=None):
"""Ask a modular question in the statusbar. """Ask a modular question in the statusbar.
Args: Args:
text: The message to display to the user. message: The message to display to the user.
mode: A PromptMode. mode: A PromptMode.
default: The default value to display. default: The default value to display.
@ -74,7 +74,7 @@ def modular_question(text, mode, default=None):
The answer the user gave or None if the prompt was cancelled. The answer the user gave or None if the prompt was cancelled.
""" """
q = Question() q = Question()
q.text = text q.text = message
q.mode = mode q.mode = mode
q.default = default q.default = default
instance().question.emit(q, True) instance().question.emit(q, True)

View File

@ -35,7 +35,6 @@ from PyQt5.QtCore import QCoreApplication, QStandardPaths
from pkg_resources import resource_string from pkg_resources import resource_string
import qutebrowser import qutebrowser
import qutebrowser.utils.message as message
MAXVALS = { MAXVALS = {
@ -106,7 +105,6 @@ def read_file(filename):
with open(fn, 'r', encoding='UTF-8') as f: with open(fn, 'r', encoding='UTF-8') as f:
return f.read() return f.read()
else: else:
from pkg_resources import resource_string
return resource_string(qutebrowser.__name__, filename).decode('UTF-8') return resource_string(qutebrowser.__name__, filename).decode('UTF-8')

View File

@ -22,7 +22,6 @@ from PyQt5.QtWidgets import QHBoxLayout, QWidget, QLineEdit
import qutebrowser.keyinput.modeman as modeman import qutebrowser.keyinput.modeman as modeman
import qutebrowser.commands.utils as cmdutils import qutebrowser.commands.utils as cmdutils
import qutebrowser.config.config as config
from qutebrowser.widgets.statusbar._textbase import TextBase from qutebrowser.widgets.statusbar._textbase import TextBase
from qutebrowser.widgets.misc import MinimalLineEdit from qutebrowser.widgets.misc import MinimalLineEdit
from qutebrowser.utils.usertypes import PromptMode, Question from qutebrowser.utils.usertypes import PromptMode, Question

View File

@ -206,7 +206,8 @@ class StatusBar(QWidget):
def _hide_prompt_widget(self): def _hide_prompt_widget(self):
"""Show temporary text instead of prompt widget.""" """Show temporary text instead of prompt widget."""
logging.debug("Hiding prompt widget, queue: {}".format(self._text_queue)) logging.debug("Hiding prompt widget, queue: {}".format(
self._text_queue))
if self._timer_was_active: if self._timer_was_active:
# Restart the text pop timer if it was active before hiding. # Restart the text pop timer if it was active before hiding.
self._pop_text() self._pop_text()
@ -317,19 +318,6 @@ class StatusBar(QWidget):
self._text_pop_timer.setInterval(config.get('ui', self._text_pop_timer.setInterval(config.get('ui',
'message-timeout')) 'message-timeout'))
@pyqtSlot('QNetworkProxy', 'QAuthenticator')
def on_proxy_authentication_required(self, proxy, authenticator):
q = Question()
q.mode = PromptMode.user_pwd
q.text = "Proxy username ({}):".format(authenticator.realm())
self.prompt.question = q
answer = self.prompt.exec_()
if answer is not None:
user, password = answer
logging.debug("user: {} / pwd: {}".format(user, password))
authenticator.setUser(user)
authenticator.setPassword(password)
def resizeEvent(self, e): def resizeEvent(self, e):
"""Extend resizeEvent of QWidget to emit a resized signal afterwards. """Extend resizeEvent of QWidget to emit a resized signal afterwards.