From e57a4fa7a980ac1da3b9f6da043a8ec758b65ae5 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sat, 8 May 2021 21:30:45 +0300 Subject: [PATCH] bitmessageqt.__init__: removed or replaced unicode(), formatted a bit --- src/bitmessageqt/__init__.py | 110 ++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 07862e10..5c6bebdc 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -525,9 +525,10 @@ class MyForm(settingsmixin.SMainWindow): # get number of (unread) messages total = 0 - queryreturn = sqlQuery('SELECT toaddress, folder, count(msgid) as cnt FROM inbox WHERE read = 0 GROUP BY toaddress, folder') - for row in queryreturn: - toaddress, folder, cnt = row + queryreturn = sqlQuery( + 'SELECT toaddress, folder, count(msgid) as cnt' + ' FROM inbox WHERE read = 0 GROUP BY toaddress, folder') + for toaddress, folder, cnt in queryreturn: total += cnt if toaddress in db and folder in db[toaddress]: db[toaddress][folder] = cnt @@ -1236,7 +1237,7 @@ class MyForm(settingsmixin.SMainWindow): for row in queryreturn: toAddress, fromAddress, subject, _, msgid, received, read = row self.addMessageListItemInbox( - tableWidget, toAddress, fromAddress, unicode(subject, 'utf-8'), + tableWidget, toAddress, fromAddress, subject.decode('utf-8'), msgid, received, read) tableWidget.horizontalHeader().setSortIndicator( @@ -1446,8 +1447,7 @@ class MyForm(settingsmixin.SMainWindow): def notifierShow( self, title, subtitle, category, label=None, icon=None): self.playSound(category, label) - self._notifier( - unicode(title), unicode(subtitle), category, label, icon) + self._notifier(title, subtitle, category, label, icon) # tree def treeWidgetKeyPressEvent(self, event): @@ -1949,16 +1949,18 @@ class MyForm(settingsmixin.SMainWindow): oldRows[item.address] = [item.label, item.type, i] if self.ui.tableWidgetAddressBook.rowCount() == 0: - self.ui.tableWidgetAddressBook.horizontalHeader().setSortIndicator(0, QtCore.Qt.AscendingOrder) + self.ui.tableWidgetAddressBook.horizontalHeader( + ).setSortIndicator(0, QtCore.Qt.AscendingOrder) if self.ui.tableWidgetAddressBook.isSortingEnabled(): self.ui.tableWidgetAddressBook.setSortingEnabled(False) newRows = {} # subscriptions - queryreturn = sqlQuery('SELECT label, address FROM subscriptions WHERE enabled = 1') - for row in queryreturn: - label, address = row - newRows[address] = [unicode(label, 'utf-8'), AccountMixin.SUBSCRIPTION] + queryreturn = sqlQuery( + 'SELECT label, address FROM subscriptions WHERE enabled = 1') + for label, address in queryreturn: + newRows[address] = [ + label.decode('utf-8'), AccountMixin.SUBSCRIPTION] # chans addresses = getSortedAccounts() for address in addresses: @@ -1969,10 +1971,9 @@ class MyForm(settingsmixin.SMainWindow): ): newRows[address] = [account.getLabel(), AccountMixin.CHAN] # normal accounts - queryreturn = sqlQuery('SELECT * FROM addressbook') - for row in queryreturn: - label, address = row - newRows[address] = [unicode(label, 'utf-8'), AccountMixin.NORMAL] + queryreturn = sqlQuery('SELECT label, address FROM addressbook') + for label, address in queryreturn: + newRows[address] = [label.decode('utf-8'), AccountMixin.NORMAL] completerList = [] for address in sorted( @@ -2117,14 +2118,13 @@ class MyForm(settingsmixin.SMainWindow): ).format(email)) return status, addressVersionNumber, streamNumber = \ - decodeAddress(toAddress)[:3] + decodeAddress(toAddress)[:3] if status != 'success': try: - toAddress_value = unicode( - toAddress, 'utf-8', 'ignore') - except: + toAddress_value = toAddress.decode('utf-8') + except UnicodeDecodeError: logger.warning( - "Failed unicode(toAddress ):", exc_info=True) + "Failed decoding toAddress ):", exc_info=True) logger.error( 'Error: Could not decode recipient address %s: %s', toAddress_value, status) @@ -2331,13 +2331,15 @@ class MyForm(settingsmixin.SMainWindow): for addressInKeysFile in getSortedAccounts(): isEnabled = BMConfigParser().getboolean( addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read. - isMaillinglist = BMConfigParser().safeGetBoolean(addressInKeysFile, 'mailinglist') + isMaillinglist = BMConfigParser().safeGetBoolean( + addressInKeysFile, 'mailinglist') if isEnabled and not isMaillinglist: - label = unicode(BMConfigParser().get(addressInKeysFile, 'label'), 'utf-8', 'ignore').strip() - if label == "": - label = addressInKeysFile - self.ui.comboBoxSendFrom.addItem(avatarize(addressInKeysFile), label, addressInKeysFile) -# self.ui.comboBoxSendFrom.model().sort(1, Qt.AscendingOrder) + label = ( + BMConfigParser().get(addressInKeysFile, 'label').decode( + 'utf-8', 'ignore').strip() or addressInKeysFile) + self.ui.comboBoxSendFrom.addItem( + avatarize(addressInKeysFile), label, addressInKeysFile) + # self.ui.comboBoxSendFrom.model().sort(1, QtCore.Qt.AscendingOrder) for i in range(self.ui.comboBoxSendFrom.count()): address = self.ui.comboBoxSendFrom.itemData( i, QtCore.Qt.UserRole) @@ -2345,7 +2347,7 @@ class MyForm(settingsmixin.SMainWindow): i, AccountColor(address).accountColor(), QtCore.Qt.ForegroundRole) self.ui.comboBoxSendFrom.insertItem(0, '', '') - if(self.ui.comboBoxSendFrom.count() == 2): + if self.ui.comboBoxSendFrom.count() == 2: self.ui.comboBoxSendFrom.setCurrentIndex(1) else: self.ui.comboBoxSendFrom.setCurrentIndex(0) @@ -2357,10 +2359,11 @@ class MyForm(settingsmixin.SMainWindow): addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read. isChan = BMConfigParser().safeGetBoolean(addressInKeysFile, 'chan') if isEnabled and not isChan: - label = unicode(BMConfigParser().get(addressInKeysFile, 'label'), 'utf-8', 'ignore').strip() - if label == "": - label = addressInKeysFile - self.ui.comboBoxSendFromBroadcast.addItem(avatarize(addressInKeysFile), label, addressInKeysFile) + label = ( + BMConfigParser().get(addressInKeysFile, 'label').decode( + 'utf-8', 'ignore').strip() or addressInKeysFile) + self.ui.comboBoxSendFromBroadcast.addItem( + avatarize(addressInKeysFile), label, addressInKeysFile) for i in range(self.ui.comboBoxSendFromBroadcast.count()): address = self.ui.comboBoxSendFromBroadcast.itemData( i, QtCore.Qt.UserRole) @@ -2880,33 +2883,32 @@ class MyForm(settingsmixin.SMainWindow): if not msgid: return queryreturn = sqlQuery( - '''select message from inbox where msgid=?''', msgid) - if queryreturn != []: - for row in queryreturn: - messageText, = row + 'SELECT message FROM inbox WHERE msgid=?', msgid) + try: + lines = queryreturn[-1][0].split('\n') + except IndexError: + lines = '' - lines = messageText.split('\n') totalLines = len(lines) - for i in xrange(totalLines): + for i in range(totalLines): if 'Message ostensibly from ' in lines[i]: lines[i] = ( '
%s
' % lines[i] ) elif ( - lines[i] == - '------------------------------------------------------' + lines[i] + == '------------------------------------------------------' ): lines[i] = '