Replaced string variable by identity & tr._translate by specific function import

This commit is contained in:
kuldeep.k@cisinlabs.com 2021-08-27 13:15:09 +05:30
parent 4148daa8a4
commit 0d59074e44
No known key found for this signature in database
GPG Key ID: AF4FB299BF7C7C2A

View File

@ -11,7 +11,7 @@ import socket
import sys import sys
import defaults import defaults
import tr # translate from tr import _translate # translate
from addresses import decodeAddress from addresses import decodeAddress
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger from debug import logger
@ -70,31 +70,31 @@ class namecoinConnection(object):
if self.nmctype == "namecoind": if self.nmctype == "namecoind":
self.con = httplib.HTTPConnection(self.host, self.port, timeout=3) self.con = httplib.HTTPConnection(self.host, self.port, timeout=3)
def query(self, string): def query(self, identity):
""" """
Query for the bitmessage address corresponding to the given identity Query for the bitmessage address corresponding to the given identity
string. If it doesn't contain a slash, id/ is prepended. We return string. If it doesn't contain a slash, id/ is prepended. We return
the result as (Error, Address) pair, where the Error is an error the result as (Error, Address) pair, where the Error is an error
message to display or None in case of success. message to display or None in case of success.
""" """
slashPos = string.find("/") slashPos = identity.find("/")
if slashPos < 0: if slashPos < 0:
display_name = string display_name = identity
string = "id/" + string identity = "id/" + identity
else: else:
display_name = string.split("/")[1] display_name = identity.split("/")[1]
try: try:
if self.nmctype == "namecoind": if self.nmctype == "namecoind":
res = self.callRPC("name_show", [string]) res = self.callRPC("name_show", [identity])
res = res["value"] res = res["value"]
elif self.nmctype == "nmcontrol": elif self.nmctype == "nmcontrol":
res = self.callRPC("data", ["getValue", string]) res = self.callRPC("data", ["getValue", identity])
res = res["reply"] res = res["reply"]
if not res: if not res:
return (tr._translate( return (_translate(
"MainWindow", 'The name %1 was not found.' "MainWindow", 'The name %1 was not found.'
).arg(string.decode('utf-8')), None) ).arg(identity.decode('utf-8')), None)
else: else:
assert False assert False
except RPCError as exc: except RPCError as exc:
@ -103,16 +103,16 @@ class namecoinConnection(object):
errmsg = exc.error["message"] errmsg = exc.error["message"]
else: else:
errmsg = exc.error errmsg = exc.error
return (tr._translate( return (_translate(
"MainWindow", 'The namecoin query failed (%1)' "MainWindow", 'The namecoin query failed (%1)'
).arg(errmsg.decode('utf-8')), None) ).arg(errmsg.decode('utf-8')), None)
except AssertionError: except AssertionError:
return (tr._translate( return (_translate(
"MainWindow", 'Unknown namecoin interface type: %1' "MainWindow", 'Unknown namecoin interface type: %1'
).arg(self.nmctype.decode('utf-8')), None) ).arg(self.nmctype.decode('utf-8')), None)
except Exception: except Exception:
logger.exception("Namecoin query exception") logger.exception("Namecoin query exception")
return (tr._translate( return (_translate(
"MainWindow", 'The namecoin query failed.'), None) "MainWindow", 'The namecoin query failed.'), None)
try: try:
@ -130,10 +130,10 @@ class namecoinConnection(object):
return ( return (
None, "%s <%s>" % (display_name, res) None, "%s <%s>" % (display_name, res)
) if valid else ( ) if valid else (
tr._translate( _translate(
"MainWindow", "MainWindow",
'The name %1 has no associated Bitmessage address.' 'The name %1 has no associated Bitmessage address.'
).arg(string.decode('utf-8')), None) ).arg(identity.decode('utf-8')), None)
def test(self): def test(self):
""" """
@ -159,7 +159,7 @@ class namecoinConnection(object):
versStr = "0.%d.%d.%d" % (v1, v2, v3) versStr = "0.%d.%d.%d" % (v1, v2, v3)
message = ( message = (
'success', 'success',
tr._translate( _translate(
"MainWindow", "MainWindow",
'Success! Namecoind version %1 running.').arg( 'Success! Namecoind version %1 running.').arg(
versStr.decode('utf-8'))) versStr.decode('utf-8')))
@ -168,10 +168,10 @@ class namecoinConnection(object):
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', tr._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', tr._translate("MainWindow", 'Couldn\'t understand NMControl.')) message = ('failed', _translate("MainWindow", 'Couldn\'t understand NMControl.'))
else: else:
print("Unsupported Namecoin type") print("Unsupported Namecoin type")
@ -183,7 +183,7 @@ class namecoinConnection(object):
logger.info("Namecoin connection test failure") logger.info("Namecoin connection test failure")
return ( return (
'failed', 'failed',
tr._translate( _translate(
"MainWindow", "The connection to namecoin failed.") "MainWindow", "The connection to namecoin failed.")
) )