python3 formatting and indentation fixes
This commit is contained in:
parent
0de9e38415
commit
ca6a56fcb9
|
@ -20,7 +20,6 @@ from network.threads import StoppableThread
|
||||||
|
|
||||||
class addressGenerator(StoppableThread):
|
class addressGenerator(StoppableThread):
|
||||||
"""A thread for creating addresses"""
|
"""A thread for creating addresses"""
|
||||||
|
|
||||||
name = "addressGenerator"
|
name = "addressGenerator"
|
||||||
|
|
||||||
def stopThread(self):
|
def stopThread(self):
|
||||||
|
@ -35,7 +34,8 @@ class addressGenerator(StoppableThread):
|
||||||
Process the requests for addresses generation
|
Process the requests for addresses generation
|
||||||
from `.queues.addressGeneratorQueue`
|
from `.queues.addressGeneratorQueue`
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-locals, too-many-branches, protected-access, too-many-statements
|
# pylint: disable=too-many-locals, too-many-branches
|
||||||
|
# pylint: disable=protected-access, too-many-statements
|
||||||
while state.shutdown == 0:
|
while state.shutdown == 0:
|
||||||
queueValue = queues.addressGeneratorQueue.get()
|
queueValue = queues.addressGeneratorQueue.get()
|
||||||
nonceTrialsPerByte = 0
|
nonceTrialsPerByte = 0
|
||||||
|
@ -206,9 +206,14 @@ class addressGenerator(StoppableThread):
|
||||||
queues.workerQueue.put((
|
queues.workerQueue.put((
|
||||||
'sendOutOrStoreMyV4Pubkey', address))
|
'sendOutOrStoreMyV4Pubkey', address))
|
||||||
|
|
||||||
elif command == 'createDeterministicAddresses' \
|
# elif command == 'createDeterministicAddresses' \
|
||||||
or command == 'getDeterministicAddress' \
|
# or command == 'getDeterministicAddress' \
|
||||||
or command == 'createChan' or command == 'joinChan':
|
# or command == 'createChan' or command == 'joinChan':
|
||||||
|
elif command in (
|
||||||
|
'createDeterministicAddresses',
|
||||||
|
'getDeterministicAddress',
|
||||||
|
'createChan',
|
||||||
|
'joinChan'):
|
||||||
if not deterministicPassphrase:
|
if not deterministicPassphrase:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'You are creating deterministic'
|
'You are creating deterministic'
|
||||||
|
@ -333,8 +338,8 @@ class addressGenerator(StoppableThread):
|
||||||
BMConfigParser().set(address, 'label', label)
|
BMConfigParser().set(address, 'label', label)
|
||||||
BMConfigParser().set(address, 'enabled', 'true')
|
BMConfigParser().set(address, 'enabled', 'true')
|
||||||
BMConfigParser().set(address, 'decoy', 'false')
|
BMConfigParser().set(address, 'decoy', 'false')
|
||||||
if command == 'joinChan' \
|
# if command == 'joinChan' or command == 'createChan':
|
||||||
or command == 'createChan':
|
if command in ('joinChan', 'createChan'):
|
||||||
BMConfigParser().set(address, 'chan', 'true')
|
BMConfigParser().set(address, 'chan', 'true')
|
||||||
BMConfigParser().set(
|
BMConfigParser().set(
|
||||||
address, 'noncetrialsperbyte',
|
address, 'noncetrialsperbyte',
|
||||||
|
@ -385,8 +390,12 @@ class addressGenerator(StoppableThread):
|
||||||
address)
|
address)
|
||||||
|
|
||||||
# Done generating addresses.
|
# Done generating addresses.
|
||||||
if command == 'createDeterministicAddresses' \
|
# if command == 'createDeterministicAddresses' \
|
||||||
or command == 'joinChan' or command == 'createChan':
|
# or command == 'joinChan' or command == 'createChan':
|
||||||
|
if command in (
|
||||||
|
'createDeterministicAddresses',
|
||||||
|
'joinChan',
|
||||||
|
'createChan'):
|
||||||
queues.apiAddressGeneratorReturnQueue.put(
|
queues.apiAddressGeneratorReturnQueue.put(
|
||||||
listOfNewAddressesToSendOutThroughTheAPI)
|
listOfNewAddressesToSendOutThroughTheAPI)
|
||||||
elif command == 'getDeterministicAddress':
|
elif command == 'getDeterministicAddress':
|
||||||
|
|
|
@ -152,9 +152,8 @@ class objectProcessor(threading.Thread):
|
||||||
(data[readPosition:],
|
(data[readPosition:],
|
||||||
tr._translate(
|
tr._translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
"Acknowledgement of the message received %1"
|
"Acknowledgement of the message received %1").arg(
|
||||||
).arg(l10n.formatTimestamp()))
|
l10n.formatTimestamp()))))
|
||||||
))
|
|
||||||
else:
|
else:
|
||||||
logger.debug('This object is not an acknowledgement bound for me.')
|
logger.debug('This object is not an acknowledgement bound for me.')
|
||||||
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import queue as Queue
|
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
|
|
||||||
class ObjectProcessorQueue(Queue.Queue):
|
|
||||||
maxSize = 32000000
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
Queue.Queue.__init__(self)
|
|
||||||
self.sizeLock = threading.Lock()
|
|
||||||
self.curSize = 0 # in Bytes. We maintain this to prevent nodes from flooing us with objects which take up too much memory. If this gets too big we'll sleep before asking for further objects.
|
|
||||||
|
|
||||||
def put(self, item, block = True, timeout = None):
|
|
||||||
while self.curSize >= self.maxSize:
|
|
||||||
time.sleep(1)
|
|
||||||
with self.sizeLock:
|
|
||||||
self.curSize += len(item[1])
|
|
||||||
Queue.Queue.put(self, item, block, timeout)
|
|
||||||
|
|
||||||
def get(self, block = True, timeout = None):
|
|
||||||
item = Queue.Queue.get(self, block, timeout)
|
|
||||||
with self.sizeLock:
|
|
||||||
self.curSize -= len(item[1])
|
|
||||||
return item
|
|
|
@ -35,6 +35,7 @@ from inventory import Inventory
|
||||||
from network.connectionpool import BMConnectionPool
|
from network.connectionpool import BMConnectionPool
|
||||||
from network.threads import StoppableThread
|
from network.threads import StoppableThread
|
||||||
|
|
||||||
|
|
||||||
class singleCleaner(StoppableThread):
|
class singleCleaner(StoppableThread):
|
||||||
"""The singleCleaner thread class"""
|
"""The singleCleaner thread class"""
|
||||||
name = "singleCleaner"
|
name = "singleCleaner"
|
||||||
|
@ -200,6 +201,10 @@ def deleteTrashMsgPermonantly():
|
||||||
"""This method is used to delete old messages"""
|
"""This method is used to delete old messages"""
|
||||||
ndays_before_time = datetime.now() - timedelta(days=30)
|
ndays_before_time = datetime.now() - timedelta(days=30)
|
||||||
old_messages = time.mktime(ndays_before_time.timetuple())
|
old_messages = time.mktime(ndays_before_time.timetuple())
|
||||||
sqlExecute("delete from sent where folder = 'trash' and lastactiontime <= ?;", int(old_messages))
|
sqlExecute(
|
||||||
sqlExecute("delete from inbox where folder = 'trash' and received <= ?;", int(old_messages))
|
"delete from sent where folder = 'trash' and lastactiontime <= ?;",
|
||||||
|
int(old_messages))
|
||||||
|
sqlExecute(
|
||||||
|
"delete from inbox where folder = 'trash' and received <= ?;",
|
||||||
|
int(old_messages))
|
||||||
return
|
return
|
||||||
|
|
|
@ -23,7 +23,8 @@ import queues
|
||||||
import shared
|
import shared
|
||||||
import state
|
import state
|
||||||
import tr
|
import tr
|
||||||
from addresses import calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
|
from addresses import (
|
||||||
|
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint)
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from helper_sql import sqlExecute, sqlQuery
|
from helper_sql import sqlExecute, sqlQuery
|
||||||
from inventory import Inventory
|
from inventory import Inventory
|
||||||
|
|
|
@ -3,7 +3,6 @@ src/class_smtpDeliver.py
|
||||||
========================
|
========================
|
||||||
"""
|
"""
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
|
|
||||||
import smtplib
|
import smtplib
|
||||||
import urlparse
|
import urlparse
|
||||||
from email.header import Header
|
from email.header import Header
|
||||||
|
@ -24,7 +23,8 @@ class smtpDeliver(StoppableThread):
|
||||||
|
|
||||||
def stopThread(self):
|
def stopThread(self):
|
||||||
try:
|
try:
|
||||||
queues.UISignallerQueue.put(("stopThread", "data")) # pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
|
queues.UISignallerQueue.put(("stopThread", "data"))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
super(smtpDeliver, self).stopThread()
|
super(smtpDeliver, self).stopThread()
|
||||||
|
@ -50,23 +50,27 @@ class smtpDeliver(StoppableThread):
|
||||||
ackData, message = data
|
ackData, message = data
|
||||||
elif command == 'displayNewInboxMessage':
|
elif command == 'displayNewInboxMessage':
|
||||||
inventoryHash, toAddress, fromAddress, subject, body = data
|
inventoryHash, toAddress, fromAddress, subject, body = data
|
||||||
dest = BMConfigParser().safeGet("bitmessagesettings", "smtpdeliver", '')
|
dest = BMConfigParser().safeGet(
|
||||||
|
"bitmessagesettings", "smtpdeliver", '')
|
||||||
if dest == '':
|
if dest == '':
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
# pylint: disable=deprecated-lambda
|
||||||
u = urlparse.urlparse(dest)
|
u = urlparse.urlparse(dest)
|
||||||
to = urlparse.parse_qs(u.query)['to']
|
to = urlparse.parse_qs(u.query)['to']
|
||||||
client = smtplib.SMTP(u.hostname, u.port)
|
client = smtplib.SMTP(u.hostname, u.port)
|
||||||
msg = MIMEText(body, 'plain', 'utf-8')
|
msg = MIMEText(body, 'plain', 'utf-8')
|
||||||
msg['Subject'] = Header(subject, 'utf-8')
|
msg['Subject'] = Header(subject, 'utf-8')
|
||||||
msg['From'] = fromAddress + '@' + SMTPDOMAIN
|
msg['From'] = fromAddress + '@' + SMTPDOMAIN
|
||||||
toLabel = map( # pylint: disable=deprecated-lambda
|
toLabel = map(
|
||||||
lambda y: BMConfigParser().safeGet(y, "label"),
|
lambda y: BMConfigParser().safeGet(y, "label"),
|
||||||
filter( # pylint: disable=deprecated-lambda
|
filter(
|
||||||
lambda x: x == toAddress, BMConfigParser().addresses())
|
lambda x: x == toAddress, BMConfigParser().addresses())
|
||||||
)
|
)
|
||||||
if toLabel:
|
if toLabel:
|
||||||
msg['To'] = "\"%s\" <%s>" % (Header(toLabel[0], 'utf-8'), toAddress + '@' + SMTPDOMAIN)
|
msg['To'] = "\"%s\" <%s>" % (
|
||||||
|
Header(toLabel[0], 'utf-8'),
|
||||||
|
toAddress + '@' + SMTPDOMAIN)
|
||||||
else:
|
else:
|
||||||
msg['To'] = toAddress + '@' + SMTPDOMAIN
|
msg['To'] = toAddress + '@' + SMTPDOMAIN
|
||||||
client.ehlo()
|
client.ehlo()
|
||||||
|
@ -80,7 +84,8 @@ class smtpDeliver(StoppableThread):
|
||||||
except:
|
except:
|
||||||
self.logger.error('smtp delivery error', exc_info=True)
|
self.logger.error('smtp delivery error', exc_info=True)
|
||||||
elif command == 'displayNewSentMessage':
|
elif command == 'displayNewSentMessage':
|
||||||
toAddress, fromLabel, fromAddress, subject, message, ackdata = data
|
toAddress, fromLabel, fromAddress, subject, message, ackdata = \
|
||||||
|
data
|
||||||
elif command == 'updateNetworkStatusTab':
|
elif command == 'updateNetworkStatusTab':
|
||||||
pass
|
pass
|
||||||
elif command == 'updateNumberOfMessagesProcessed':
|
elif command == 'updateNumberOfMessagesProcessed':
|
||||||
|
|
|
@ -214,7 +214,8 @@ class sqlThread(threading.Thread):
|
||||||
parameters = ''
|
parameters = ''
|
||||||
self.cur.execute(item, parameters)
|
self.cur.execute(item, parameters)
|
||||||
currentVersion = int(self.cur.fetchall()[0][0])
|
currentVersion = int(self.cur.fetchall()[0][0])
|
||||||
if currentVersion == 1 or currentVersion == 3:
|
# if currentVersion == 1 or currentVersion == 3:
|
||||||
|
if currentVersion in (1, 3):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'In messages.dat database, adding tag field to'
|
'In messages.dat database, adding tag field to'
|
||||||
' the inventory table.')
|
' the inventory table.')
|
||||||
|
@ -578,9 +579,13 @@ class sqlThread(threading.Thread):
|
||||||
# print ('+++++++++++++++++++++++++++++')
|
# print ('+++++++++++++++++++++++++++++')
|
||||||
try:
|
try:
|
||||||
if 'sent' == parameters[1] and 'B' in parameters[0]:
|
if 'sent' == parameters[1] and 'B' in parameters[0]:
|
||||||
item = '''SELECT toaddress, fromaddress, subject, message, status, ackdata, lastactiontime FROM sent WHERE fromaddress = ? ORDER BY lastactiontime DESC '''
|
item = (
|
||||||
|
'''SELECT toaddress, fromaddress, subject,'''
|
||||||
|
''' message, status, ackdata, lastactiontime'''
|
||||||
|
''' FROM sent WHERE fromaddress = ?'''
|
||||||
|
''' ORDER BY lastactiontime DESC''')
|
||||||
parameters = (parameters[0],)
|
parameters = (parameters[0],)
|
||||||
except (IndexError,TypeError) as e:
|
except(IndexError, TypeError):
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
self.cur.execute(item, parameters)
|
self.cur.execute(item, parameters)
|
||||||
|
|
Reference in New Issue
Block a user