From 3f773c78f70c5a517d26c8fa4d9858c1d4fd3bb6 Mon Sep 17 00:00:00 2001 From: lakshya Date: Mon, 18 May 2020 21:30:13 +0530 Subject: [PATCH] setting, openssl and bmproto quality fixes --- src/bitmessageqt/settings.py | 49 +++++++++++++++++++----------------- src/network/bmproto.py | 13 +++++----- src/pyelliptic/openssl.py | 4 +-- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 1f650fe7..8e4bf198 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -1,3 +1,6 @@ +""" +This module setting file is for settings +""" import ConfigParser import os import sys @@ -110,7 +113,7 @@ class SettingsDialog(QtGui.QDialog): tempfile.NamedTemporaryFile( dir=paths.lookupExeFolder(), delete=True ).close() # should autodelete - except: + except Exception: self.checkBoxPortableMode.setDisabled(True) if 'darwin' in sys.platform: @@ -407,14 +410,14 @@ class SettingsDialog(QtGui.QDialog): self.config.set( 'bitmessagesettings', 'defaultnoncetrialsperbyte', str(int( - float(self.lineEditTotalDifficulty.text()) * - defaults.networkDefaultProofOfWorkNonceTrialsPerByte))) + float(self.lineEditTotalDifficulty.text()) + * defaults.networkDefaultProofOfWorkNonceTrialsPerByte))) if float(self.lineEditSmallMessageDifficulty.text()) >= 1: self.config.set( 'bitmessagesettings', 'defaultpayloadlengthextrabytes', str(int( - float(self.lineEditSmallMessageDifficulty.text()) * - defaults.networkDefaultPayloadLengthExtraBytes))) + float(self.lineEditSmallMessageDifficulty.text()) + * defaults.networkDefaultPayloadLengthExtraBytes))) if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet( 'bitmessagesettings', 'opencl'): @@ -426,40 +429,40 @@ class SettingsDialog(QtGui.QDialog): acceptableDifficultyChanged = False if ( - float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or - float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0 + float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 + or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0 ): if self.config.get( 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte' ) != str(int( - float(self.lineEditMaxAcceptableTotalDifficulty.text()) * - defaults.networkDefaultProofOfWorkNonceTrialsPerByte) + float(self.lineEditMaxAcceptableTotalDifficulty.text()) + * defaults.networkDefaultProofOfWorkNonceTrialsPerByte) ): # the user changed the max acceptable total difficulty acceptableDifficultyChanged = True self.config.set( 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', str(int( - float(self.lineEditMaxAcceptableTotalDifficulty.text()) * - defaults.networkDefaultProofOfWorkNonceTrialsPerByte)) + float(self.lineEditMaxAcceptableTotalDifficulty.text()) + * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)) ) if ( - float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or - float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0 + float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 + or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0 ): if self.config.get( 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes' ) != str(int( - float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) * - defaults.networkDefaultPayloadLengthExtraBytes) + float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) + * defaults.networkDefaultPayloadLengthExtraBytes) ): # the user changed the max acceptable small message difficulty acceptableDifficultyChanged = True self.config.set( 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int( - float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) * - defaults.networkDefaultPayloadLengthExtraBytes)) + float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) + * defaults.networkDefaultPayloadLengthExtraBytes)) ) if acceptableDifficultyChanged: # It might now be possible to send msgs which were previously @@ -537,8 +540,8 @@ class SettingsDialog(QtGui.QDialog): self.parent.updateStartOnLogon() if ( - state.appdata != paths.lookupExeFolder() and - self.checkBoxPortableMode.isChecked() + state.appdata != paths.lookupExeFolder() + and self.checkBoxPortableMode.isChecked() ): # If we are NOT using portable mode now but the user selected # that we should... @@ -556,12 +559,12 @@ class SettingsDialog(QtGui.QDialog): try: os.remove(previousAppdataLocation + 'debug.log') os.remove(previousAppdataLocation + 'debug.log.1') - except: + except Exception: pass if ( - state.appdata == paths.lookupExeFolder() and - not self.checkBoxPortableMode.isChecked() + state.appdata == paths.lookupExeFolder() + and not self.checkBoxPortableMode.isChecked() ): # If we ARE using portable mode now but the user selected # that we shouldn't... @@ -579,5 +582,5 @@ class SettingsDialog(QtGui.QDialog): try: os.remove(paths.lookupExeFolder() + 'debug.log') os.remove(paths.lookupExeFolder() + 'debug.log.1') - except: + except Exception: pass diff --git a/src/network/bmproto.py b/src/network/bmproto.py index ed8e5924..637e2ba7 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -441,9 +441,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker): if stream not in state.streamsInWhichIAmParticipating: continue if ( - decodedIP and time.time() - seenTime > 0 and - seenTime > time.time() - ADDRESS_ALIVE and - port > 0 + decodedIP + and time.time() - seenTime > 0 + and seenTime > time.time() - ADDRESS_ALIVE + and port > 0 ): peer = Peer(decodedIP, port) try: @@ -541,8 +542,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker): logger.debug( '%(host)s:%(port)i sending version', self.destination._asdict()) - if ((self.services & protocol.NODE_SSL == protocol.NODE_SSL) and - protocol.haveSSL(not self.isOutbound)): + if ((self.services & protocol.NODE_SSL == protocol.NODE_SSL) + and protocol.haveSSL(not self.isOutbound)): self.isSSL = True if not self.verackReceived: return True @@ -600,7 +601,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): 'Closed connection to %s because we are already' ' connected to that IP.', self.destination) return False - except: + except Exception: pass if not self.isOutbound: # incoming from a peer we're connected to as outbound, diff --git a/src/pyelliptic/openssl.py b/src/pyelliptic/openssl.py index 17a8d6d1..accaaa94 100644 --- a/src/pyelliptic/openssl.py +++ b/src/pyelliptic/openssl.py @@ -453,7 +453,7 @@ class _OpenSSL(object): try: self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC - except: + except Exception: # The above is not compatible with all versions of OSX. self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC_SHA1 @@ -794,7 +794,7 @@ def loadOpenSSL(): try: OpenSSL = _OpenSSL(library) return - except: + except Exception: pass raise Exception( "Couldn't find and load the OpenSSL library. You must install it.")