diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py
index aaf2f243..2ecd8e40 100644
--- a/src/bitmessageqt/__init__.py
+++ b/src/bitmessageqt/__init__.py
@@ -53,7 +53,7 @@ import shutdown
from .statusbar import BMStatusBar
import bitmessageqt.sound as sound
# This is needed for tray icon
-import bitmessageqt.bitmessage_icons_rc as bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import
+import bitmessageqt.bitmessage_icons_rc as bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import
import helper_sent
try:
@@ -1419,7 +1419,7 @@ class MyForm(settingsmixin.SMainWindow):
self, title, subtitle, category, label=None, icon=QtWidgets.QSystemTrayIcon.MessageIcon.Information):
self.playSound(category, label)
self._notifier(
- str(title), str(subtitle), category, label, icon)
+ title, subtitle, category, label, icon)
# tree
def treeWidgetKeyPressEvent(self, event):
@@ -2860,7 +2860,6 @@ class MyForm(settingsmixin.SMainWindow):
lines[i] = '
'
content = ' '.join(lines) # To keep the whitespace between lines
content = shared.fixPotentiallyInvalidUTF8Data(content)
- content = content
textEdit.setHtml(content)
def on_action_InboxMarkUnread(self):
@@ -3786,20 +3785,20 @@ class MyForm(settingsmixin.SMainWindow):
self.setAddressSound(widget.item(widget.currentRow(), 0).text())
def setAddressSound(self, addr):
- filters = [str(_translate(
+ filters = [_translate(
"MainWindow", "Sound files (%s)" %
' '.join(['*%s%s' % (os.extsep, ext) for ext in sound.extensions])
- ))]
- sourcefile = str(QtWidgets.QFileDialog.getOpenFileName(
+ )]
+ sourcefile = QtWidgets.QFileDialog.getOpenFileName(
self, _translate("MainWindow", "Set notification sound..."),
filter=';;'.join(filters)
- ))
+ )
if not sourcefile:
return
destdir = os.path.join(state.appdata, 'sounds')
- destfile = str(addr) + os.path.splitext(sourcefile)[-1]
+ destfile = addr + os.path.splitext(sourcefile)[-1]
destination = os.path.join(destdir, destfile)
if sourcefile == destination:
@@ -3952,7 +3951,6 @@ class MyForm(settingsmixin.SMainWindow):
def inboxSearchLineEditUpdated(self, text):
# dynamic search for too short text is slow
- text = text
if 0 < len(text) < 3:
return
messagelist = self.getCurrentMessagelist()
@@ -4080,7 +4078,7 @@ class MyForm(settingsmixin.SMainWindow):
self.rerenderMessagelistToLabels()
completerList = self.ui.lineEditTo.completer().model().stringList()
for i in range(len(completerList)):
- if str(completerList[i]).endswith(" <" + item.address + ">"):
+ if completerList[i].endswith(" <" + item.address + ">"):
completerList[i] = item.label + " <" + item.address + ">"
self.ui.lineEditTo.completer().model().setStringList(completerList)
diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py
index 896b355d..13d7ba77 100644
--- a/src/bitmessageqt/foldertree.py
+++ b/src/bitmessageqt/foldertree.py
@@ -135,7 +135,6 @@ class AccountMixin(object):
if queryreturn != []:
for row in queryreturn:
retval, = row
- retval = retval
elif self.address is None or self.type == AccountMixin.ALL:
return _translate("MainWindow", "All accounts")
diff --git a/src/class_addressGenerator.py b/src/class_addressGenerator.py
index 800ea241..feed720e 100644
--- a/src/class_addressGenerator.py
+++ b/src/class_addressGenerator.py
@@ -142,7 +142,7 @@ class addressGenerator(StoppableThread):
):
break
self.logger.info(
- 'Generated address with ripe digest: %s', hexlify(ripe))
+ 'Generated address with ripe digest: %s', hexlify(ripe).decode())
try:
self.logger.info(
'Address generator calculated %s addresses at %s'
@@ -255,7 +255,7 @@ class addressGenerator(StoppableThread):
break
self.logger.info(
- 'Generated address with ripe digest: %s', hexlify(ripe))
+ 'Generated address with ripe digest: %s', hexlify(ripe).decode())
try:
self.logger.info(
'Address generator calculated %s addresses'
diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py
index 1a71f929..d9920f4a 100644
--- a/src/class_objectProcessor.py
+++ b/src/class_objectProcessor.py
@@ -153,7 +153,7 @@ class objectProcessor(threading.Thread):
data[readPosition:],
_translate(
"MainWindow",
- "Acknowledgement of the message received {}"
+ "Acknowledgement of the message received {0}"
).format(l10n.formatTimestamp()))
))
else:
@@ -326,8 +326,8 @@ class objectProcessor(threading.Thread):
'within recpubkey, addressVersion: %s, streamNumber: %s'
'\nripe %s\npublicSigningKey in hex: %s'
'\npublicEncryptionKey in hex: %s',
- addressVersion, streamNumber, hexlify(ripe),
- hexlify(publicSigningKey), hexlify(publicEncryptionKey)
+ addressVersion, streamNumber, hexlify(ripe).decode(),
+ hexlify(publicSigningKey).decode(), hexlify(publicEncryptionKey).decode()
)
address = encodeAddress(addressVersion, streamNumber, ripe)
@@ -391,8 +391,8 @@ class objectProcessor(threading.Thread):
'within recpubkey, addressVersion: %s, streamNumber: %s'
'\nripe %s\npublicSigningKey in hex: %s'
'\npublicEncryptionKey in hex: %s',
- addressVersion, streamNumber, hexlify(ripe),
- hexlify(publicSigningKey), hexlify(publicEncryptionKey)
+ addressVersion, streamNumber, hexlify(ripe).decode(),
+ hexlify(publicSigningKey).decode(), hexlify(publicEncryptionKey).decode()
)
address = encodeAddress(addressVersion, streamNumber, ripe)
@@ -481,7 +481,7 @@ class objectProcessor(threading.Thread):
initialDecryptionSuccessful = True
logger.info(
'EC decryption successful using key associated'
- ' with ripe hash: %s.', hexlify(key))
+ ' with ripe hash: %s.', hexlify(key).decode())
except Exception: # nosec B110
pass
if not initialDecryptionSuccessful:
@@ -544,8 +544,8 @@ class objectProcessor(threading.Thread):
' Attack.\nSee: '
'http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html'
'\nyour toRipe: %s\nembedded destination toRipe: %s',
- hexlify(toRipe),
- hexlify(decryptedData[readPosition:readPosition + 20])
+ hexlify(toRipe).decode(),
+ hexlify(decryptedData[readPosition:readPosition + 20]).decode()
)
readPosition += 20
messageEncodingType, messageEncodingTypeLength = decodeVarint(
@@ -808,9 +808,9 @@ class objectProcessor(threading.Thread):
logger.info(
'EC decryption successful using key associated'
' with ripe hash: %s', hexlify(key).decode())
- except Exception as ex:
+ except Exception:
logger.debug(
- 'cryptorObject.decrypt Exception: {}'.format(ex))
+ 'cryptorObject.decrypt Exception:', exc_info=True)
if not initialDecryptionSuccessful:
# This is not a broadcast I am interested in.
return logger.debug(
diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py
index 7a41f3c1..846467e5 100644
--- a/src/class_singleWorker.py
+++ b/src/class_singleWorker.py
@@ -146,38 +146,38 @@ class singleWorker(StoppableThread):
if command == 'sendmessage':
try:
self.sendMsg()
- except Exception as ex: # noqa:E722
- self.logger.warning("sendMsg didn't work: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("sendMsg didn't work")
elif command == 'sendbroadcast':
try:
self.sendBroadcast()
- except Exception as ex: # noqa:E722
- self.logger.warning("sendBroadcast didn't work: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("sendBroadcast didn't work")
elif command == 'doPOWForMyV2Pubkey':
try:
self.doPOWForMyV2Pubkey(data)
- except Exception as ex: # noqa:E722
- self.logger.warning("doPOWForMyV2Pubkey didn't work: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("doPOWForMyV2Pubkey didn't work")
elif command == 'sendOutOrStoreMyV3Pubkey':
try:
self.sendOutOrStoreMyV3Pubkey(data)
- except Exception as ex: # noqa:E722
- self.logger.warning("sendOutOrStoreMyV3Pubkey didn't work: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("sendOutOrStoreMyV3Pubkey didn't work")
elif command == 'sendOutOrStoreMyV4Pubkey':
try:
self.sendOutOrStoreMyV4Pubkey(data)
- except Exception as ex: # noqa:E722
- self.logger.warning("sendOutOrStoreMyV4Pubkey didn't work: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("sendOutOrStoreMyV4Pubkey didn't work")
elif command == 'sendOnionPeerObj':
try:
self.sendOnionPeerObj(data)
- except Exception as ex: # noqa:E722
- self.logger.warning("sendOnionPeerObj didn't work: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("sendOnionPeerObj didn't work")
elif command == 'resetPoW':
try:
proofofwork.resetPoW()
- except Exception as ex: # noqa:E722
- self.logger.warning("proofofwork.resetPoW didn't work: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("proofofwork.resetPoW didn't work")
elif command == 'stopThread':
self.busy = 0
return
@@ -1230,8 +1230,8 @@ class singleWorker(StoppableThread):
encrypted = highlevelcrypto.encrypt(
payload, b"04" + hexlify(pubEncryptionKeyBase256)
)
- except Exception as ex: # noqa:E722
- self.logger.warning("highlevelcrypto.encrypt didn't work: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("highlevelcrypto.encrypt didn't work")
sqlExecute(
'''UPDATE sent SET status='badkey' WHERE ackdata=? AND folder='sent' ''',
ackdata
@@ -1282,8 +1282,8 @@ class singleWorker(StoppableThread):
time.time() - powStartTime,
sizeof_fmt(nonce / (time.time() - powStartTime))
)
- except Exception as ex: # noqa:E722
- self.logger.warning("Proof of Work exception: {}".format(ex))
+ except: # noqa:E722
+ self.logger.warning("Proof of Work exception")
encryptedPayload = pack('>Q', nonce) + encryptedPayload
@@ -1485,7 +1485,7 @@ class singleWorker(StoppableThread):
tr._translate(
"MainWindow",
"Sending public key request. Waiting for reply."
- " Requested at %1"
+ " Requested at {0}"
).format(l10n.formatTimestamp()))
))
diff --git a/src/depends.py b/src/depends.py
index 3f08f4d3..c894faad 100755
--- a/src/depends.py
+++ b/src/depends.py
@@ -435,8 +435,8 @@ def check_dependencies(verbose=False, optional=False):
logger.info('Python version: %s', sys.version)
if sys.hexversion < 0x3000000:
logger.error(
- 'PyBitmessage requires Python 3 or greater')
- #has_all_dependencies = False
+ 'PyBitmessage does not support Python 2.7-. Python 3'
+ ' or greater is required.')
sys.exit()
# FIXME: This needs to be uncommented when more of the code is python3 compatible
diff --git a/src/helper_msgcoding.py b/src/helper_msgcoding.py
index 225f352c..8aa8dc0f 100644
--- a/src/helper_msgcoding.py
+++ b/src/helper_msgcoding.py
@@ -71,16 +71,12 @@ class MsgEncode(object):
def encodeSimple(self, message):
"""Handle simple encoding"""
- data = 'Subject:%(subject)s\nBody:%(body)s' % message
- self.data = data.encode('utf-8', 'backslashreplace')
+ self.data = ('Subject:%(subject)s\nBody:%(body)s' % message).encode()
self.length = len(self.data)
def encodeTrivial(self, message):
"""Handle trivial encoding"""
- data = message['body']
- if isinstance(data, str):
- data = data.encode('utf-8', 'backslashreplace')
- self.data = data
+ self.data = message['body'].encode()
self.length = len(self.data)
@@ -146,7 +142,7 @@ class MsgDecode(object):
def decodeSimple(self, data):
"""Handle simple encoding"""
- data = data.decode('utf-8', 'backslashreplace')
+ data = data.decode('utf-8', 'replace')
bodyPositionIndex = data.find('\nBody:')
if bodyPositionIndex > 1:
subject = data[8:bodyPositionIndex]
diff --git a/src/network/__init__.py b/src/network/__init__.py
index 1851e072..cc7bfb58 100644
--- a/src/network/__init__.py
+++ b/src/network/__init__.py
@@ -12,7 +12,7 @@ def start(config, state):
"""Start network threads"""
import state
from .announcethread import AnnounceThread
- import network.connectionpool as connectionpool # pylint: disable=relative-import
+ import network.connectionpool as connectionpool # pylint: disable=relative-import
from .addrthread import AddrThread
from .dandelion import Dandelion
from .downloadthread import DownloadThread
diff --git a/src/network/asyncore_pollchoose.py b/src/network/asyncore_pollchoose.py
index ccbe2aef..f37c9df8 100644
--- a/src/network/asyncore_pollchoose.py
+++ b/src/network/asyncore_pollchoose.py
@@ -723,9 +723,9 @@ class dispatcher(object):
if why.args[0] not in (ENOTCONN, EBADF):
raise
- # XXX unresolved
# cheap inheritance, used to pass all other attribute
# references to the underlying socket object.
+ # XXX unresolved: is this can be removed safely or not?
#def __getattr__(self, attr):
# try:
# retattr = getattr(self.socket, attr)
diff --git a/src/network/bmproto.py b/src/network/bmproto.py
index 4ef131d8..be7ea795 100644
--- a/src/network/bmproto.py
+++ b/src/network/bmproto.py
@@ -110,16 +110,15 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
b"error", b"version", b"verack"):
logger.error(
'Received command %s before connection was fully'
- ' established, ignoring', self.command.decode('utf-8', 'replace'))
+ ' established, ignoring', self.command)
self.invalid = True
if not self.invalid:
try:
retval = getattr(
self, "bm_command_" + self.command.decode('utf-8', 'replace').lower())()
- except AttributeError as err:
- logger.debug('command = {}, err = {}'.format(self.command.decode('utf-8', 'replace'), err))
+ except AttributeError:
# unimplemented command
- logger.debug('unimplemented command %s', self.command.decode('utf-8', 'replace'))
+ logger.debug('unimplemented command %s', self.command)
except BMProtoInsufficientDataError:
logger.debug('packet length too short, skipping')
except BMProtoExcessiveDataError:
@@ -142,8 +141,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
# broken read, ignore
pass
else:
- logger.debug('Closing due to invalid command %s', self.command.decode('utf-8', 'replace'))
- self.close_reason = "Invalid command %s" % self.command.decode('utf-8', 'replace')
+ logger.debug('Closing due to invalid command %s', self.command)
+ self.close_reason = "Invalid command %s" % self.command
self.set_state("close")
return False
if retval:
diff --git a/src/network/tcp.py b/src/network/tcp.py
index 75768f22..a49804a6 100644
--- a/src/network/tcp.py
+++ b/src/network/tcp.py
@@ -184,10 +184,7 @@ class TCPConnection(BMProto, TLSDispatcher):
try:
return s.endswith(tail)
except:
- try:
- return s.decode('ascii').endswith(tail)
- except UnicodeDecodeError:
- return False
+ return s.decode('utf-8', 'replace').endswith(tail)
templist = []
addrs = {}
diff --git a/src/network/tls.py b/src/network/tls.py
index 2f30fcc0..59dfc082 100644
--- a/src/network/tls.py
+++ b/src/network/tls.py
@@ -92,6 +92,7 @@ class TLSDispatcher(AdvancedDispatcher):
ciphers=self.ciphers, do_handshake_on_connect=False)
self.sslSocket.setblocking(0)
self.want_read = self.want_write = True
+ self.tlsPrepared = True
return False
@staticmethod
@@ -139,7 +140,6 @@ class TLSDispatcher(AdvancedDispatcher):
if self.tlsStarted and not self.tlsDone and not self.write_buf:
if not self.tlsPrepared:
self.do_tls_init()
- self.tlsPrepared = True
else:
self.tls_handshake()
else:
@@ -165,7 +165,6 @@ class TLSDispatcher(AdvancedDispatcher):
if self.tlsStarted and not self.tlsDone and not self.write_buf:
if not self.tlsPrepared:
self.do_tls_init()
- self.tlsPrepared = True
else:
self.tls_handshake()
else:
diff --git a/src/randomtrackingdict.py b/src/randomtrackingdict.py
index 1435180a..0944da2a 100644
--- a/src/randomtrackingdict.py
+++ b/src/randomtrackingdict.py
@@ -3,7 +3,6 @@ Track randomize ordered dict
"""
from threading import RLock
from time import time
-from binascii import hexlify
try:
import helper_random