From 222cfaa92a3fde99f9d884824c06205afe476664 Mon Sep 17 00:00:00 2001 From: "kuldeep.k@cisinlabs.com" Date: Tue, 7 Sep 2021 22:17:49 +0530 Subject: [PATCH] Updated double quotes, removed print statements & fixed long line warnings --- src/namecoin.py | 84 ++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/src/namecoin.py b/src/namecoin.py index 00df96a4..381a04b0 100644 --- a/src/namecoin.py +++ b/src/namecoin.py @@ -29,7 +29,7 @@ class RPCError(Exception): self.error = data def __str__(self): - return '{0}: {1}'.format(type(self).__name__, self.error) + return "{0}: {1}".format(type(self).__name__, self.error) class namecoinConnection(object): @@ -52,12 +52,16 @@ class namecoinConnection(object): actually changing the values (yet). """ if options is None: - self.nmctype = BMConfigParser().get(configSection, "namecoinrpctype") - self.host = BMConfigParser().get(configSection, "namecoinrpchost") - self.port = int(BMConfigParser().get(configSection, "namecoinrpcport")) - self.user = BMConfigParser().get(configSection, "namecoinrpcuser") - self.password = BMConfigParser().get(configSection, - "namecoinrpcpassword") + self.nmctype = BMConfigParser().get( + configSection, "namecoinrpctype") + self.host = BMConfigParser().get( + configSection, "namecoinrpchost") + self.port = int(BMConfigParser().get( + configSection, "namecoinrpcport")) + self.user = BMConfigParser().get( + configSection, "namecoinrpcuser") + self.password = BMConfigParser().get( + configSection, "namecoinrpcpassword") else: self.nmctype = options["type"] self.host = options["host"] @@ -92,8 +96,8 @@ class namecoinConnection(object): res = res["reply"] if not res: return (_translate( - "MainWindow", 'The name %1 was not found.' - ).arg(identity.decode('utf-8', 'ignore')), None) + "MainWindow", "The name %1 was not found." + ).arg(identity.decode("utf-8", "ignore")), None) else: assert False except RPCError as exc: @@ -103,16 +107,16 @@ class namecoinConnection(object): else: errmsg = exc.error return (_translate( - "MainWindow", 'The namecoin query failed (%1)' - ).arg(errmsg.decode('utf-8', 'ignore')), None) + "MainWindow", "The namecoin query failed (%1)" + ).arg(errmsg.decode("utf-8", "ignore")), None) except AssertionError: return (_translate( - "MainWindow", 'Unknown namecoin interface type: %1' - ).arg(self.nmctype.decode('utf-8', 'ignore')), None) + "MainWindow", "Unknown namecoin interface type: %1" + ).arg(self.nmctype.decode("utf-8", "ignore")), None) except Exception: logger.exception("Namecoin query exception") return (_translate( - "MainWindow", 'The namecoin query failed.'), None) + "MainWindow", "The namecoin query failed."), None) try: res = json.loads(res) @@ -125,14 +129,14 @@ class namecoinConnection(object): pass res = res.get("bitmessage") - valid = decodeAddress(res)[0] == 'success' + valid = decodeAddress(res)[0] == "success" return ( None, "%s <%s>" % (display_name, res) ) if valid else ( _translate( "MainWindow", - 'The name %1 has no associated Bitmessage address.' - ).arg(identity.decode('utf-8', 'ignore')), None) + "The name %1 has no associated Bitmessage address." + ).arg(identity.decode("utf-8", "ignore")), None) def test(self): """ @@ -157,31 +161,42 @@ class namecoinConnection(object): else: versStr = "0.%d.%d.%d" % (v1, v2, v3) message = ( - 'success', + "success", _translate( "MainWindow", - 'Success! Namecoind version %1 running.').arg( - versStr.decode('utf-8', 'ignore'))) + "Success! Namecoind version %1 running.").arg( + versStr.decode("utf-8", "ignore"))) elif self.nmctype == "nmcontrol": res = self.callRPC("data", ["status"]) prefix = "Plugin data running" if ("reply" in res) and res["reply"][:len(prefix)] == prefix: - return ('success', _translate("MainWindow", 'Success! NMControll is up and running.')) + return ( + "success", + _translate( + "MainWindow", + "Success! NMControll is up and running." + ) + ) logger.error("Unexpected nmcontrol reply: %s", res) - message = ('failed', _translate("MainWindow", 'Couldn\'t understand NMControl.')) + message = ( + "failed", + _translate( + "MainWindow", + "Couldn\'t understand NMControl." + ) + ) else: - print("Unsupported Namecoin type") - sys.exit(1) + sys.exit("Unsupported Namecoin type") return message except Exception: logger.info("Namecoin connection test failure") return ( - 'failed', + "failed", _translate( "MainWindow", "The connection to namecoin failed.") ) @@ -226,14 +241,17 @@ class namecoinConnection(object): self.con.putheader("Content-Length", str(len(data))) self.con.putheader("Accept", "application/json") authstr = "%s:%s" % (self.user, self.password) - self.con.putheader("Authorization", "Basic %s" % base64.b64encode(authstr)) + self.con.putheader( + "Authorization", "Basic %s" % base64.b64encode(authstr)) self.con.endheaders() self.con.send(data) try: resp = self.con.getresponse() result = resp.read() if resp.status != 200: - raise Exception("Namecoin returned status %i: %s" % (resp.status, resp.reason)) + raise Exception( + "Namecoin returned status" + " %i: %s" % (resp.status, resp.reason)) except: # noqa:E722 logger.info("HTTP receive error") except: # noqa:E722 @@ -242,7 +260,8 @@ class namecoinConnection(object): return result def queryServer(self, data): - """Helper routine sending data to the RPC server and returning the result.""" + """Helper routine sending data to the RPC " + "server and returning the result.""" try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -278,13 +297,12 @@ def lookupNamecoinFolder(): if sys.platform == "darwin": if "HOME" in environ: dataFolder = path.join(os.environ["HOME"], - "Library/Application Support/", app) + '/' + "Library/Application Support/", app) + "/" else: - print( + sys.exit( "Could not find home folder, please report this message" " and your OS X version to the BitMessage Github." ) - sys.exit() elif "win32" in sys.platform or "win64" in sys.platform: dataFolder = path.join(environ["APPDATA"], app) + "\\" @@ -335,7 +353,9 @@ def ensureNamecoinOptions(): nmc.close() except IOError: - logger.warning("%s unreadable or missing, Namecoin support deactivated", nmcConfig) + logger.warning( + "%s unreadable or missing, Namecoin support deactivated", + nmcConfig) except Exception: logger.warning("Error processing namecoin.conf", exc_info=True)