python3 formatting and indentation fixes

This commit is contained in:
lakshyacis 2019-12-25 20:21:08 +05:30
parent 0de9e38415
commit ca6a56fcb9
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
8 changed files with 51 additions and 51 deletions

View File

@ -20,7 +20,6 @@ from network.threads import StoppableThread
class addressGenerator(StoppableThread):
"""A thread for creating addresses"""
name = "addressGenerator"
def stopThread(self):
@ -35,7 +34,8 @@ class addressGenerator(StoppableThread):
Process the requests for addresses generation
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:
queueValue = queues.addressGeneratorQueue.get()
nonceTrialsPerByte = 0
@ -206,9 +206,14 @@ class addressGenerator(StoppableThread):
queues.workerQueue.put((
'sendOutOrStoreMyV4Pubkey', address))
elif command == 'createDeterministicAddresses' \
or command == 'getDeterministicAddress' \
or command == 'createChan' or command == 'joinChan':
# elif command == 'createDeterministicAddresses' \
# or command == 'getDeterministicAddress' \
# or command == 'createChan' or command == 'joinChan':
elif command in (
'createDeterministicAddresses',
'getDeterministicAddress',
'createChan',
'joinChan'):
if not deterministicPassphrase:
self.logger.warning(
'You are creating deterministic'
@ -333,8 +338,8 @@ class addressGenerator(StoppableThread):
BMConfigParser().set(address, 'label', label)
BMConfigParser().set(address, 'enabled', 'true')
BMConfigParser().set(address, 'decoy', 'false')
if command == 'joinChan' \
or command == 'createChan':
# if command == 'joinChan' or command == 'createChan':
if command in ('joinChan', 'createChan'):
BMConfigParser().set(address, 'chan', 'true')
BMConfigParser().set(
address, 'noncetrialsperbyte',
@ -385,8 +390,12 @@ class addressGenerator(StoppableThread):
address)
# Done generating addresses.
if command == 'createDeterministicAddresses' \
or command == 'joinChan' or command == 'createChan':
# if command == 'createDeterministicAddresses' \
# or command == 'joinChan' or command == 'createChan':
if command in (
'createDeterministicAddresses',
'joinChan',
'createChan'):
queues.apiAddressGeneratorReturnQueue.put(
listOfNewAddressesToSendOutThroughTheAPI)
elif command == 'getDeterministicAddress':

View File

@ -152,9 +152,8 @@ class objectProcessor(threading.Thread):
(data[readPosition:],
tr._translate(
"MainWindow",
"Acknowledgement of the message received %1"
).arg(l10n.formatTimestamp()))
))
"Acknowledgement of the message received %1").arg(
l10n.formatTimestamp()))))
else:
logger.debug('This object is not an acknowledgement bound for me.')

View File

@ -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

View File

@ -35,6 +35,7 @@ from inventory import Inventory
from network.connectionpool import BMConnectionPool
from network.threads import StoppableThread
class singleCleaner(StoppableThread):
"""The singleCleaner thread class"""
name = "singleCleaner"
@ -200,6 +201,10 @@ def deleteTrashMsgPermonantly():
"""This method is used to delete old messages"""
ndays_before_time = datetime.now() - timedelta(days=30)
old_messages = time.mktime(ndays_before_time.timetuple())
sqlExecute("delete from sent where folder = 'trash' and lastactiontime <= ?;", int(old_messages))
sqlExecute("delete from inbox where folder = 'trash' and received <= ?;", int(old_messages))
sqlExecute(
"delete from sent where folder = 'trash' and lastactiontime <= ?;",
int(old_messages))
sqlExecute(
"delete from inbox where folder = 'trash' and received <= ?;",
int(old_messages))
return

View File

@ -23,7 +23,8 @@ import queues
import shared
import state
import tr
from addresses import calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint)
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory

View File

@ -3,7 +3,6 @@ src/class_smtpDeliver.py
========================
"""
# pylint: disable=unused-variable
import smtplib
import urlparse
from email.header import Header
@ -24,7 +23,8 @@ class smtpDeliver(StoppableThread):
def stopThread(self):
try:
queues.UISignallerQueue.put(("stopThread", "data")) # pylint: disable=no-member
# pylint: disable=no-member
queues.UISignallerQueue.put(("stopThread", "data"))
except:
pass
super(smtpDeliver, self).stopThread()
@ -50,23 +50,27 @@ class smtpDeliver(StoppableThread):
ackData, message = data
elif command == 'displayNewInboxMessage':
inventoryHash, toAddress, fromAddress, subject, body = data
dest = BMConfigParser().safeGet("bitmessagesettings", "smtpdeliver", '')
dest = BMConfigParser().safeGet(
"bitmessagesettings", "smtpdeliver", '')
if dest == '':
continue
try:
# pylint: disable=deprecated-lambda
u = urlparse.urlparse(dest)
to = urlparse.parse_qs(u.query)['to']
client = smtplib.SMTP(u.hostname, u.port)
msg = MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = fromAddress + '@' + SMTPDOMAIN
toLabel = map( # pylint: disable=deprecated-lambda
toLabel = map(
lambda y: BMConfigParser().safeGet(y, "label"),
filter( # pylint: disable=deprecated-lambda
filter(
lambda x: x == toAddress, BMConfigParser().addresses())
)
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:
msg['To'] = toAddress + '@' + SMTPDOMAIN
client.ehlo()
@ -80,7 +84,8 @@ class smtpDeliver(StoppableThread):
except:
self.logger.error('smtp delivery error', exc_info=True)
elif command == 'displayNewSentMessage':
toAddress, fromLabel, fromAddress, subject, message, ackdata = data
toAddress, fromLabel, fromAddress, subject, message, ackdata = \
data
elif command == 'updateNetworkStatusTab':
pass
elif command == 'updateNumberOfMessagesProcessed':

View File

@ -214,7 +214,8 @@ class sqlThread(threading.Thread):
parameters = ''
self.cur.execute(item, parameters)
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(
'In messages.dat database, adding tag field to'
' the inventory table.')
@ -578,9 +579,13 @@ class sqlThread(threading.Thread):
# print ('+++++++++++++++++++++++++++++')
try:
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],)
except (IndexError,TypeError) as e:
except(IndexError, TypeError):
pass
try:
self.cur.execute(item, parameters)