Fixed: Simple Codacy errors and warnings in src/helper_*
* Some local pickle operations and non-cryptographic random operations were marked as safe to the bandit linter * A bandit config file was added and assert warnings are now ignored globally * Tightened up exception handling and code style
This commit is contained in:
parent
c9a2240b44
commit
dd1ee618a5
4
bandit.yml
Normal file
4
bandit.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Codacy uses Bandit.
|
||||||
|
|
||||||
|
# Asserts are accepted throughout the project.
|
||||||
|
skips: ['B101']
|
|
@ -1,6 +1,6 @@
|
||||||
import socket
|
import socket
|
||||||
import defaultKnownNodes
|
import defaultKnownNodes
|
||||||
import pickle
|
import pickle # nosec
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
@ -24,7 +24,7 @@ def knownNodes():
|
||||||
try:
|
try:
|
||||||
with open(state.appdata + 'knownnodes.dat', 'rb') as pickleFile:
|
with open(state.appdata + 'knownnodes.dat', 'rb') as pickleFile:
|
||||||
with knownnodes.knownNodesLock:
|
with knownnodes.knownNodesLock:
|
||||||
knownnodes.knownNodes = pickle.load(pickleFile)
|
knownnodes.knownNodes = pickle.load(pickleFile) # nosec
|
||||||
# the old format was {Peer:lastseen, ...}
|
# the old format was {Peer:lastseen, ...}
|
||||||
# the new format is {Peer:{"lastseen":i, "rating":f}}
|
# the new format is {Peer:{"lastseen":i, "rating":f}}
|
||||||
for stream in knownnodes.knownNodes.keys():
|
for stream in knownnodes.knownNodes.keys():
|
||||||
|
|
|
@ -140,7 +140,6 @@ class MsgDecode(object):
|
||||||
self.body = body
|
self.body = body
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import random
|
|
||||||
messageData = {
|
messageData = {
|
||||||
"subject": ''.join(helper_random.randomchoice(string.ascii_lowercase + string.digits) for _ in range(40)),
|
"subject": ''.join(helper_random.randomchoice(string.ascii_lowercase + string.digits) for _ in range(40)),
|
||||||
"body": ''.join(helper_random.randomchoice(string.ascii_lowercase + string.digits) for _ in range(10000))
|
"body": ''.join(helper_random.randomchoice(string.ascii_lowercase + string.digits) for _ in range(10000))
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
"""Convenience functions for random operations. Not suitable for security / cryptography operations."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
from pyelliptic.openssl import OpenSSL
|
from pyelliptic.openssl import OpenSSL
|
||||||
|
@ -48,9 +50,9 @@ def randomrandrange(x, y=None):
|
||||||
but doesnt actually build a range object.
|
but doesnt actually build a range object.
|
||||||
"""
|
"""
|
||||||
if isinstance(y, NoneType):
|
if isinstance(y, NoneType):
|
||||||
return random.randrange(x)
|
return random.randrange(x) # nosec
|
||||||
else:
|
else:
|
||||||
return random.randrange(x, y)
|
return random.randrange(x, y) # nosec
|
||||||
|
|
||||||
|
|
||||||
def randomchoice(population):
|
def randomchoice(population):
|
||||||
|
@ -60,4 +62,4 @@ def randomchoice(population):
|
||||||
sequence seq. If seq is empty, raises
|
sequence seq. If seq is empty, raises
|
||||||
IndexError.
|
IndexError.
|
||||||
"""
|
"""
|
||||||
return random.choice(population)
|
return random.choice(population) # nosec
|
||||||
|
|
|
@ -5,7 +5,7 @@ from helper_sql import *
|
||||||
try:
|
try:
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
haveQt = True
|
haveQt = True
|
||||||
except Exception:
|
except ImportError:
|
||||||
haveQt = False
|
haveQt = False
|
||||||
|
|
||||||
def search_translate (context, text):
|
def search_translate (context, text):
|
||||||
|
|
|
@ -91,6 +91,7 @@ class SqlBulkExecute:
|
||||||
def execute(sqlStatement, *args):
|
def execute(sqlStatement, *args):
|
||||||
"""Used for statements that do not return results."""
|
"""Used for statements that do not return results."""
|
||||||
sqlSubmitQueue.put(sqlStatement)
|
sqlSubmitQueue.put(sqlStatement)
|
||||||
|
|
||||||
if args == ():
|
if args == ():
|
||||||
sqlSubmitQueue.put('')
|
sqlSubmitQueue.put('')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -113,7 +113,8 @@ def loadConfig():
|
||||||
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0')
|
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0')
|
||||||
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8')
|
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8')
|
||||||
BMConfigParser().set('bitmessagesettings', 'ttl', '367200')
|
BMConfigParser().set('bitmessagesettings', 'ttl', '367200')
|
||||||
#start:UI setting to stop trying to send messages after X days/months
|
|
||||||
|
#start:UI setting to stop trying to send messages after X days/months
|
||||||
BMConfigParser().set(
|
BMConfigParser().set(
|
||||||
'bitmessagesettings', 'stopresendingafterxdays', '')
|
'bitmessagesettings', 'stopresendingafterxdays', '')
|
||||||
BMConfigParser().set(
|
BMConfigParser().set(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user