Fix pylint errors

This commit is contained in:
Sébastien Helleu 2021-11-13 19:50:33 +01:00
parent aa89cf7836
commit 1fe8853608
13 changed files with 79 additions and 64 deletions

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""About dialog box."""
from PySide6 import QtCore, QtWidgets as QtGui from PySide6 import QtCore, QtWidgets as QtGui

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""Management of WeeChat buffers/nicklist."""
from pkg_resources import resource_filename from pkg_resources import resource_filename
from PySide6 import QtCore, QtGui, QtWidgets from PySide6 import QtCore, QtGui, QtWidgets
@ -68,9 +70,6 @@ class GenericListWidget(QtWidgets.QListWidget):
class BufferListWidget(GenericListWidget): class BufferListWidget(GenericListWidget):
"""Widget with list of buffers.""" """Widget with list of buffers."""
def __init__(self, *args):
super().__init__(*args)
def switch_prev_buffer(self): def switch_prev_buffer(self):
if self.currentRow() > 0: if self.currentRow() > 0:
self.setCurrentRow(self.currentRow() - 1) self.setCurrentRow(self.currentRow() - 1)
@ -148,9 +147,9 @@ class Buffer(QtCore.QObject):
bufferInput = QtCore.Signal(str, str) bufferInput = QtCore.Signal(str, str)
def __init__(self, data={}): def __init__(self, data=None):
QtCore.QObject.__init__(self) QtCore.QObject.__init__(self)
self.data = data self.data = data or {}
self.nicklist = {} self.nicklist = {}
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', self.widget = BufferWidget(display_nicklist=self.data.get('nicklist',
0)) 0))
@ -234,12 +233,12 @@ class Buffer(QtCore.QObject):
' ': '', ' ': '',
'+': 'yellow', '+': 'yellow',
} }
color = prefix_color.get(nick['prefix'], 'green') col = prefix_color.get(nick['prefix'], 'green')
if color: if col:
icon = QtGui.QIcon( icon = QtGui.QIcon(
resource_filename(__name__, resource_filename(__name__,
'data/icons/bullet_%s_8x8.png' % 'data/icons/bullet_%s_8x8.png' %
color)) col))
else: else:
pixmap = QtGui.QPixmap(8, 8) pixmap = QtGui.QPixmap(8, 8)
pixmap.fill() pixmap.fill()

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""Chat area."""
import datetime import datetime
from PySide6 import QtCore, QtWidgets, QtGui from PySide6 import QtCore, QtWidgets, QtGui
@ -64,11 +66,11 @@ class ChatTextEdit(QtWidgets.QTextEdit):
def display(self, time, prefix, text, forcecolor=None): def display(self, time, prefix, text, forcecolor=None):
if time == 0: if time == 0:
d = datetime.datetime.now() now = datetime.datetime.now()
else: else:
d = datetime.datetime.fromtimestamp(float(time)) now = datetime.datetime.fromtimestamp(float(time))
self.setTextColor(QtGui.QColor('#999999')) self.setTextColor(QtGui.QColor('#999999'))
self.insertPlainText(d.strftime('%H:%M ')) self.insertPlainText(now.strftime('%H:%M '))
prefix = self._color.convert(prefix) prefix = self._color.convert(prefix)
text = self._color.convert(text) text = self._color.convert(text)
if forcecolor: if forcecolor:
@ -136,5 +138,5 @@ class ChatTextEdit(QtWidgets.QTextEdit):
self._setfont[attr](self._fontvalues[self._font[attr]][attr]) self._setfont[attr](self._fontvalues[self._font[attr]][attr])
def scroll_bottom(self): def scroll_bottom(self):
bar = self.verticalScrollBar() scroll = self.verticalScrollBar()
bar.setValue(bar.maximum()) scroll.setValue(scroll.maximum())

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""Configuration for QWeeChat."""
import configparser import configparser
import os import os

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""Connection window."""
from PySide6 import QtGui, QtWidgets from PySide6 import QtGui, QtWidgets

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""Debug window."""
from PySide6 import QtWidgets from PySide6 import QtWidgets
from qweechat.chat import ChatTextEdit from qweechat.chat import ChatTextEdit

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""Input line for chat and debug window."""
from PySide6 import QtCore, QtWidgets from PySide6 import QtCore, QtWidgets
@ -40,7 +42,7 @@ class InputLineEdit(QtWidgets.QLineEdit):
def keyPressEvent(self, event): def keyPressEvent(self, event):
key = event.key() key = event.key()
modifiers = event.modifiers() modifiers = event.modifiers()
bar = self.scroll_widget.verticalScrollBar() scroll = self.scroll_widget.verticalScrollBar()
if modifiers == QtCore.Qt.ControlModifier: if modifiers == QtCore.Qt.ControlModifier:
if key == QtCore.Qt.Key_PageUp: if key == QtCore.Qt.Key_PageUp:
self.bufferSwitchPrev.emit() self.bufferSwitchPrev.emit()
@ -54,19 +56,19 @@ class InputLineEdit(QtWidgets.QLineEdit):
elif key in (QtCore.Qt.Key_Right, QtCore.Qt.Key_Down): elif key in (QtCore.Qt.Key_Right, QtCore.Qt.Key_Down):
self.bufferSwitchNext.emit() self.bufferSwitchNext.emit()
elif key == QtCore.Qt.Key_PageUp: elif key == QtCore.Qt.Key_PageUp:
bar.setValue(bar.value() - (bar.pageStep() / 10)) scroll.setValue(scroll.value() - (scroll.pageStep() / 10))
elif key == QtCore.Qt.Key_PageDown: elif key == QtCore.Qt.Key_PageDown:
bar.setValue(bar.value() + (bar.pageStep() / 10)) scroll.setValue(scroll.value() + (scroll.pageStep() / 10))
elif key == QtCore.Qt.Key_Home: elif key == QtCore.Qt.Key_Home:
bar.setValue(bar.minimum()) scroll.setValue(scroll.minimum())
elif key == QtCore.Qt.Key_End: elif key == QtCore.Qt.Key_End:
bar.setValue(bar.maximum()) scroll.setValue(scroll.maximum())
else: else:
QtWidgets.QLineEdit.keyPressEvent(self, event) QtWidgets.QLineEdit.keyPressEvent(self, event)
elif key == QtCore.Qt.Key_PageUp: elif key == QtCore.Qt.Key_PageUp:
bar.setValue(bar.value() - bar.pageStep()) scroll.setValue(scroll.value() - scroll.pageStep())
elif key == QtCore.Qt.Key_PageDown: elif key == QtCore.Qt.Key_PageDown:
bar.setValue(bar.value() + bar.pageStep()) scroll.setValue(scroll.value() + scroll.pageStep())
elif key == QtCore.Qt.Key_Up: elif key == QtCore.Qt.Key_Up:
self._history_navigate(-1) self._history_navigate(-1)
elif key == QtCore.Qt.Key_Down: elif key == QtCore.Qt.Key_Down:

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""I/O with WeeChat/relay."""
import struct import struct
from PySide6 import QtCore, QtNetwork from PySide6 import QtCore, QtNetwork

View File

@ -62,7 +62,7 @@ class MainWindow(QtWidgets.QMainWindow):
"""Main window.""" """Main window."""
def __init__(self, *args): def __init__(self, *args):
super().__init__() super().__init__(*args)
self.config = config.read() self.config = config.read()
@ -207,7 +207,7 @@ class MainWindow(QtWidgets.QMainWindow):
"""Save connection configuration.""" """Save connection configuration."""
if self.network: if self.network:
options = self.network.get_options() options = self.network.get_options()
for option in options.keys(): for option in options:
self.config.set('relay', option, options[option]) self.config.set('relay', option, options[option])
def debug_display(self, *args, **kwargs): def debug_display(self, *args, **kwargs):
@ -550,8 +550,8 @@ def main():
app.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks')) app.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks'))
app.setWindowIcon(QtGui.QIcon( app.setWindowIcon(QtGui.QIcon(
resource_filename(__name__, 'data/icons/weechat.png'))) resource_filename(__name__, 'data/icons/weechat.png')))
main = MainWindow() main_win = MainWindow()
main.show() main_win.show()
sys.exit(app.exec_()) sys.exit(app.exec_())

View File

@ -20,8 +20,11 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""Version of QWeeChat."""
VERSION = '0.0.1-dev' VERSION = '0.0.1-dev'
def qweechat_version(): def qweechat_version():
"""Return QWeeChat version."""
return VERSION return VERSION

View File

@ -20,6 +20,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
"""Remove/replace colors in WeeChat strings."""
import re import re
import logging import logging
@ -86,25 +88,25 @@ class Color():
def _rgb_color(self, index): def _rgb_color(self, index):
color = TERMINAL_COLORS[index*6:(index*6)+6] color = TERMINAL_COLORS[index*6:(index*6)+6]
r = int(color[0:2], 16) * 0.85 col_r = int(color[0:2], 16) * 0.85
g = int(color[2:4], 16) * 0.85 col_g = int(color[2:4], 16) * 0.85
b = int(color[4:6], 16) * 0.85 col_b = int(color[4:6], 16) * 0.85
return '%02x%02x%02x' % (r, g, b) return '%02x%02x%02x' % (col_r, col_g, col_b)
def _convert_weechat_color(self, color): def _convert_weechat_color(self, color):
try: try:
index = int(color) index = int(color)
return '\x01(Fr%s)' % self.color_options[index] return '\x01(Fr%s)' % self.color_options[index]
except: # noqa: E722 except Exception: # noqa: E722
log.debug('Error decoding WeeChat color "%s"' % color) log.debug('Error decoding WeeChat color "%s"', color)
return '' return ''
def _convert_terminal_color(self, fg_bg, attrs, color): def _convert_terminal_color(self, fg_bg, attrs, color):
try: try:
index = int(color) index = int(color)
return '\x01(%s%s#%s)' % (fg_bg, attrs, self._rgb_color(index)) return '\x01(%s%s#%s)' % (fg_bg, attrs, self._rgb_color(index))
except: # noqa: E722 except Exception: # noqa: E722
log.debug('Error decoding terminal color "%s"' % color) log.debug('Error decoding terminal color "%s"', color)
return '' return ''
def _convert_color_attr(self, fg_bg, color): def _convert_color_attr(self, fg_bg, color):
@ -126,8 +128,8 @@ class Color():
index = int(color) index = int(color)
return self._convert_terminal_color(fg_bg, attrs, return self._convert_terminal_color(fg_bg, attrs,
WEECHAT_BASIC_COLORS[index][1]) WEECHAT_BASIC_COLORS[index][1])
except: # noqa: E722 except Exception: # noqa: E722
log.debug('Error decoding color "%s"' % color) log.debug('Error decoding color "%s"', color)
return '' return ''
def _attrcode_to_char(self, code): def _attrcode_to_char(self, code):
@ -145,29 +147,27 @@ class Color():
if color[1] == 'b': if color[1] == 'b':
# bar code, ignored # bar code, ignored
return '' return ''
elif color[1] == '\x1C': if color[1] == '\x1C':
# reset # reset
return '\x01(Fr)\x01(Br)' return '\x01(Fr)\x01(Br)'
elif color[1] in ('F', 'B'): if color[1] in ('F', 'B'):
# foreground or background # foreground or background
return self._convert_color_attr(color[1], color[2:]) return self._convert_color_attr(color[1], color[2:])
elif color[1] == '*': if color[1] == '*':
# foreground with optional background # foreground with optional background
items = color[2:].split(',') items = color[2:].split(',')
s = self._convert_color_attr('F', items[0]) str_col = self._convert_color_attr('F', items[0])
if len(items) > 1: if len(items) > 1:
s += self._convert_color_attr('B', items[1]) str_col += self._convert_color_attr('B', items[1])
return s return str_col
elif color[1] == '@': if color[1] == '@':
# direct ncurses pair number, ignored # direct ncurses pair number, ignored
return '' return ''
elif color[1] == 'E': if color[1] == 'E':
# text emphasis, ignored # text emphasis, ignored
return '' return ''
if color[1:].isdigit(): if color[1:].isdigit():
return self._convert_weechat_color(int(color[1:])) return self._convert_weechat_color(int(color[1:]))
# color code
pass
elif color[0] == '\x1A': elif color[0] == '\x1A':
# set attribute # set attribute
return '\x01(+%s)' % self._attrcode_to_char(color[1]) return '\x01(+%s)' % self._attrcode_to_char(color[1])
@ -191,8 +191,7 @@ class Color():
return '' return ''
if self.debug: if self.debug:
return RE_COLOR.sub(self._convert_color_debug, text) return RE_COLOR.sub(self._convert_color_debug, text)
else: return RE_COLOR.sub(self._convert_color, text)
return RE_COLOR.sub(self._convert_color, text)
def remove(text): def remove(text):

View File

@ -30,6 +30,8 @@
# start dev # start dev
# #
"""Decode binary messages received from WeeChat/relay."""
import collections import collections
import struct import struct
import zlib import zlib
@ -49,10 +51,10 @@ class WeechatObject:
self.indent = ' ' if separator == '\n' else '' self.indent = ' ' if separator == '\n' else ''
self.separator1 = '\n%s' % self.indent if separator == '\n' else '' self.separator1 = '\n%s' % self.indent if separator == '\n' else ''
def _str_value(self, v): def _str_value(self, val):
if type(v) is str and v is not None: if isinstance(val, str) and val is not None:
return '\'%s\'' % v return '\'%s\'' % val
return str(v) return str(val)
def _str_value_hdata(self): def _str_value_hdata(self):
lines = ['%skeys: %s%s%spath: %s' % (self.separator1, lines = ['%skeys: %s%s%spath: %s' % (self.separator1,
@ -84,17 +86,17 @@ class WeechatObject:
return self._str_value(self.value) return self._str_value(self.value)
def __str__(self): def __str__(self):
self._obj_cb = { obj_cb = {
'hda': self._str_value_hdata, 'hda': self._str_value_hdata,
'inl': self._str_value_infolist, 'inl': self._str_value_infolist,
} }
return '%s: %s' % (self.objtype, return '%s: %s' % (self.objtype,
self._obj_cb.get(self.objtype, obj_cb.get(self.objtype, self._str_value_other)())
self._str_value_other)())
class WeechatObjects(list): class WeechatObjects(list):
def __init__(self, separator='\n'): def __init__(self, separator='\n'):
super().__init__()
self.separator = separator self.separator = separator
def __str__(self): def __str__(self):
@ -117,16 +119,16 @@ class WeechatMessage:
self.size, self.size_uncompressed, self.size, self.size_uncompressed,
100 - ((self.size * 100) // self.size_uncompressed), 100 - ((self.size * 100) // self.size_uncompressed),
self.msgid, self.objects) self.msgid, self.objects)
else: return 'size: %d, id=\'%s\', objects:\n%s' % (self.size,
return 'size: %d, id=\'%s\', objects:\n%s' % (self.size, self.msgid,
self.msgid, self.objects)
self.objects)
class Protocol: class Protocol:
"""Decode binary message received from WeeChat/relay.""" """Decode binary message received from WeeChat/relay."""
def __init__(self): def __init__(self):
self.data = ''
self._obj_cb = { self._obj_cb = {
'chr': self._obj_char, 'chr': self._obj_char,
'int': self._obj_int, 'int': self._obj_int,
@ -349,7 +351,7 @@ def hex_and_ascii(data, bytes_per_line=10):
char = b'x' char = b'x'
byte = struct.unpack('B', char)[0] byte = struct.unpack('B', char)[0]
str_hex.append(b'%02X' % int(byte)) str_hex.append(b'%02X' % int(byte))
if byte >= 32 and byte <= 127: if 32 <= byte <= 127:
str_ascii.append(char) str_ascii.append(char)
else: else:
str_ascii.append(b'.') str_ascii.append(b'.')

View File

@ -20,9 +20,7 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>. # along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
# #
""" """Command-line program for testing WeeChat/relay protocol."""
Command-line program for testing WeeChat/relay protocol.
"""
import argparse import argparse
import os import os
@ -81,7 +79,7 @@ class TestProto(object):
self.sock.sendall(msg + b'\n') self.sock.sendall(msg + b'\n')
sys.stdout.write( sys.stdout.write(
(b'\x1b[33m<-- ' + msg + b'\x1b[0m\n').decode()) (b'\x1b[33m<-- ' + msg + b'\x1b[0m\n').decode())
except: # noqa: E722 except Exception: # noqa: E722
traceback.print_exc() traceback.print_exc()
print('Failed to send message') print('Failed to send message')
return False return False
@ -106,7 +104,7 @@ class TestProto(object):
protocol.hex_and_ascii(msgd.uncompressed, 20))) protocol.hex_and_ascii(msgd.uncompressed, 20)))
# display decoded message # display decoded message
print('\x1b[32m--> {0}\x1b[0m'.format(msgd)) print('\x1b[32m--> {0}\x1b[0m'.format(msgd))
except: # noqa: E722 except Exception: # noqa: E722
traceback.print_exc() traceback.print_exc()
print('Error while decoding message from WeeChat') print('Error while decoding message from WeeChat')
return False return False
@ -183,7 +181,7 @@ class TestProto(object):
recvbuf = b'' recvbuf = b''
sys.stdout.write((prompt + message).decode()) sys.stdout.write((prompt + message).decode())
sys.stdout.flush() sys.stdout.flush()
except: # noqa: E722 except Exception: # noqa: E722
traceback.print_exc() traceback.print_exc()
self.send(b'quit') self.send(b'quit')
return 0 return 0