Skip to content

Commit 8a7c78b

Browse files
committed
Code quality
1 parent d8365be commit 8a7c78b

6 files changed

Lines changed: 70 additions & 64 deletions

File tree

src/bitmessagemain.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
# Right now, PyBitmessage only support connecting to stream 1. It doesn't
1111
# yet contain logic to expand into further streams.
12+
13+
# flake8: noqa:402
1214
import os
1315
import sys
1416

src/bitmessageqt/__init__.py

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def init_file_menu(self):
176176
QtCore.QObject.connect(
177177
self.ui.pushButtonAddChan,
178178
QtCore.SIGNAL("clicked()"),
179-
self.click_actionJoinChan) # also used for creating chans.
179+
self.click_actionJoinChan) # also used for creating chans.
180180
QtCore.QObject.connect(self.ui.pushButtonNewAddress, QtCore.SIGNAL(
181181
"clicked()"), self.click_NewAddressDialog)
182182
QtCore.QObject.connect(self.ui.pushButtonAddAddressBook, QtCore.SIGNAL(
@@ -1760,7 +1760,8 @@ def changeEvent(self, event):
17601760
self.ui.blackwhitelist.init_blacklist_popup_menu(False)
17611761
if event.type() == QtCore.QEvent.WindowStateChange:
17621762
if self.windowState() & QtCore.Qt.WindowMinimized:
1763-
if config.getboolean('bitmessagesettings', 'minimizetotray') and not 'darwin' in sys.platform:
1763+
if (config.getboolean('bitmessagesettings', 'minimizetotray')
1764+
and 'darwin' not in sys.platform):
17641765
QtCore.QTimer.singleShot(0, self.appIndicatorHide)
17651766
elif event.oldState() & QtCore.Qt.WindowMinimized:
17661767
# The window state has just been changed to
@@ -1873,7 +1874,7 @@ def calcTrayIcon(self, iconFileName, inboxUnreadCount):
18731874
painter.setPen(
18741875
QtGui.QPen(QtGui.QColor(255, 0, 0), QtCore.Qt.SolidPattern))
18751876
painter.setFont(font)
1876-
painter.drawText(24-rect.right()-marginX, -rect.top()+marginY, txt)
1877+
painter.drawText(24 - rect.right() - marginX, -rect.top() + marginY, txt)
18771878
painter.end()
18781879
return QtGui.QIcon(pixmap)
18791880

@@ -1950,7 +1951,7 @@ def updateSentItemStatusByAckdata(self, ackdata, textToDisplay):
19501951
try:
19511952
newlinePosition = textToDisplay.indexOf('\n')
19521953
except:
1953-
# If someone misses adding a "_translate" to a string before passing it to this function,
1954+
# If someone misses adding a "_translate" to a string before passing it to this function,
19541955
# this function won't receive a qstring which will cause an exception.
19551956
newlinePosition = 0
19561957
if newlinePosition > 1:
@@ -1987,8 +1988,7 @@ def newVersionAvailable(self, version):
19871988
"MainWindow",
19881989
"New version of PyBitmessage is available: %1. Download it"
19891990
" from https://github.com/Bitmessage/PyBitmessage/releases/latest"
1990-
).arg(self.notifiedNewVersion)
1991-
)
1991+
).arg(self.notifiedNewVersion))
19921992

19931993
def displayAlert(self, title, text, exitAfterUserClicksOk):
19941994
self.updateStatusBar(text)
@@ -2011,7 +2011,7 @@ def rerenderMessagelistToLabels(self):
20112011
messagelist.item(i, 0).setLabel()
20122012

20132013
def rerenderAddressBook(self):
2014-
def addRow (address, label, type):
2014+
def addRow(address, label, type):
20152015
self.ui.tableWidgetAddressBook.insertRow(0)
20162016
newItem = Ui_AddressBookWidgetItemLabel(address, text_type(label, 'utf-8'), type)
20172017
self.ui.tableWidgetAddressBook.setItem(0, 0, newItem)
@@ -2157,14 +2157,16 @@ def click_pushButtonSend(self):
21572157
"MainWindow",
21582158
"You are trying to send an email instead of a bitmessage. "
21592159
"This requires registering with a gateway. Attempt to register?"),
2160-
QtGui.QMessageBox.Yes|QtGui.QMessageBox.No) != QtGui.QMessageBox.Yes:
2160+
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) != QtGui.QMessageBox.Yes:
21612161
continue
21622162
email = acct.getLabel()
2163-
if email[-14:] != "@mailchuck.com": # attempt register
2163+
if email[-14:] != "@mailchuck.com": # attempt register
21642164
# 12 character random email address
21652165
email = ''.join(
2166-
random.SystemRandom().choice(string.ascii_lowercase) for _ in range(12)
2167-
) + "@mailchuck.com"
2166+
random.SystemRandom().
2167+
choice(string.ascii_lowercase)
2168+
for _ in range(12)
2169+
) + "@mailchuck.com"
21682170
acct = MailchuckAccount(fromAddress)
21692171
acct.register(email)
21702172
config.set(fromAddress, 'label', email)
@@ -2176,8 +2178,7 @@ def click_pushButtonSend(self):
21762178
" an email gateway. Sending registration"
21772179
" now as %1, please wait for the registration"
21782180
" to be processed before retrying sending."
2179-
).arg(email)
2180-
)
2181+
).arg(email))
21812182
return
21822183
status, addressVersionNumber, streamNumber = decodeAddress(toAddress)[:3]
21832184
if status != 'success':
@@ -2192,57 +2193,57 @@ def click_pushButtonSend(self):
21922193
"MainWindow",
21932194
"Error: Bitmessage addresses start with"
21942195
" BM- Please check the recipient address %1"
2195-
).arg(toAddress))
2196+
).arg(toAddress))
21962197
elif status == 'checksumfailed':
21972198
self.updateStatusBar(_translate(
21982199
"MainWindow",
21992200
"Error: The recipient address %1 is not"
22002201
" typed or copied correctly. Please check it."
2201-
).arg(toAddress))
2202+
).arg(toAddress))
22022203
elif status == 'invalidcharacters':
22032204
self.updateStatusBar(_translate(
22042205
"MainWindow",
22052206
"Error: The recipient address %1 contains"
22062207
" invalid characters. Please check it."
2207-
).arg(toAddress))
2208+
).arg(toAddress))
22082209
elif status == 'versiontoohigh':
22092210
self.updateStatusBar(_translate(
22102211
"MainWindow",
22112212
"Error: The version of the recipient address"
22122213
" %1 is too high. Either you need to upgrade"
22132214
" your Bitmessage software or your"
22142215
" acquaintance is being clever."
2215-
).arg(toAddress))
2216+
).arg(toAddress))
22162217
elif status == 'ripetooshort':
22172218
self.updateStatusBar(_translate(
22182219
"MainWindow",
22192220
"Error: Some data encoded in the recipient"
22202221
" address %1 is too short. There might be"
22212222
" something wrong with the software of"
22222223
" your acquaintance."
2223-
).arg(toAddress))
2224+
).arg(toAddress))
22242225
elif status == 'ripetoolong':
22252226
self.updateStatusBar(_translate(
22262227
"MainWindow",
22272228
"Error: Some data encoded in the recipient"
22282229
" address %1 is too long. There might be"
22292230
" something wrong with the software of"
22302231
" your acquaintance."
2231-
).arg(toAddress))
2232+
).arg(toAddress))
22322233
elif status == 'varintmalformed':
22332234
self.updateStatusBar(_translate(
22342235
"MainWindow",
22352236
"Error: Some data encoded in the recipient"
22362237
" address %1 is malformed. There might be"
22372238
" something wrong with the software of"
22382239
" your acquaintance."
2239-
).arg(toAddress))
2240+
).arg(toAddress))
22402241
else:
22412242
self.updateStatusBar(_translate(
22422243
"MainWindow",
22432244
"Error: Something is wrong with the"
22442245
" recipient address %1."
2245-
).arg(toAddress))
2246+
).arg(toAddress))
22462247
elif fromAddress == '':
22472248
self.updateStatusBar(_translate(
22482249
"MainWindow",
@@ -2750,14 +2751,14 @@ def quit(self):
27502751
_translate(
27512752
"MainWindow",
27522753
"%n object(s) pending proof of work", None,
2753-
QtCore.QCoreApplication.CodecForTr, powQueueSize()
2754-
) + ", " +
2755-
_translate(
2754+
QtCore.QCoreApplication.CodecForTr, powQueueSize())
2755+
+ ", "
2756+
+ _translate(
27562757
"MainWindow",
27572758
"%n object(s) waiting to be distributed", None,
2758-
QtCore.QCoreApplication.CodecForTr, pendingUpload()
2759-
) + "\n\n" +
2760-
_translate(
2759+
QtCore.QCoreApplication.CodecForTr, pendingUpload())
2760+
+ "\n\n"
2761+
+ _translate(
27612762
"MainWindow", "Wait until these tasks finish?"),
27622763
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
27632764
| QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel)
@@ -2840,8 +2841,8 @@ def quit(self):
28402841
if curWorkerQueue > 0:
28412842
self.updateStatusBar(_translate(
28422843
"MainWindow", "Waiting for PoW to finish... %1%"
2843-
).arg(50 * (maxWorkerQueue - curWorkerQueue) /
2844-
maxWorkerQueue))
2844+
).arg(50 * (maxWorkerQueue - curWorkerQueue)
2845+
/ maxWorkerQueue))
28452846
time.sleep(0.5)
28462847
QtCore.QCoreApplication.processEvents(
28472848
QtCore.QEventLoop.AllEvents, 1000
@@ -2947,10 +2948,10 @@ def on_action_InboxMessageForceHtml(self):
29472948
lines[i])
29482949
elif lines[i] == '------------------------------------------------------':
29492950
lines[i] = '<hr>'
2950-
elif lines[i] == '' and (i+1) < totalLines and \
2951-
lines[i+1] != '------------------------------------------------------':
2951+
elif lines[i] == '' and (i + 1) < totalLines and \
2952+
lines[i + 1] != '------------------------------------------------------':
29522953
lines[i] = '<br><br>'
2953-
content = ' '.join(lines) # To keep the whitespace between lines
2954+
content = ' '.join(lines) # To keep the whitespace between lines
29542955
content = shared.fixPotentiallyInvalidUTF8Data(content)
29552956
content = text_type(content, 'utf-8)')
29562957
textEdit.setHtml(QtCore.QString(content))
@@ -3007,7 +3008,8 @@ def quote_line(line):
30073008
# Wrap and quote lines/paragraphs new to this message.
30083009
else:
30093010
return quoteWrapper.fill(line)
3010-
return '\n'.join([quote_line(l) for l in message.splitlines()]) + '\n\n'
3011+
return '\n'.join([quote_line(line)
3012+
for line in message.splitlines()]) + '\n\n'
30113013

30123014
def setSendFromComboBox(self, address=None):
30133015
if address is None:
@@ -3109,8 +3111,8 @@ def on_action_InboxReply(self, reply_type=None):
31093111
toAddressAtCurrentInboxRow = fromAddressAtCurrentInboxRow
31103112
if fromAddressAtCurrentInboxRow == \
31113113
tableWidget.item(currentInboxRow, column_from).label or (
3112-
isinstance(acct, GatewayAccount) and
3113-
fromAddressAtCurrentInboxRow == acct.relayAddress):
3114+
isinstance(acct, GatewayAccount)
3115+
and fromAddressAtCurrentInboxRow == acct.relayAddress):
31143116
self.ui.lineEditTo.setText(str(acct.fromAddress))
31153117
else:
31163118
self.ui.lineEditTo.setText(
@@ -3239,8 +3241,8 @@ def on_action_InboxTrash(self):
32393241
idCount = len(inventoryHashesToTrash)
32403242
sqlExecuteChunked(
32413243
("DELETE FROM inbox" if folder == "trash" or shifted else
3242-
"UPDATE inbox SET folder='trash', read=1") +
3243-
" WHERE msgid IN ({0})", idCount, *inventoryHashesToTrash)
3244+
"UPDATE inbox SET folder='trash', read=1")
3245+
+ " WHERE msgid IN ({0})", idCount, *inventoryHashesToTrash)
32443246
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
32453247
tableWidget.setUpdatesEnabled(True)
32463248
self.propagateUnreadCount(folder)
@@ -3296,7 +3298,7 @@ def on_action_InboxSaveMessageAs(self):
32963298
defaultFilename = "".join(x for x in subjectAtCurrentInboxRow if x.isalnum()) + '.txt'
32973299
filename = QtGui.QFileDialog.getSaveFileName(
32983300
self,
3299-
_translate("MainWindow","Save As..."),
3301+
_translate("MainWindow", "Save As..."),
33003302
defaultFilename,
33013303
"Text files (*.txt);;All files (*.*)")
33023304
if filename == '':
@@ -3755,8 +3757,8 @@ def on_action_ClipboardMessagelist(self):
37553757
otherAddress = tableWidget.item(currentRow, 1).data(QtCore.Qt.UserRole)
37563758
account = accountClass(myAddress)
37573759
if isinstance(account, GatewayAccount) and otherAddress == account.relayAddress and (
3758-
(currentColumn in [0, 2] and self.getCurrentFolder() == "sent") or
3759-
(currentColumn in [1, 2] and self.getCurrentFolder() != "sent")):
3760+
(currentColumn in [0, 2] and self.getCurrentFolder() == "sent")
3761+
or (currentColumn in [1, 2] and self.getCurrentFolder() != "sent")):
37603762
text = str(tableWidget.item(currentRow, currentColumn).label)
37613763
else:
37623764
text = tableWidget.item(currentRow, currentColumn).data(QtCore.Qt.UserRole)

src/bitmessageqt/migrationwizard.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#!/usr/bin/env python2.7
2-
from PyQt4 import QtCore, QtGui
2+
from PyQt4 import QtGui
3+
34

45
class MigrationWizardIntroPage(QtGui.QWizardPage):
56
def __init__(self):
67
super(QtGui.QWizardPage, self).__init__()
78
self.setTitle("Migrating configuration")
89

910
label = QtGui.QLabel("This wizard will help you to migrate your configuration. "
10-
"You can still keep using PyBitMessage once you migrate, the changes are backwards compatible.")
11+
"You can still keep using PyBitmessage once you migrate, "
12+
"the changes are backwards compatible.")
1113
label.setWordWrap(True)
1214

1315
layout = QtGui.QVBoxLayout()
1416
layout.addWidget(label)
1517
self.setLayout(layout)
16-
18+
1719
def nextId(self):
1820
return 1
19-
21+
2022

2123
class MigrationWizardAddressesPage(QtGui.QWizardPage):
2224
def __init__(self, addresses):
@@ -29,10 +31,10 @@ def __init__(self, addresses):
2931
layout = QtGui.QVBoxLayout()
3032
layout.addWidget(label)
3133
self.setLayout(layout)
32-
34+
3335
def nextId(self):
3436
return 10
35-
37+
3638

3739
class MigrationWizardGPUPage(QtGui.QWizardPage):
3840
def __init__(self):
@@ -45,10 +47,10 @@ def __init__(self):
4547
layout = QtGui.QVBoxLayout()
4648
layout.addWidget(label)
4749
self.setLayout(layout)
48-
50+
4951
def nextId(self):
5052
return 10
51-
53+
5254

5355
class MigrationWizardConclusionPage(QtGui.QWizardPage):
5456
def __init__(self):
@@ -68,7 +70,7 @@ def __init__(self, addresses):
6870
super(QtGui.QWizard, self).__init__()
6971

7072
self.pages = {}
71-
73+
7274
page = MigrationWizardIntroPage()
7375
self.setPage(0, page)
7476
self.setStartId(0)
@@ -81,4 +83,4 @@ def __init__(self, addresses):
8183

8284
self.setWindowTitle("Migration from PyBitMessage wizard")
8385
self.adjustSize()
84-
self.show()
86+
self.show()

src/bitmessageqt/retranslateui.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from os import path
21
from PyQt4 import QtGui
3-
from debug import logger
42
import widgets
53

4+
65
class RetranslateMixin(object):
76
def retranslateUi(self):
87
defaults = QtGui.QWidget()
@@ -12,9 +11,9 @@ def retranslateUi(self):
1211
if callable(setTextMethod):
1312
getattr(self, attr).setText(getattr(defaults, attr).text())
1413
elif isinstance(value, QtGui.QTableWidget):
15-
for i in range (value.columnCount()):
14+
for i in range(value.columnCount()):
1615
getattr(self, attr).horizontalHeaderItem(i).setText(
1716
getattr(defaults, attr).horizontalHeaderItem(i).text())
18-
for i in range (value.rowCount()):
17+
for i in range(value.rowCount()):
1918
getattr(self, attr).verticalHeaderItem(i).setText(
2019
getattr(defaults, attr).verticalHeaderItem(i).text())

src/class_singleCleaner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ def resendPubkeyRequest(self, address):
160160
pass
161161
except RuntimeError:
162162
self.logger.warning(
163-
"Can't remove %s from neededPubkeys, requesting pubkey will be delayed", address, exc_info=True)
163+
"Can't remove %s from neededPubkeys, requesting pubkey will be delayed",
164+
address, exc_info=True)
164165

165166
queues.UISignalQueue.put((
166167
'updateStatusBar',

src/fallback/umsgpack/umsgpack.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ def __eq__(self, other):
110110
"""
111111
Compare this Ext object with another for equality.
112112
"""
113-
return (isinstance(other, self.__class__) and
114-
self.type == other.type and
115-
self.data == other.data)
113+
return (isinstance(other, self.__class__)
114+
and self.type == other.type
115+
and self.data == other.data)
116116

117117
def __ne__(self, other):
118118
"""
@@ -337,14 +337,14 @@ def _pack_ext(obj, fp, options):
337337
elif len(obj.data) == 16:
338338
fp.write(b"\xd8" + struct.pack("B", obj.type & 0xff) + obj.data)
339339
elif len(obj.data) <= 2**8 - 1:
340-
fp.write(b"\xc7" +
341-
struct.pack("BB", len(obj.data), obj.type & 0xff) + obj.data)
340+
fp.write(b"\xc7"
341+
+ struct.pack("BB", len(obj.data), obj.type & 0xff) + obj.data)
342342
elif len(obj.data) <= 2**16 - 1:
343-
fp.write(b"\xc8" +
344-
struct.pack(">HB", len(obj.data), obj.type & 0xff) + obj.data)
343+
fp.write(b"\xc8"
344+
+ struct.pack(">HB", len(obj.data), obj.type & 0xff) + obj.data)
345345
elif len(obj.data) <= 2**32 - 1:
346-
fp.write(b"\xc9" +
347-
struct.pack(">IB", len(obj.data), obj.type & 0xff) + obj.data)
346+
fp.write(b"\xc9"
347+
+ struct.pack(">IB", len(obj.data), obj.type & 0xff) + obj.data)
348348
else:
349349
raise UnsupportedTypeException("huge ext data")
350350

0 commit comments

Comments
 (0)