From d33959defc82f360e6e7d311e04c087284fef368 Mon Sep 17 00:00:00 2001 From: anand-skss <160696255+anand-skss@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:48:54 +0000 Subject: [PATCH] Code Quality --- src/bitmessagekivy/identiconGeneration.py | 2 +- src/class_objectProcessor.py | 3 +-- src/depends.py | 2 +- src/network/bmproto.py | 2 +- src/network/networkthread.py | 6 +++--- src/openclpow.py | 2 +- src/proofofwork.py | 12 ++++++------ src/shared.py | 5 ++--- src/upnp.py | 2 +- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/bitmessagekivy/identiconGeneration.py b/src/bitmessagekivy/identiconGeneration.py index 8f129185..17e211dd 100644 --- a/src/bitmessagekivy/identiconGeneration.py +++ b/src/bitmessagekivy/identiconGeneration.py @@ -40,7 +40,7 @@ def generate_hash(string): try: # make input case insensitive string = str.lower(string) - hash_object = hashlib.md5(str.encode(string)) # nosec B303, B324 + hash_object = hashlib.md5(str.encode(string)) # nosec B324, B303 print(hash_object.hexdigest()) # returned object is a hex string return hash_object.hexdigest() diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index bab181b8..b7d351ab 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -686,8 +686,7 @@ class objectProcessor(threading.Thread): apiNotifyPath = config.safeGet( 'bitmessagesettings', 'apinotifypath') if apiNotifyPath: - subprocess.call( # nosec B603 - [apiNotifyPath, "newMessage"]) + subprocess.call([apiNotifyPath, "newMessage"]) # nosec B603 # Let us now check and see whether our receiving address is # behaving as a mailing list diff --git a/src/depends.py b/src/depends.py index b386f468..b3521411 100755 --- a/src/depends.py +++ b/src/depends.py @@ -287,7 +287,7 @@ def check_openssl(): path = ctypes.util.find_library('ssl') if path not in paths: paths.append(path) - except: # nosec:B110 pylint:disable=bare-except + except: # nosec:B110 # pylint:disable=bare-except pass openssl_version = None diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 5af71845..b1b04703 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -610,7 +610,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): 'Closed connection to %s because we are already' ' connected to that IP.', self.destination) return False - except Exception: # nosec:B110 pylint:disable=broad-exception-caught + except Exception: # nosec:B110 # pylint:disable=broad-exception-caught pass if not self.isOutbound: # incoming from a peer we're connected to as outbound, diff --git a/src/network/networkthread.py b/src/network/networkthread.py index 659b16d9..accf50d9 100644 --- a/src/network/networkthread.py +++ b/src/network/networkthread.py @@ -25,17 +25,17 @@ class BMNetworkThread(StoppableThread): for i in BMConnectionPool().listeningSockets.values(): try: i.close() - except: # nosec:B110 pylint:disable=bare-except + except: # nosec:B110 # pylint:disable=bare-except pass for i in BMConnectionPool().outboundConnections.values(): try: i.close() - except: # nosec:B110 pylint:disable=bare-except + except: # nosec:B110 # pylint:disable=bare-except pass for i in BMConnectionPool().inboundConnections.values(): try: i.close() - except: # nosec:B110 pylint:disable=bare-except + except: # nosec:B110 # pylint:disable=bare-except pass # just in case diff --git a/src/openclpow.py b/src/openclpow.py index 4a349af1..9834be5e 100644 --- a/src/openclpow.py +++ b/src/openclpow.py @@ -47,7 +47,7 @@ def initCL(): device_type=cl.device_type.GPU)) if platform.vendor not in vendors: vendors.append(platform.vendor) - except: # nosec:B110 noqa:E722 pylint:disable=bare-except + except: # nosec:B110 # noqa:E722 # pylint:disable=bare-except pass if enabledGpus: ctx = cl.Context(devices=enabledGpus) diff --git a/src/proofofwork.py b/src/proofofwork.py index e560cc78..606a5ca4 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -82,7 +82,7 @@ def _set_idle(): pid = win32api.GetCurrentProcessId() handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid) win32process.SetPriorityClass(handle, win32process.IDLE_PRIORITY_CLASS) - except: # nosec:B110 noqa:E722 pylint:disable=bare-except + except: # nosec:B110 # noqa:E722 # pylint:disable=bare-except # Windows 64-bit pass @@ -135,7 +135,7 @@ def _doFastPoW(target, initialHash): try: pool.terminate() pool.join() - except: # nosec:B110 noqa:E722 pylint:disable=bare-except + except: # nosec:B110 # noqa:E722 # pylint:disable=bare-except pass raise StopIteration("Interrupted") for i in range(pool_size): @@ -297,14 +297,14 @@ def run(target, initialHash): return _doGPUPoW(target, initialHash) except StopIteration: raise - except: # nosec:B110 noqa:E722 pylint:disable=bare-except + except: # nosec:B110 # noqa:E722 # pylint:disable=bare-except pass # fallback if bmpow: try: return _doCPoW(target, initialHash) except StopIteration: raise - except: # nosec:B110 noqa:E722 pylint:disable=bare-except + except: # nosec:B110 # noqa:E722 # pylint:disable=bare-except pass # fallback if paths.frozen == "macosx_app" or not paths.frozen: # on my (Peter Surda) Windows 10, Windows Defender @@ -316,13 +316,13 @@ def run(target, initialHash): except StopIteration: logger.error("Fast PoW got StopIteration") raise - except: # noqa:E722 pylint:disable=bare-except + except: # noqa:E722 # pylint:disable=bare-except logger.error("Fast PoW got exception:", exc_info=True) try: return _doSafePoW(target, initialHash) except StopIteration: raise - except: # nosec:B110 noqa:E722 pylint:disable=bare-except + except: # nosec:B110 # noqa:E722 # pylint:disable=bare-except pass # fallback diff --git a/src/shared.py b/src/shared.py index b1493a44..b23dbd67 100644 --- a/src/shared.py +++ b/src/shared.py @@ -212,10 +212,9 @@ def checkSensitiveFilePermissions(filename): # Skip known problems for non-Win32 filesystems # without POSIX permissions. fstype = subprocess.check_output( - 'stat -f -c "%%T" %s' % (filename), - shell=True, + ['/usr/bin/stat', '-f', '-c', '%T', filename], stderr=subprocess.STDOUT - ) + ) # nosec B603 if 'fuseblk' in fstype: logger.info( 'Skipping file permissions check for %s.' diff --git a/src/upnp.py b/src/upnp.py index 659c7de2..c4a33392 100644 --- a/src/upnp.py +++ b/src/upnp.py @@ -241,7 +241,7 @@ class uPnPThread(StoppableThread): if time.time() - lastSent > self.sendSleep and not self.routers: try: self.sendSearchRouter() - except: # nosec:B110 noqa:E722 pylint:disable=bare-except + except: # nosec:B110 # noqa:E722 # pylint:disable=bare-except pass lastSent = time.time() try: