Skip to content

Commit 8d33f3c

Browse files
committed
Changes based on style and lint checks. Some empty docstrings remain to be completed in the future. (final_code_quality_9)
1 parent 6969ec0 commit 8d33f3c

File tree

6 files changed

+252
-145
lines changed

6 files changed

+252
-145
lines changed

src/bitmessageqt/addressvalidator.py

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
from PyQt4 import QtGui
1+
"""
2+
src/bitmessageqt/addressvalidator.py
3+
====================================
4+
"""
5+
# pylint: disable=too-many-branches,too-many-arguments
26
from Queue import Empty
37

4-
from addresses import decodeAddress, addBMIfNotPresent
8+
from PyQt4 import QtGui
9+
510
from account import getSortedAccounts
6-
from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue
11+
from addresses import addBMIfNotPresent, decodeAddress
12+
from queues import addressGeneratorQueue, apiAddressGeneratorReturnQueue
713
from tr import _translate
814
from utils import str_chan
915

10-
class AddressPassPhraseValidatorMixin():
11-
def setParams(self, passPhraseObject=None, addressObject=None, feedBackObject=None, buttonBox=None, addressMandatory=True):
16+
17+
class AddressPassPhraseValidatorMixin(object):
18+
""""""
19+
def setParams(
20+
self,
21+
passPhraseObject=None,
22+
addressObject=None,
23+
feedBackObject=None,
24+
buttonBox=None,
25+
addressMandatory=True):
26+
""""""
27+
# pylint: disable=too-many-arguments
1228
self.addressObject = addressObject
1329
self.passPhraseObject = passPhraseObject
1430
self.feedBackObject = feedBackObject
@@ -19,6 +35,7 @@ def setParams(self, passPhraseObject=None, addressObject=None, feedBackObject=No
1935
self.okButtonLabel = self.buttonBox.button(QtGui.QDialogButtonBox.Ok).text()
2036

2137
def setError(self, string):
38+
""""""
2239
if string is not None and self.feedBackObject is not None:
2340
font = QtGui.QFont()
2441
font.setBold(True)
@@ -31,9 +48,14 @@ def setError(self, string):
3148
if string is not None and self.feedBackObject is not None:
3249
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(_translate("AddressValidator", "Invalid"))
3350
else:
34-
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(_translate("AddressValidator", "Validating..."))
51+
self.buttonBox.button(
52+
QtGui.QDialogButtonBox.Ok).setText(
53+
_translate(
54+
"AddressValidator",
55+
"Validating..."))
3556

3657
def setOK(self, string):
58+
""""""
3759
if string is not None and self.feedBackObject is not None:
3860
font = QtGui.QFont()
3961
font.setBold(False)
@@ -45,7 +67,8 @@ def setOK(self, string):
4567
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
4668
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(self.okButtonLabel)
4769

48-
def checkQueue(self):
70+
def checkQueue(self): # pylint: disable=inconsistent-return-statements
71+
""""""
4972
gotOne = False
5073

5174
# wait until processing is done
@@ -64,21 +87,28 @@ def checkQueue(self):
6487
else:
6588
gotOne = True
6689

67-
if len(addressGeneratorReturnValue) == 0:
90+
if not addressGeneratorReturnValue:
6891
self.setError(_translate("AddressValidator", "Address already present as one of your identities."))
6992
return (QtGui.QValidator.Intermediate, 0)
93+
7094
if addressGeneratorReturnValue[0] == 'chan name does not match address':
71-
self.setError(_translate("AddressValidator", "Although the Bitmessage address you entered was valid, it doesn\'t match the chan name."))
95+
self.setError(
96+
_translate(
97+
"AddressValidator",
98+
"Although the Bitmessage address you entered was valid, it doesn\'t match the chan name."))
7299
return (QtGui.QValidator.Intermediate, 0)
100+
73101
self.setOK(_translate("MainWindow", "Passphrase and address appear to be valid."))
74102

75103
def returnValid(self):
104+
""""""
76105
if self.isValid:
77106
return QtGui.QValidator.Acceptable
78-
else:
79-
return QtGui.QValidator.Intermediate
107+
return QtGui.QValidator.Intermediate
80108

81109
def validate(self, s, pos):
110+
""""""
111+
# pylint: disable=unused-argument
82112
if self.addressObject is None:
83113
address = None
84114
else:
@@ -105,9 +135,13 @@ def validate(self, s, pos):
105135

106136
# version too high
107137
if decodeAddress(address)[0] == 'versiontoohigh':
108-
self.setError(_translate("AddressValidator", "Address too new. Although that Bitmessage address might be valid, its version number is too new for us to handle. Perhaps you need to upgrade Bitmessage."))
138+
self.setError(
139+
_translate(
140+
"AddressValidator",
141+
"Address too new. Although that Bitmessage address might be valid, its version number is"
142+
" too new for us to handle. Perhaps you need to upgrade Bitmessage."))
109143
return (QtGui.QValidator.Intermediate, pos)
110-
144+
111145
# invalid
112146
if decodeAddress(address)[0] != 'success':
113147
self.setError(_translate("AddressValidator", "The Bitmessage address is not valid."))
@@ -122,23 +156,29 @@ def validate(self, s, pos):
122156
if address is None:
123157
addressGeneratorQueue.put(('createChan', 4, 1, str_chan + ' ' + str(passPhrase), passPhrase, False))
124158
else:
125-
addressGeneratorQueue.put(('joinChan', addBMIfNotPresent(address), str_chan + ' ' + str(passPhrase), passPhrase, False))
159+
addressGeneratorQueue.put(
160+
('joinChan', addBMIfNotPresent(address),
161+
str_chan + ' ' + str(passPhrase),
162+
passPhrase, False))
126163

127164
if self.buttonBox.button(QtGui.QDialogButtonBox.Ok).hasFocus():
128165
return (self.returnValid(), pos)
129-
else:
130-
return (QtGui.QValidator.Intermediate, pos)
166+
return (QtGui.QValidator.Intermediate, pos)
131167

132168
def checkData(self):
169+
""""""
133170
return self.validate("", 0)
134171

172+
135173
class AddressValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
174+
""""""
136175
def __init__(self, parent=None, passPhraseObject=None, feedBackObject=None, buttonBox=None, addressMandatory=True):
137176
super(AddressValidator, self).__init__(parent)
138177
self.setParams(passPhraseObject, parent, feedBackObject, buttonBox, addressMandatory)
139178

140179

141180
class PassPhraseValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
181+
""""""
142182
def __init__(self, parent=None, addressObject=None, feedBackObject=None, buttonBox=None, addressMandatory=False):
143183
super(PassPhraseValidator, self).__init__(parent)
144184
self.setParams(parent, addressObject, feedBackObject, buttonBox, addressMandatory)

src/bitmessageqt/blacklist.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1+
"""
2+
src/bitmessageqt/blacklist.py
3+
=============================
4+
"""
5+
16
from PyQt4 import QtCore, QtGui
2-
from tr import _translate
3-
import l10n
7+
48
import widgets
59
from addresses import addBMIfNotPresent
610
from bmconfigparser import BMConfigParser
711
from dialogs import AddAddressDialog
812
from helper_sql import sqlExecute, sqlQuery
913
from retranslateui import RetranslateMixin
10-
from utils import avatarize
14+
from tr import _translate
1115
from uisignaler import UISignaler
16+
from utils import avatarize
1217

1318

1419
class Blacklist(QtGui.QWidget, RetranslateMixin):
20+
""""""
21+
# pylint: disable=too-many-instance-attributes
1522
def __init__(self, parent=None):
23+
# pylint: disable=no-member
1624
super(Blacklist, self).__init__(parent)
1725
widgets.load('blacklist.ui', self)
1826

@@ -21,7 +29,7 @@ def __init__(self, parent=None):
2129
QtCore.QObject.connect(self.radioButtonWhitelist, QtCore.SIGNAL(
2230
"clicked()"), self.click_radioButtonWhitelist)
2331
QtCore.QObject.connect(self.pushButtonAddBlacklist, QtCore.SIGNAL(
24-
"clicked()"), self.click_pushButtonAddBlacklist)
32+
"clicked()"), self.click_pushButtonAddBlacklist)
2533

2634
self.init_blacklist_popup_menu()
2735

@@ -30,14 +38,15 @@ def __init__(self, parent=None):
3038
"itemChanged(QTableWidgetItem *)"), self.tableWidgetBlacklistItemChanged)
3139

3240
# Set the icon sizes for the identicons
33-
identicon_size = 3*7
41+
identicon_size = 3 * 7
3442
self.tableWidgetBlacklist.setIconSize(QtCore.QSize(identicon_size, identicon_size))
3543

3644
self.UISignalThread = UISignaler.get()
3745
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
3846
"rerenderBlackWhiteList()"), self.rerenderBlackWhiteList)
3947

4048
def click_radioButtonBlacklist(self):
49+
""""""
4150
if BMConfigParser().get('bitmessagesettings', 'blackwhitelist') == 'white':
4251
BMConfigParser().set('bitmessagesettings', 'blackwhitelist', 'black')
4352
BMConfigParser().save()
@@ -46,6 +55,7 @@ def click_radioButtonBlacklist(self):
4655
self.rerenderBlackWhiteList()
4756

4857
def click_radioButtonWhitelist(self):
58+
""""""
4959
if BMConfigParser().get('bitmessagesettings', 'blackwhitelist') == 'black':
5060
BMConfigParser().set('bitmessagesettings', 'blackwhitelist', 'white')
5161
BMConfigParser().save()
@@ -54,7 +64,8 @@ def click_radioButtonWhitelist(self):
5464
self.rerenderBlackWhiteList()
5565

5666
def click_pushButtonAddBlacklist(self):
57-
self.NewBlacklistDialogInstance = AddAddressDialog(self)
67+
""""""
68+
self.NewBlacklistDialogInstance = AddAddressDialog(self) # pylint: disable=attribute-defined-outside-init
5869
if self.NewBlacklistDialogInstance.exec_():
5970
if self.NewBlacklistDialogInstance.labelAddressCheck.text() == \
6071
_translate("MainWindow", "Address is valid."):
@@ -68,7 +79,7 @@ def click_pushButtonAddBlacklist(self):
6879
sql = '''select * from blacklist where address=?'''
6980
else:
7081
sql = '''select * from whitelist where address=?'''
71-
queryreturn = sqlQuery(sql,*t)
82+
queryreturn = sqlQuery(sql, *t)
7283
if queryreturn == []:
7384
self.tableWidgetBlacklist.setSortingEnabled(False)
7485
self.tableWidgetBlacklist.insertRow(0)
@@ -88,24 +99,29 @@ def click_pushButtonAddBlacklist(self):
8899
sql = '''INSERT INTO whitelist VALUES (?,?,?)'''
89100
sqlExecute(sql, *t)
90101
else:
91-
self.statusBar().showMessage(_translate(
92-
"MainWindow", "Error: You cannot add the same address to your list twice. Perhaps rename the existing one if you want."))
102+
self.statusBar().showMessage(
103+
_translate(
104+
"MainWindow",
105+
"Error: You cannot add the same address to your list twice."
106+
" Perhaps rename the existing one if you want."))
93107
else:
94108
self.statusBar().showMessage(_translate(
95109
"MainWindow", "The address you entered was invalid. Ignoring it."))
96110

97111
def tableWidgetBlacklistItemChanged(self, item):
112+
""""""
98113
if item.column() == 0:
99114
addressitem = self.tableWidgetBlacklist.item(item.row(), 1)
100115
if isinstance(addressitem, QtGui.QTableWidgetItem):
101116
if self.radioButtonBlacklist.isChecked():
102117
sqlExecute('''UPDATE blacklist SET label=? WHERE address=?''',
103-
str(item.text()), str(addressitem.text()))
118+
str(item.text()), str(addressitem.text()))
104119
else:
105120
sqlExecute('''UPDATE whitelist SET label=? WHERE address=?''',
106-
str(item.text()), str(addressitem.text()))
121+
str(item.text()), str(addressitem.text()))
107122

108123
def init_blacklist_popup_menu(self, connectSignal=True):
124+
""""""
109125
# Popup menu for the Blacklist page
110126
self.blacklistContextMenuToolbar = QtGui.QToolBar()
111127
# Actions
@@ -132,9 +148,10 @@ def init_blacklist_popup_menu(self, connectSignal=True):
132148
self.tableWidgetBlacklist.setContextMenuPolicy(
133149
QtCore.Qt.CustomContextMenu)
134150
if connectSignal:
135-
self.connect(self.tableWidgetBlacklist, QtCore.SIGNAL(
136-
'customContextMenuRequested(const QPoint&)'),
137-
self.on_context_menuBlacklist)
151+
self.connect(
152+
self.tableWidgetBlacklist,
153+
QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'),
154+
self.on_context_menuBlacklist)
138155
self.popMenuBlacklist = QtGui.QMenu(self)
139156
# self.popMenuBlacklist.addAction( self.actionBlacklistNew )
140157
self.popMenuBlacklist.addAction(self.actionBlacklistDelete)
@@ -146,6 +163,7 @@ def init_blacklist_popup_menu(self, connectSignal=True):
146163
self.popMenuBlacklist.addAction(self.actionBlacklistSetAvatar)
147164

148165
def rerenderBlackWhiteList(self):
166+
""""""
149167
tabs = self.parent().parent()
150168
if BMConfigParser().get('bitmessagesettings', 'blackwhitelist') == 'black':
151169
tabs.setTabText(tabs.indexOf(self), _translate('blacklist', 'Blacklist'))
@@ -176,9 +194,11 @@ def rerenderBlackWhiteList(self):
176194

177195
# Group of functions for the Blacklist dialog box
178196
def on_action_BlacklistNew(self):
197+
""""""
179198
self.click_pushButtonAddBlacklist()
180199

181200
def on_action_BlacklistDelete(self):
201+
""""""
182202
currentRow = self.tableWidgetBlacklist.currentRow()
183203
labelAtCurrentRow = self.tableWidgetBlacklist.item(
184204
currentRow, 0).text().toUtf8()
@@ -195,17 +215,20 @@ def on_action_BlacklistDelete(self):
195215
self.tableWidgetBlacklist.removeRow(currentRow)
196216

197217
def on_action_BlacklistClipboard(self):
218+
""""""
198219
currentRow = self.tableWidgetBlacklist.currentRow()
199220
addressAtCurrentRow = self.tableWidgetBlacklist.item(
200221
currentRow, 1).text()
201222
clipboard = QtGui.QApplication.clipboard()
202223
clipboard.setText(str(addressAtCurrentRow))
203224

204225
def on_context_menuBlacklist(self, point):
226+
""""""
205227
self.popMenuBlacklist.exec_(
206228
self.tableWidgetBlacklist.mapToGlobal(point))
207229

208230
def on_action_BlacklistEnable(self):
231+
""""""
209232
currentRow = self.tableWidgetBlacklist.currentRow()
210233
addressAtCurrentRow = self.tableWidgetBlacklist.item(
211234
currentRow, 1).text()
@@ -223,6 +246,7 @@ def on_action_BlacklistEnable(self):
223246
str(addressAtCurrentRow))
224247

225248
def on_action_BlacklistDisable(self):
249+
""""""
226250
currentRow = self.tableWidgetBlacklist.currentRow()
227251
addressAtCurrentRow = self.tableWidgetBlacklist.item(
228252
currentRow, 1).text()
@@ -238,5 +262,5 @@ def on_action_BlacklistDisable(self):
238262
'''UPDATE whitelist SET enabled=0 WHERE address=?''', str(addressAtCurrentRow))
239263

240264
def on_action_BlacklistSetAvatar(self):
265+
""""""
241266
self.window().on_action_SetAvatar(self.tableWidgetBlacklist)
242-

0 commit comments

Comments
 (0)