Updated double quotes, removed print statements & fixed long line warnings

This commit is contained in:
kuldeep.k@cisinlabs.com 2021-09-07 22:17:49 +05:30
parent 2402e2c71a
commit 222cfaa92a
No known key found for this signature in database
GPG Key ID: AF4FB299BF7C7C2A

View File

@ -29,7 +29,7 @@ class RPCError(Exception):
self.error = data self.error = data
def __str__(self): def __str__(self):
return '{0}: {1}'.format(type(self).__name__, self.error) return "{0}: {1}".format(type(self).__name__, self.error)
class namecoinConnection(object): class namecoinConnection(object):
@ -52,12 +52,16 @@ class namecoinConnection(object):
actually changing the values (yet). actually changing the values (yet).
""" """
if options is None: if options is None:
self.nmctype = BMConfigParser().get(configSection, "namecoinrpctype") self.nmctype = BMConfigParser().get(
self.host = BMConfigParser().get(configSection, "namecoinrpchost") configSection, "namecoinrpctype")
self.port = int(BMConfigParser().get(configSection, "namecoinrpcport")) self.host = BMConfigParser().get(
self.user = BMConfigParser().get(configSection, "namecoinrpcuser") configSection, "namecoinrpchost")
self.password = BMConfigParser().get(configSection, self.port = int(BMConfigParser().get(
"namecoinrpcpassword") configSection, "namecoinrpcport"))
self.user = BMConfigParser().get(
configSection, "namecoinrpcuser")
self.password = BMConfigParser().get(
configSection, "namecoinrpcpassword")
else: else:
self.nmctype = options["type"] self.nmctype = options["type"]
self.host = options["host"] self.host = options["host"]
@ -92,8 +96,8 @@ class namecoinConnection(object):
res = res["reply"] res = res["reply"]
if not res: if not res:
return (_translate( return (_translate(
"MainWindow", 'The name %1 was not found.' "MainWindow", "The name %1 was not found."
).arg(identity.decode('utf-8', 'ignore')), None) ).arg(identity.decode("utf-8", "ignore")), None)
else: else:
assert False assert False
except RPCError as exc: except RPCError as exc:
@ -103,16 +107,16 @@ class namecoinConnection(object):
else: else:
errmsg = exc.error errmsg = exc.error
return (_translate( return (_translate(
"MainWindow", 'The namecoin query failed (%1)' "MainWindow", "The namecoin query failed (%1)"
).arg(errmsg.decode('utf-8', 'ignore')), None) ).arg(errmsg.decode("utf-8", "ignore")), None)
except AssertionError: except AssertionError:
return (_translate( return (_translate(
"MainWindow", 'Unknown namecoin interface type: %1' "MainWindow", "Unknown namecoin interface type: %1"
).arg(self.nmctype.decode('utf-8', 'ignore')), None) ).arg(self.nmctype.decode("utf-8", "ignore")), None)
except Exception: except Exception:
logger.exception("Namecoin query exception") logger.exception("Namecoin query exception")
return (_translate( return (_translate(
"MainWindow", 'The namecoin query failed.'), None) "MainWindow", "The namecoin query failed."), None)
try: try:
res = json.loads(res) res = json.loads(res)
@ -125,14 +129,14 @@ class namecoinConnection(object):
pass pass
res = res.get("bitmessage") res = res.get("bitmessage")
valid = decodeAddress(res)[0] == 'success' valid = decodeAddress(res)[0] == "success"
return ( return (
None, "%s <%s>" % (display_name, res) None, "%s <%s>" % (display_name, res)
) if valid else ( ) if valid else (
_translate( _translate(
"MainWindow", "MainWindow",
'The name %1 has no associated Bitmessage address.' "The name %1 has no associated Bitmessage address."
).arg(identity.decode('utf-8', 'ignore')), None) ).arg(identity.decode("utf-8", "ignore")), None)
def test(self): def test(self):
""" """
@ -157,31 +161,42 @@ class namecoinConnection(object):
else: else:
versStr = "0.%d.%d.%d" % (v1, v2, v3) versStr = "0.%d.%d.%d" % (v1, v2, v3)
message = ( message = (
'success', "success",
_translate( _translate(
"MainWindow", "MainWindow",
'Success! Namecoind version %1 running.').arg( "Success! Namecoind version %1 running.").arg(
versStr.decode('utf-8', 'ignore'))) versStr.decode("utf-8", "ignore")))
elif self.nmctype == "nmcontrol": elif self.nmctype == "nmcontrol":
res = self.callRPC("data", ["status"]) res = self.callRPC("data", ["status"])
prefix = "Plugin data running" prefix = "Plugin data running"
if ("reply" in res) and res["reply"][:len(prefix)] == prefix: 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) logger.error("Unexpected nmcontrol reply: %s", res)
message = ('failed', _translate("MainWindow", 'Couldn\'t understand NMControl.')) message = (
"failed",
_translate(
"MainWindow",
"Couldn\'t understand NMControl."
)
)
else: else:
print("Unsupported Namecoin type") sys.exit("Unsupported Namecoin type")
sys.exit(1)
return message return message
except Exception: except Exception:
logger.info("Namecoin connection test failure") logger.info("Namecoin connection test failure")
return ( return (
'failed', "failed",
_translate( _translate(
"MainWindow", "The connection to namecoin failed.") "MainWindow", "The connection to namecoin failed.")
) )
@ -226,14 +241,17 @@ class namecoinConnection(object):
self.con.putheader("Content-Length", str(len(data))) self.con.putheader("Content-Length", str(len(data)))
self.con.putheader("Accept", "application/json") self.con.putheader("Accept", "application/json")
authstr = "%s:%s" % (self.user, self.password) 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.endheaders()
self.con.send(data) self.con.send(data)
try: try:
resp = self.con.getresponse() resp = self.con.getresponse()
result = resp.read() result = resp.read()
if resp.status != 200: 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 except: # noqa:E722
logger.info("HTTP receive error") logger.info("HTTP receive error")
except: # noqa:E722 except: # noqa:E722
@ -242,7 +260,8 @@ class namecoinConnection(object):
return result return result
def queryServer(self, data): 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: try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@ -278,13 +297,12 @@ def lookupNamecoinFolder():
if sys.platform == "darwin": if sys.platform == "darwin":
if "HOME" in environ: if "HOME" in environ:
dataFolder = path.join(os.environ["HOME"], dataFolder = path.join(os.environ["HOME"],
"Library/Application Support/", app) + '/' "Library/Application Support/", app) + "/"
else: else:
print( sys.exit(
"Could not find home folder, please report this message" "Could not find home folder, please report this message"
" and your OS X version to the BitMessage Github." " and your OS X version to the BitMessage Github."
) )
sys.exit()
elif "win32" in sys.platform or "win64" in sys.platform: elif "win32" in sys.platform or "win64" in sys.platform:
dataFolder = path.join(environ["APPDATA"], app) + "\\" dataFolder = path.join(environ["APPDATA"], app) + "\\"
@ -335,7 +353,9 @@ def ensureNamecoinOptions():
nmc.close() nmc.close()
except IOError: except IOError:
logger.warning("%s unreadable or missing, Namecoin support deactivated", nmcConfig) logger.warning(
"%s unreadable or missing, Namecoin support deactivated",
nmcConfig)
except Exception: except Exception:
logger.warning("Error processing namecoin.conf", exc_info=True) logger.warning("Error processing namecoin.conf", exc_info=True)