Skip to content

Commit 011500e

Browse files
committed
Code quality
1 parent 9d998a9 commit 011500e

11 files changed

Lines changed: 91 additions & 86 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: 37 additions & 37 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:
@@ -346,9 +346,10 @@ def choose_font(self):
346346
if valid:
347347
self.save_font_setting(font)
348348

349+
# pylint: disable=too-many-branches,too-many-statements
350+
# pylint: disable=too-many-locals
349351
def accept(self):
350352
"""A callback for accepted event of buttonBox (OK button pressed)"""
351-
# pylint: disable=too-many-branches,too-many-statements
352353
super(SettingsDialog, self).accept()
353354
if self.firstrun:
354355
self.config.remove_option('bitmessagesettings', 'dontconnect')
@@ -374,7 +375,7 @@ def accept(self):
374375

375376
window_style = str(self.comboBoxStyle.currentText())
376377
if self.app.get_windowstyle() != window_style or self.config.safeGet(
377-
'bitmessagesettings', 'font'
378+
'bitmessagesettings', 'font'
378379
) != self.font_setting:
379380
self.config.set('bitmessagesettings', 'windowstyle', window_style)
380381
self.config.set('bitmessagesettings', 'font', self.font_setting)
@@ -455,8 +456,8 @@ def accept(self):
455456
self.config.set('bitmessagesettings', 'sockslisten', str(
456457
self.checkBoxSocksListen.isChecked()))
457458
if (
458-
self.checkBoxOnionOnly.isChecked()
459-
and not self.config.safeGetBoolean(
459+
self.checkBoxOnionOnly.isChecked()
460+
and not self.config.safeGetBoolean(
460461
'bitmessagesettings', 'onionservicesonly')
461462
):
462463
self.net_restart_needed = True
@@ -519,40 +520,39 @@ def accept(self):
519520

520521
acceptableDifficultyChanged = False
521522

522-
if (
523-
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1
524-
or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
525-
):
523+
max_total_diff = float(
524+
self.lineEditMaxAcceptableTotalDifficulty.text())
525+
if max_total_diff >= 1 or max_total_diff == 0:
526+
nonce_trials = str(int(
527+
max_total_diff
528+
* defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
526529
if self.config.get(
527-
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte'
528-
) != str(int(
529-
float(self.lineEditMaxAcceptableTotalDifficulty.text())
530-
* defaults.networkDefaultProofOfWorkNonceTrialsPerByte)):
530+
'bitmessagesettings',
531+
'maxacceptablenoncetrialsperbyte'
532+
) != nonce_trials:
531533
# the user changed the max acceptable total difficulty
532534
acceptableDifficultyChanged = True
533535
self.config.set(
534-
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
535-
str(int(
536-
float(self.lineEditMaxAcceptableTotalDifficulty.text())
537-
* defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
538-
)
539-
if (
540-
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1
541-
or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
542-
):
536+
'bitmessagesettings',
537+
'maxacceptablenoncetrialsperbyte',
538+
nonce_trials)
539+
540+
max_msg_diff = float(
541+
self.lineEditMaxAcceptableSmallMessageDifficulty.text())
542+
if max_msg_diff >= 1 or max_msg_diff == 0:
543+
extra_bytes = str(int(
544+
max_msg_diff
545+
* defaults.networkDefaultPayloadLengthExtraBytes))
543546
if self.config.get(
544-
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
545-
) != str(int(
546-
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text())
547-
* defaults.networkDefaultPayloadLengthExtraBytes)):
547+
'bitmessagesettings',
548+
'maxacceptablepayloadlengthextrabytes'
549+
) != extra_bytes:
548550
# the user changed the max acceptable small message difficulty
549551
acceptableDifficultyChanged = True
550552
self.config.set(
551-
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
552-
str(int(
553-
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text())
554-
* defaults.networkDefaultPayloadLengthExtraBytes))
555-
)
553+
'bitmessagesettings',
554+
'maxacceptablepayloadlengthextrabytes',
555+
extra_bytes)
556556
if acceptableDifficultyChanged:
557557
# It might now be possible to send msgs which were previously
558558
# marked as toodifficult. Let us change them to 'msgqueued'.
@@ -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

0 commit comments

Comments
 (0)