Skip to content

Commit c99c3fc

Browse files
committed
Fixed: Codacy issues in src/class_*.py
1 parent c9a2240 commit c99c3fc

9 files changed

+137
-184
lines changed

PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
- make the pull request against the ["v0.6" branch](https://github.com/Bitmessage/PyBitmessage/tree/v0.6)
66
- it should be possible to do a fast-forward merge of the pull requests
77
- PGP-sign the commits included in the pull request
8+
- try to use a good editor that removes trailing whitespace, highlights potential python issues and uses unix line endings
89
- You can get paid for merged commits if you register at [Tip4Commit](https://tip4commit.com/github/Bitmessage/PyBitmessage)
910

1011
If for some reason you don't want to use github, you can submit the patch using Bitmessage to the "bitmessage" chan, or to one of the developers.
1112
## Translations
1213

1314
For helping with translations, please use [Transifex](https://www.transifex.com/bitmessage-project/pybitmessage/). There is no need to submit pull requests for translations.
14-
For translating technical terms it is recommended to consult the [Microsoft Language Portal](https://www.microsoft.com/Language/en-US/Default.aspx).
15+
For translating technical terms it is recommended to consult the [Microsoft Language Portal](https://www.microsoft.com/Language/en-US/Default.aspx).

src/class_addressGenerator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def run(self):
230230
# need it if we end up passing the info to the API.
231231
listOfNewAddressesToSendOutThroughTheAPI = []
232232

233-
for i in range(numberOfAddressesToMake):
233+
for _ in range(numberOfAddressesToMake):
234234
# This next section is a little bit strange. We're
235235
# going to generate keys over and over until we find
236236
# one that has a RIPEMD hash that starts with either

src/class_objectProcessor.py

Lines changed: 66 additions & 84 deletions
Large diffs are not rendered by default.

src/class_objectProcessorQueue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def put(self, item, block = True, timeout = None):
2020
def get(self, block = True, timeout = None):
2121
try:
2222
item = Queue.Queue.get(self, block, timeout)
23-
except Queue.Empty as e:
23+
except Queue.Empty:
2424
raise Queue.Empty()
2525
with self.sizeLock:
2626
self.curSize -= len(item[1])

src/class_singleCleaner.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
import gc
2-
import threading
3-
import shared
4-
import time
5-
import os
6-
7-
import tr#anslate
8-
from bmconfigparser import BMConfigParser
9-
from helper_sql import *
10-
from helper_threading import *
11-
from inventory import Inventory
12-
from network.connectionpool import BMConnectionPool
13-
from debug import logger
14-
import knownnodes
15-
import queues
16-
import state
17-
181
"""
19-
The singleCleaner class is a timer-driven thread that cleans data structures
20-
to free memory, resends messages when a remote node doesn't respond, and
2+
The singleCleaner class is a timer-driven thread that cleans data structures
3+
to free memory, resends messages when a remote node doesn't respond, and
214
sends pong messages to keep connections alive if the network isn't busy.
225
It cleans these data structures in memory:
236
inventory (moves data to the on-disk sql database)
@@ -34,6 +17,23 @@
3417
3518
"""
3619

20+
import gc
21+
import threading
22+
import shared
23+
import time
24+
import os
25+
26+
import tr#anslate
27+
from bmconfigparser import BMConfigParser
28+
from helper_sql import *
29+
from helper_threading import *
30+
from inventory import Inventory
31+
from network.connectionpool import BMConnectionPool
32+
from debug import logger
33+
import knownnodes
34+
import queues
35+
import state
36+
3737

3838
class singleCleaner(threading.Thread, StoppableThread):
3939
cycleLength = 300
@@ -61,7 +61,7 @@ def run(self):
6161
'updateStatusBar', 'Doing housekeeping (Flushing inventory in memory to disk...)'))
6262
Inventory().flush()
6363
queues.UISignalQueue.put(('updateStatusBar', ''))
64-
64+
6565
# If we are running as a daemon then we are going to fill up the UI
6666
# queue which will never be handled by a UI. We should clear it to
6767
# save memory.

src/class_singleWorker.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import hashlib
66
from struct import pack
77
# used when the API must execute an outside program
8-
from subprocess import call
8+
from subprocess import call # nosec
99
from binascii import hexlify, unhexlify
1010

1111
import tr
@@ -228,7 +228,7 @@ def _doPOWDefaults(self, payload, TTL,
228228

229229
# This function also broadcasts out the pubkey message
230230
# once it is done with the POW
231-
def doPOWForMyV2Pubkey(self, hash):
231+
def doPOWForMyV2Pubkey(self, adressHash):
232232
# Look up my stream number based on my address hash
233233
"""configSections = shared.config.addresses()
234234
for addressInKeysFile in configSections:
@@ -239,9 +239,9 @@ def doPOWForMyV2Pubkey(self, hash):
239239
if hash == hashFromThisParticularAddress:
240240
myAddress = addressInKeysFile
241241
break"""
242-
myAddress = shared.myAddressesByHash[hash]
242+
myAddress = shared.myAddressesByHash[adressHash]
243243
# status
244-
_, addressVersionNumber, streamNumber, hash = decodeAddress(myAddress)
244+
_, addressVersionNumber, streamNumber, adressHash = decodeAddress(myAddress)
245245

246246
# 28 days from now plus or minus five minutes
247247
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
@@ -293,31 +293,31 @@ def doPOWForMyV2Pubkey(self, hash):
293293
# does the necessary POW and sends it out. If it *is* a chan then it
294294
# assembles the pubkey and stores is in the pubkey table so that we can
295295
# send messages to "ourselves".
296-
def sendOutOrStoreMyV3Pubkey(self, hash):
296+
def sendOutOrStoreMyV3Pubkey(self, adressHash):
297297
try:
298-
myAddress = shared.myAddressesByHash[hash]
298+
myAddress = shared.myAddressesByHash[adressHash]
299299
except:
300300
# The address has been deleted.
301301
return
302302
if BMConfigParser().safeGetBoolean(myAddress, 'chan'):
303303
logger.info('This is a chan address. Not sending pubkey.')
304304
return
305-
status, addressVersionNumber, streamNumber, hash = decodeAddress(
305+
_, addressVersionNumber, streamNumber, adressHash = decodeAddress(
306306
myAddress)
307307

308308
# 28 days from now plus or minus five minutes
309309
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
310310
embeddedTime = int(time.time() + TTL)
311+
311312
# signedTimeForProtocolV2 = embeddedTime - TTL
312-
"""
313-
According to the protocol specification, the expiresTime
314-
along with the pubkey information is signed. But to be
315-
backwards compatible during the upgrade period, we shall sign
316-
not the expiresTime but rather the current time. There must be
317-
precisely a 28 day difference between the two. After the upgrade
318-
period we'll switch to signing the whole payload with the
319-
expiresTime time.
320-
"""
313+
# According to the protocol specification, the expiresTime
314+
# along with the pubkey information is signed. But to be
315+
# backwards compatible during the upgrade period, we shall sign
316+
# not the expiresTime but rather the current time. There must be
317+
# precisely a 28 day difference between the two. After the upgrade
318+
# period we'll switch to signing the whole payload with the
319+
# expiresTime time.
320+
321321
payload = pack('>Q', (embeddedTime))
322322
payload += '\x00\x00\x00\x01' # object type: pubkey
323323
payload += encodeVarint(addressVersionNumber) # Address version number
@@ -379,7 +379,7 @@ def sendOutOrStoreMyV4Pubkey(self, myAddress):
379379
if shared.BMConfigParser().safeGetBoolean(myAddress, 'chan'):
380380
logger.info('This is a chan address. Not sending pubkey.')
381381
return
382-
status, addressVersionNumber, streamNumber, hash = decodeAddress(
382+
_, addressVersionNumber, streamNumber, addressHash = decodeAddress(
383383
myAddress)
384384

385385
# 28 days from now plus or minus five minutes
@@ -419,7 +419,7 @@ def sendOutOrStoreMyV4Pubkey(self, myAddress):
419419
# when they want to send a message.
420420
doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(
421421
encodeVarint(addressVersionNumber) +
422-
encodeVarint(streamNumber) + hash
422+
encodeVarint(streamNumber) + addressHash
423423
).digest()).digest()
424424
payload += doubleHashOfAddressData[32:] # the tag
425425
signature = highlevelcrypto.sign(
@@ -462,6 +462,7 @@ def sendBroadcast(self):
462462
# Reset just in case
463463
sqlExecute(
464464
'''UPDATE sent SET status='broadcastqueued' '''
465+
465466
'''WHERE status = 'doingbroadcastpow' ''')
466467
queryreturn = sqlQuery(
467468
'''SELECT fromaddress, subject, message, '''
@@ -848,7 +849,7 @@ def sendMsg(self):
848849

849850
# to bypass the address version whose length is definitely 1
850851
readPosition = 1
851-
streamNumber, streamNumberLength = decodeVarint(
852+
_, streamNumberLength = decodeVarint(
852853
pubkeyPayload[readPosition:readPosition + 10])
853854
readPosition += streamNumberLength
854855
behaviorBitfield = pubkeyPayload[readPosition:readPosition + 4]
@@ -925,7 +926,7 @@ def sendMsg(self):
925926
# regardless of what they say is allowed in order
926927
# to get our message to propagate through the network.
927928
if requiredAverageProofOfWorkNonceTrialsPerByte < \
928-
defaults.networkDefaultProofOfWorkNonceTrialsPerByte:
929+
defaults.networkDefaultProofOfWorkNonceTrialsPerByte:
929930
requiredAverageProofOfWorkNonceTrialsPerByte = \
930931
defaults.networkDefaultProofOfWorkNonceTrialsPerByte
931932
if requiredPayloadLengthExtraBytes < \
@@ -1266,7 +1267,7 @@ def sendMsg(self):
12661267
except:
12671268
apiNotifyPath = ''
12681269
if apiNotifyPath != '':
1269-
call([apiNotifyPath, "newMessage"])
1270+
call([apiNotifyPath, "newMessage"]) # nosec
12701271

12711272
def requestPubKey(self, toAddress):
12721273
toStatus, addressVersionNumber, streamNumber, ripe = decodeAddress(

src/class_smtpDeliver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class smtpDeliver(threading.Thread, StoppableThread):
1919
def __init__(self, parent=None):
2020
threading.Thread.__init__(self, name="smtpDeliver")
2121
self.initStop()
22-
22+
2323
def stopThread(self):
2424
try:
2525
queues.UISignallerQueue.put(("stopThread", "data"))

src/class_smtpServer.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import re
77
import signal
88
import smtpd
9-
import socket
109
import threading
1110
import time
1211

@@ -16,7 +15,6 @@
1615
from helper_sql import sqlExecute
1716
from helper_ackPayload import genAckPayload
1817
from helper_threading import StoppableThread
19-
from pyelliptic.openssl import OpenSSL
2018
import queues
2119
from version import softwareVersion
2220

@@ -68,7 +66,6 @@ def send(self, fromAddress, toAddress, subject, message):
6866
status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress)
6967
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
7068
ackdata = genAckPayload(streamNumber, stealthLevel)
71-
t = ()
7269
sqlExecute(
7370
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
7471
'',
@@ -97,7 +94,7 @@ def decode_header(self, hdr):
9794
ret.append(unicode(h[0], h[1]))
9895
else:
9996
ret.append(h[0].decode("utf-8", errors='replace'))
100-
97+
10198
return ret
10299

103100

@@ -151,7 +148,7 @@ def process_message(self, peer, mailfrom, rcpttos, data):
151148
raise Exception("Bad domain %s", domain)
152149
logger.debug("Sending %s to %s about %s", sender, rcpt, msg_subject)
153150
self.send(sender, rcpt, msg_subject, body)
154-
logger.info("Relayed %s to %s", sender, rcpt)
151+
logger.info("Relayed %s to %s", sender, rcpt)
155152
except Exception as err:
156153
logger.error( "Bad to %s: %s", to, repr(err))
157154
continue
@@ -162,21 +159,11 @@ def __init__(self, parent=None):
162159
threading.Thread.__init__(self, name="smtpServerThread")
163160
self.initStop()
164161
self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None)
165-
162+
166163
def stopThread(self):
167164
super(smtpServer, self).stopThread()
168165
self.server.close()
169166
return
170-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
171-
# for ip in ('127.0.0.1', BMConfigParser().get('bitmessagesettings', 'onionbindip')):
172-
for ip in ('127.0.0.1'):
173-
try:
174-
s.connect((ip, LISTENPORT))
175-
s.shutdown(socket.SHUT_RDWR)
176-
s.close()
177-
break
178-
except:
179-
pass
180167

181168
def run(self):
182169
asyncore.loop(1)

0 commit comments

Comments
 (0)