Skip to content

Commit add4e79

Browse files
committed
Code quality
1 parent 9d998a9 commit add4e79

11 files changed

Lines changed: 69 additions & 64 deletions

src/api.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
For further examples please reference `.tests.test_api`.
5858
"""
5959

60+
# pylint: disable=too-many-lines,relative-import
61+
6062
import base64
6163
import errno
6264
import hashlib
@@ -112,48 +114,48 @@ class ErrorCodes(type):
112114
0: 'Invalid command parameters number',
113115
1: 'The specified passphrase is blank.',
114116
2: 'The address version number currently must be 3, 4, or 0'
115-
' (which means auto-select).',
117+
' (which means auto-select).',
116118
3: 'The stream number must be 1 (or 0 which means'
117-
' auto-select). Others aren\'t supported.',
119+
' auto-select). Others aren\'t supported.',
118120
4: 'Why would you ask me to generate 0 addresses for you?',
119121
5: 'You have (accidentally?) specified too many addresses to'
120-
' make. Maximum 999. This check only exists to prevent'
121-
' mischief; if you really want to create more addresses than'
122-
' this, contact the Bitmessage developers and we can modify'
123-
' the check or you can do it yourself by searching the source'
124-
' code for this message.',
122+
' make. Maximum 999. This check only exists to prevent'
123+
' mischief; if you really want to create more addresses than'
124+
' this, contact the Bitmessage developers and we can modify'
125+
' the check or you can do it yourself by searching the source'
126+
' code for this message.',
125127
6: 'The encoding type must be 2 or 3.',
126128
7: 'Could not decode address',
127129
8: 'Checksum failed for address',
128130
9: 'Invalid characters in address',
129131
10: 'Address version number too high (or zero)',
130132
11: 'The address version number currently must be 2, 3 or 4.'
131-
' Others aren\'t supported. Check the address.',
133+
' Others aren\'t supported. Check the address.',
132134
12: 'The stream number must be 1. Others aren\'t supported.'
133-
' Check the address.',
135+
' Check the address.',
134136
13: 'Could not find this address in your keys.dat file.',
135137
14: 'Your fromAddress is disabled. Cannot send.',
136138
15: 'Invalid ackData object size.',
137139
16: 'You are already subscribed to that address.',
138140
17: 'Label is not valid UTF-8 data.',
139141
18: 'Chan name does not match address.',
140142
19: 'The length of hash should be 32 bytes (encoded in hex'
141-
' thus 64 characters).',
143+
' thus 64 characters).',
142144
20: 'Invalid method:',
143145
21: 'Unexpected API Failure',
144146
22: 'Decode error',
145147
23: 'Bool expected in eighteenByteRipe',
146148
24: 'Chan address is already present.',
147149
25: 'Specified address is not a chan address.'
148-
' Use deleteAddress API call instead.',
150+
' Use deleteAddress API call instead.',
149151
26: 'Malformed varint in address: ',
150152
27: 'Message is too long.',
151153
28: 'Invalid parameter'
152154
}
153155

154156
def __new__(mcs, name, bases, namespace):
155157
result = super(ErrorCodes, mcs).__new__(mcs, name, bases, namespace)
156-
for code in six.iteritems(mcs._CODES):
158+
for code in six.iteritems(mcs._CODES): # pylint: disable=no-member
157159
# beware: the formatting is adjusted for list-table
158160
result.__doc__ += """ * - %04i
159161
- %s
@@ -466,6 +468,7 @@ def APIAuthenticateClient(self):
466468
class BMRPCDispatcher(object):
467469
"""This class is used to dispatch API commands"""
468470

471+
# pylint: disable=inconsistent-return-statements
469472
@staticmethod
470473
def _decode(text, decode_type):
471474
try:
@@ -722,8 +725,8 @@ def HandleDeleteWhitelistEntry(self, address):
722725

723726
@command('createRandomAddress')
724727
def HandleCreateRandomAddress(
725-
self, label, eighteenByteRipe=False, totalDifficulty=0,
726-
smallMessageDifficulty=0
728+
self, label, eighteenByteRipe=False, totalDifficulty=0,
729+
smallMessageDifficulty=0
727730
):
728731
"""
729732
Create one address using the random number generator.
@@ -763,9 +766,9 @@ def HandleCreateRandomAddress(
763766

764767
@command('createDeterministicAddresses')
765768
def HandleCreateDeterministicAddresses(
766-
self, passphrase, numberOfAddresses=1, addressVersionNumber=0,
767-
streamNumber=0, eighteenByteRipe=False, totalDifficulty=0,
768-
smallMessageDifficulty=0
769+
self, passphrase, numberOfAddresses=1, addressVersionNumber=0,
770+
streamNumber=0, eighteenByteRipe=False, totalDifficulty=0,
771+
smallMessageDifficulty=0
769772
):
770773
"""
771774
Create many addresses deterministically using the passphrase.
@@ -1190,8 +1193,8 @@ def HandleTrashSentMessage(self, msgid):
11901193

11911194
@command('sendMessage')
11921195
def HandleSendMessage(
1193-
self, toAddress, fromAddress, subject, message,
1194-
encodingType=2, TTL=4 * 24 * 60 * 60
1196+
self, toAddress, fromAddress, subject, message,
1197+
encodingType=2, TTL=4 * 24 * 60 * 60
11951198
):
11961199
"""
11971200
Send the message and return ackdata (hex encoded string).
@@ -1242,7 +1245,7 @@ def HandleSendMessage(
12421245

12431246
@command('sendBroadcast')
12441247
def HandleSendBroadcast(
1245-
self, fromAddress, subject, message, encodingType=2,
1248+
self, fromAddress, subject, message, encodingType=2,
12461249
TTL=4 * 24 * 60 * 60):
12471250
"""Send the broadcast message. Similiar to *sendMessage*."""
12481251

@@ -1361,9 +1364,9 @@ def ListSubscriptions(self):
13611364

13621365
@command('disseminatePreEncryptedMsg', 'disseminatePreparedObject')
13631366
def HandleDisseminatePreparedObject(
1364-
self, encryptedPayload,
1365-
nonceTrialsPerByte=networkDefaultProofOfWorkNonceTrialsPerByte,
1366-
payloadLengthExtraBytes=networkDefaultPayloadLengthExtraBytes
1367+
self, encryptedPayload,
1368+
nonceTrialsPerByte=networkDefaultProofOfWorkNonceTrialsPerByte,
1369+
payloadLengthExtraBytes=networkDefaultPayloadLengthExtraBytes
13671370
):
13681371
"""
13691372
Handle a request to disseminate an encrypted message.

src/bitmessagemain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# yet contain logic to expand into further streams.
1212

1313
# flake8: noqa:402
14+
# pylint: disable=superfluous-parens
1415
import os
1516
import sys
1617

src/bitmessageqt/settings.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ def adjust_from_config(self, config):
176176

177177
if self._proxy_type:
178178
for node, info in six.iteritems(
179-
knownnodes.knownNodes.get(
179+
knownnodes.knownNodes.get(
180180
min(connectionpool.pool.streams), [])
181181
):
182182
if (
183-
node.host.endswith('.onion') and len(node.host) > 22
184-
and not info.get('self')
183+
node.host.endswith('.onion') and len(node.host) > 22
184+
and not info.get('self')
185185
):
186186
break
187187
else:
@@ -374,7 +374,7 @@ def accept(self):
374374

375375
window_style = str(self.comboBoxStyle.currentText())
376376
if self.app.get_windowstyle() != window_style or self.config.safeGet(
377-
'bitmessagesettings', 'font'
377+
'bitmessagesettings', 'font'
378378
) != self.font_setting:
379379
self.config.set('bitmessagesettings', 'windowstyle', window_style)
380380
self.config.set('bitmessagesettings', 'font', self.font_setting)
@@ -455,8 +455,8 @@ def accept(self):
455455
self.config.set('bitmessagesettings', 'sockslisten', str(
456456
self.checkBoxSocksListen.isChecked()))
457457
if (
458-
self.checkBoxOnionOnly.isChecked()
459-
and not self.config.safeGetBoolean(
458+
self.checkBoxOnionOnly.isChecked()
459+
and not self.config.safeGetBoolean(
460460
'bitmessagesettings', 'onionservicesonly')
461461
):
462462
self.net_restart_needed = True
@@ -520,14 +520,14 @@ def accept(self):
520520
acceptableDifficultyChanged = False
521521

522522
if (
523-
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1
524-
or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
523+
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1
524+
or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
525525
):
526526
if self.config.get(
527527
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte'
528528
) != str(int(
529529
float(self.lineEditMaxAcceptableTotalDifficulty.text())
530-
* defaults.networkDefaultProofOfWorkNonceTrialsPerByte)):
530+
* defaults.networkDefaultProofOfWorkNonceTrialsPerByte)):
531531
# the user changed the max acceptable total difficulty
532532
acceptableDifficultyChanged = True
533533
self.config.set(
@@ -537,8 +537,8 @@ def accept(self):
537537
* defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
538538
)
539539
if (
540-
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1
541-
or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
540+
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1
541+
or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
542542
):
543543
if self.config.get(
544544
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
@@ -629,8 +629,8 @@ def accept(self):
629629
self.parent.updateStartOnLogon()
630630

631631
if (
632-
state.appdata != paths.lookupExeFolder()
633-
and self.checkBoxPortableMode.isChecked()
632+
state.appdata != paths.lookupExeFolder()
633+
and self.checkBoxPortableMode.isChecked()
634634
):
635635
# If we are NOT using portable mode now but the user selected
636636
# that we should...
@@ -652,8 +652,8 @@ def accept(self):
652652
pass
653653

654654
if (
655-
state.appdata == paths.lookupExeFolder()
656-
and not self.checkBoxPortableMode.isChecked()
655+
state.appdata == paths.lookupExeFolder()
656+
and not self.checkBoxPortableMode.isChecked()
657657
):
658658
# If we ARE using portable mode now but the user selected
659659
# that we shouldn't...

src/bmconfigparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def save(self):
128128
shutil.copyfile(fileName, fileNameBak)
129129
# The backup succeeded.
130130
fileNameExisted = True
131-
except(IOError, Exception):
131+
except (IOError, Exception):
132132
# The backup failed. This can happen if the file
133133
# didn't exist before.
134134
fileNameExisted = False

src/class_addressGenerator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def stopThread(self):
3232

3333
super(addressGenerator, self).stopThread()
3434

35+
# pylint: disable=too-many-arguments,too-many-positional-arguments
3536
def save_address(
36-
# pylint: disable=too-many-arguments,too-many-positional-arguments
37-
self, version, stream, ripe, label, signing_key, encryption_key,
38-
nonceTrialsPerByte, payloadLengthExtraBytes
37+
self, version, stream, ripe, label, signing_key, encryption_key,
38+
nonceTrialsPerByte, payloadLengthExtraBytes
3939
):
4040
"""Write essential address config values and reload cryptors"""
4141
address = encodeAddress(version, stream, ripe)
@@ -183,8 +183,8 @@ def run(self):
183183
ripe = highlevelcrypto.to_ripe(
184184
pubSigningKey, potentialPubEncryptionKey)
185185
if (
186-
ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash]
187-
== b'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
186+
ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash]
187+
== b'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
188188
):
189189
break
190190
self.logger.info(

src/class_singleWorker.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def _getKeysForAddress(self, address):
221221

222222
@classmethod
223223
def _doPOWDefaults(
224-
cls, payload, TTL,
225-
nonceTrialsPerByte=None, payloadLengthExtraBytes=None,
226-
log_prefix='', log_time=False
224+
cls, payload, TTL,
225+
nonceTrialsPerByte=None, payloadLengthExtraBytes=None,
226+
log_prefix='', log_time=False
227227
):
228228
if not nonceTrialsPerByte:
229229
nonceTrialsPerByte = \
@@ -755,9 +755,9 @@ def sendMsg(self):
755755
# in our keys.dat file.
756756
elif config.has_section(toaddress):
757757
if not sqlExecute(
758-
'''UPDATE sent SET status='doingmsgpow' '''
759-
''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''',
760-
toaddress
758+
'''UPDATE sent SET status='doingmsgpow' '''
759+
''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''',
760+
toaddress
761761
):
762762
continue
763763
status = 'doingmsgpow'

src/helper_search.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
def search_sql(
11-
xAddress='toaddress', account=None, folder='inbox', where=None,
12-
what=None, unreadOnly=False
11+
xAddress='toaddress', account=None, folder='inbox', where=None,
12+
what=None, unreadOnly=False
1313
):
1414
"""
1515
Search for messages from given account and folder having search term
@@ -88,24 +88,24 @@ def check_match(
8888
return True
8989

9090
if where in (
91-
_translate("MainWindow", "To"), _translate("MainWindow", "All")
91+
_translate("MainWindow", "To"), _translate("MainWindow", "All")
9292
):
9393
if what.lower() not in toAddress.lower():
9494
return False
9595
elif where in (
96-
_translate("MainWindow", "From"), _translate("MainWindow", "All")
96+
_translate("MainWindow", "From"), _translate("MainWindow", "All")
9797
):
9898
if what.lower() not in fromAddress.lower():
9999
return False
100100
elif where in (
101-
_translate("MainWindow", "Subject"),
102-
_translate("MainWindow", "All")
101+
_translate("MainWindow", "Subject"),
102+
_translate("MainWindow", "All")
103103
):
104104
if what.lower() not in subject.lower():
105105
return False
106106
elif where in (
107-
_translate("MainWindow", "Message"),
108-
_translate("MainWindow", "All")
107+
_translate("MainWindow", "Message"),
108+
_translate("MainWindow", "All")
109109
):
110110
if what.lower() not in message.lower():
111111
return False

src/main-android-live.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""This module is for thread start."""
2+
# pylint: disable=superfluous-parens
23
import state
34
import sys
45
from bitmessagemain import main

src/network/asyncore_pollchoose.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,12 @@ def del_channel(self):
560560
try:
561561
kqueue_poller.pollster.control([select.kevent(
562562
fd, select.KQ_FILTER_READ, select.KQ_EV_DELETE)], 0)
563-
except(AttributeError, KeyError, TypeError, IOError, OSError):
563+
except (AttributeError, KeyError, TypeError, IOError, OSError):
564564
pass
565565
try:
566566
kqueue_poller.pollster.control([select.kevent(
567567
fd, select.KQ_FILTER_WRITE, select.KQ_EV_DELETE)], 0)
568-
except(AttributeError, KeyError, TypeError, IOError, OSError):
568+
except (AttributeError, KeyError, TypeError, IOError, OSError):
569569
pass
570570
try:
571571
epoll_poller.pollster.unregister(fd)

src/qidenticon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ def decode(self, code, twoColor):
262262
else:
263263
secondColor = foreColor
264264

265-
return (middleType, middleInvert, 0),\
266-
(cornerType, cornerInvert, cornerTurn),\
267-
(sideType, sideInvert, sideTurn),\
265+
return (middleType, middleInvert, 0), \
266+
(cornerType, cornerInvert, cornerTurn), \
267+
(sideType, sideInvert, sideTurn), \
268268
foreColor, secondColor, swap_cross
269269

270270

0 commit comments

Comments
 (0)