fix small failures in migrating to Python3 + PyQt6
This commit is contained in:
parent
97c9b7eaf6
commit
74bb8763e9
|
@ -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] = '<br><br>'
|
||||
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)
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()))
|
||||
))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -3,7 +3,6 @@ Track randomize ordered dict
|
|||
"""
|
||||
from threading import RLock
|
||||
from time import time
|
||||
from binascii import hexlify
|
||||
|
||||
try:
|
||||
import helper_random
|
||||
|
|
Reference in New Issue
Block a user