No more arg() call on result of _translate()

This commit is contained in:
Dmitri Bogomolov 2018-02-22 15:09:40 +02:00
parent 64bd64eea2
commit 6c134d0a08
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
5 changed files with 148 additions and 163 deletions

View File

@ -147,14 +147,11 @@ class objectProcessor(threading.Thread):
' WHERE ackdata=?', ' WHERE ackdata=?',
'ackreceived', int(time.time()), data[readPosition:]) 'ackreceived', int(time.time()), data[readPosition:])
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', 'updateSentItemStatusByAckdata', (
( data[readPosition:], tr._translate(
data[readPosition:],
tr._translate(
"MainWindow", "MainWindow",
"Acknowledgement of the message received %1" "Acknowledgement of the message received {0}"
).arg(l10n.formatTimestamp()) ).format(l10n.formatTimestamp()))
)
)) ))
else: else:
logger.debug('This object is not an acknowledgement bound for me.') logger.debug('This object is not an acknowledgement bound for me.')

View File

@ -24,14 +24,13 @@ import protocol
import queues import queues
import shared import shared
import state import state
import tr
from addresses import ( from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint)
)
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory from inventory import Inventory
from network import knownnodes, StoppableThread from network import knownnodes, StoppableThread
from tr import _translate
def sizeof_fmt(num, suffix='h/s'): def sizeof_fmt(num, suffix='h/s'):
@ -215,9 +214,8 @@ class singleWorker(StoppableThread):
return privSigningKeyHex, privEncryptionKeyHex, \ return privSigningKeyHex, privEncryptionKeyHex, \
pubSigningKey, pubEncryptionKey pubSigningKey, pubEncryptionKey
def _doPOWDefaults(self, payload, TTL, def _doPOWDefaults(
log_prefix='', self, payload, TTL, log_prefix='', log_time=False):
log_time=False):
target = 2 ** 64 / ( target = 2 ** 64 / (
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * ( defaults.networkDefaultProofOfWorkNonceTrialsPerByte * (
len(payload) + 8 + len(payload) + 8 +
@ -243,14 +241,16 @@ class singleWorker(StoppableThread):
'PoW took %.1f seconds, speed %s.', 'PoW took %.1f seconds, speed %s.',
delta, sizeof_fmt(nonce / delta) delta, sizeof_fmt(nonce / delta)
) )
except: # NameError except NameError:
pass pass
payload = pack('>Q', nonce) + payload payload = pack('>Q', nonce) + payload
return payload return payload
def doPOWForMyV2Pubkey(self, adressHash): def doPOWForMyV2Pubkey(self, adressHash):
""" This function also broadcasts out the pubkey """
message once it is done with the POW""" This function also broadcasts out the pubkey message once it is
done with the POW
"""
# Look up my stream number based on my address hash # Look up my stream number based on my address hash
myAddress = shared.myAddressesByHash[adressHash] myAddress = shared.myAddressesByHash[adressHash]
# status # status
@ -306,13 +306,14 @@ class singleWorker(StoppableThread):
def sendOutOrStoreMyV3Pubkey(self, adressHash): def sendOutOrStoreMyV3Pubkey(self, adressHash):
""" """
If this isn't a chan address, this function assembles the pubkey data, does the necessary POW and sends it out. If this isn't a chan address, this function assembles the pubkey
If it *is* a chan then it assembles the pubkey and stores is in the pubkey table so that we can send messages data, does the necessary POW and sends it out.
to "ourselves". If it *is* a chan then it assembles the pubkey and stores it in
the pubkey table so that we can send messages to "ourselves".
""" """
try: try:
myAddress = shared.myAddressesByHash[adressHash] myAddress = shared.myAddressesByHash[adressHash]
except: except KeyError:
# The address has been deleted. # The address has been deleted.
return return
if BMConfigParser().safeGetBoolean(myAddress, 'chan'): if BMConfigParser().safeGetBoolean(myAddress, 'chan'):
@ -389,9 +390,10 @@ class singleWorker(StoppableThread):
def sendOutOrStoreMyV4Pubkey(self, myAddress): def sendOutOrStoreMyV4Pubkey(self, myAddress):
""" """
It doesn't send directly anymore. It put is to a queue for another thread to send at an appropriate time, It doesn't send directly anymore. It put is to a queue for
whereas in the past it directly appended it to the outgoing buffer, I think. Same with all the other methods in another thread to send at an appropriate time, whereas in the
this class. past it directly appended it to the outgoing buffer, I think.
Same with all the other methods in this class.
""" """
if not BMConfigParser().has_section(myAddress): if not BMConfigParser().has_section(myAddress):
# The address has been deleted. # The address has been deleted.
@ -518,7 +520,10 @@ class singleWorker(StoppableThread):
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
def sendBroadcast(self): def sendBroadcast(self):
"""Send a broadcast-type object (assemble the object, perform PoW and put it to the inv announcement queue)""" """
Send a broadcast-type object (assemble the object, perform PoW
and put it to the inv announcement queue)
"""
# Reset just in case # Reset just in case
sqlExecute( sqlExecute(
'''UPDATE sent SET status='broadcastqueued' ''' '''UPDATE sent SET status='broadcastqueued' '''
@ -549,8 +554,7 @@ class singleWorker(StoppableThread):
except: except:
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Error! Could not find sender address" "Error! Could not find sender address"
" (your address) in the keys.dat file.")) " (your address) in the keys.dat file."))
@ -640,8 +644,7 @@ class singleWorker(StoppableThread):
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Doing work necessary to send broadcast...")) "Doing work necessary to send broadcast..."))
)) ))
@ -673,11 +676,9 @@ class singleWorker(StoppableThread):
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate( "MainWindow", "Broadcast sent on {0}"
"MainWindow", ).format(l10n.formatTimestamp()))
"Broadcast sent on %1"
).arg(l10n.formatTimestamp()))
)) ))
# Update the status of the message in the 'sent' table to have # Update the status of the message in the 'sent' table to have
@ -689,7 +690,10 @@ class singleWorker(StoppableThread):
) )
def sendMsg(self): def sendMsg(self):
"""Send a message-type object (assemble the object, perform PoW and put it to the inv announcement queue)""" """
Send a message-type object (assemble the object, perform PoW
and put it to the inv announcement queue)
"""
# pylint: disable=too-many-nested-blocks # pylint: disable=too-many-nested-blocks
# Reset just in case # Reset just in case
sqlExecute( sqlExecute(
@ -785,8 +789,7 @@ class singleWorker(StoppableThread):
) )
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByToAddress', ( 'updateSentItemStatusByToAddress', (
toaddress, toaddress, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Encryption key was requested earlier.")) "Encryption key was requested earlier."))
)) ))
@ -858,8 +861,7 @@ class singleWorker(StoppableThread):
) )
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByToAddress', ( 'updateSentItemStatusByToAddress', (
toaddress, toaddress, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Sending a request for the" "Sending a request for the"
" recipient\'s encryption key.")) " recipient\'s encryption key."))
@ -883,8 +885,7 @@ class singleWorker(StoppableThread):
state.ackdataForWhichImWatching[ackdata] = 0 state.ackdataForWhichImWatching[ackdata] = 0
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Looking up the receiver\'s public key")) "Looking up the receiver\'s public key"))
)) ))
@ -941,15 +942,14 @@ class singleWorker(StoppableThread):
) )
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Problem: Destination is a mobile" "Problem: Destination is a mobile"
" device who requests that the" " device who requests that the"
" destination be included in the" " destination be included in the"
" message but this is disallowed in" " message but this is disallowed in"
" your settings. %1" " your settings. {0}"
).arg(l10n.formatTimestamp())) ).format(l10n.formatTimestamp()))
)) ))
# if the human changes their setting and then # if the human changes their setting and then
# sends another message or restarts their client, # sends another message or restarts their client,
@ -972,8 +972,7 @@ class singleWorker(StoppableThread):
defaults.networkDefaultPayloadLengthExtraBytes defaults.networkDefaultPayloadLengthExtraBytes
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Doing work necessary to send message.\n" "Doing work necessary to send message.\n"
"There is no required difficulty for" "There is no required difficulty for"
@ -1005,32 +1004,18 @@ class singleWorker(StoppableThread):
requiredAverageProofOfWorkNonceTrialsPerByte, requiredAverageProofOfWorkNonceTrialsPerByte,
requiredPayloadLengthExtraBytes requiredPayloadLengthExtraBytes
) )
queues.UISignalQueue.put((
queues.UISignalQueue.put( 'updateSentItemStatusByAckdata', (
( ackdata, _translate(
'updateSentItemStatusByAckdata', "MainWindow",
( "Doing work necessary to send message.\n"
ackdata, "Receiver\'s required difficulty: {0} and {1}"
tr._translate( ).format(
"MainWindow", float(requiredAverageProofOfWorkNonceTrialsPerByte) /
"Doing work necessary to send message.\n" defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
"Receiver\'s required difficulty: %1" float(requiredPayloadLengthExtraBytes) /
" and %2" defaults.networkDefaultPayloadLengthExtraBytes))
).arg( ))
str(
float(requiredAverageProofOfWorkNonceTrialsPerByte) /
defaults.networkDefaultProofOfWorkNonceTrialsPerByte
)
).arg(
str(
float(requiredPayloadLengthExtraBytes) /
defaults.networkDefaultPayloadLengthExtraBytes
)
)
)
)
)
if status != 'forcepow': if status != 'forcepow':
maxacceptablenoncetrialsperbyte = BMConfigParser().getint( maxacceptablenoncetrialsperbyte = BMConfigParser().getint(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte') 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte')
@ -1050,18 +1035,19 @@ class singleWorker(StoppableThread):
ackdata) ackdata)
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Problem: The work demanded by" "Problem: The work demanded by the"
" the recipient (%1 and %2) is" " recipient ({0} and {1}) is more"
" more difficult than you are" " difficult than you are willing"
" willing to do. %3" " to do. {2}"
).arg(str(float(requiredAverageProofOfWorkNonceTrialsPerByte) / ).format(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)).arg( float(requiredAverageProofOfWorkNonceTrialsPerByte) /
str(float(requiredPayloadLengthExtraBytes) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
defaults.networkDefaultPayloadLengthExtraBytes)).arg( float(requiredPayloadLengthExtraBytes) /
l10n.formatTimestamp())))) defaults.networkDefaultPayloadLengthExtraBytes,
l10n.formatTimestamp()))
))
continue continue
else: # if we are sending a message to ourselves or a chan.. else: # if we are sending a message to ourselves or a chan..
self.logger.info('Sending a message.') self.logger.info('Sending a message.')
@ -1075,15 +1061,14 @@ class singleWorker(StoppableThread):
except Exception as err: except Exception as err:
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Problem: You are trying to send a" "Problem: You are trying to send a"
" message to yourself or a chan but your" " message to yourself or a chan but your"
" encryption key could not be found in" " encryption key could not be found in"
" the keys.dat file. Could not encrypt" " the keys.dat file. Could not encrypt"
" message. %1" " message. {0}"
).arg(l10n.formatTimestamp())) ).format(l10n.formatTimestamp()))
)) ))
self.logger.error( self.logger.error(
'Error within sendMsg. Could not read the keys' 'Error within sendMsg. Could not read the keys'
@ -1100,8 +1085,7 @@ class singleWorker(StoppableThread):
defaults.networkDefaultPayloadLengthExtraBytes defaults.networkDefaultPayloadLengthExtraBytes
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Doing work necessary to send message.")) "Doing work necessary to send message."))
)) ))
@ -1123,8 +1107,7 @@ class singleWorker(StoppableThread):
except: except:
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Error! Could not find sender address" "Error! Could not find sender address"
" (your address) in the keys.dat file.")) " (your address) in the keys.dat file."))
@ -1177,8 +1160,7 @@ class singleWorker(StoppableThread):
# The fullAckPayload is a normal msg protocol message # The fullAckPayload is a normal msg protocol message
# with the proof of work already completed that the # with the proof of work already completed that the
# receiver of this message can easily send out. # receiver of this message can easily send out.
fullAckPayload = self.generateFullAckMessage( fullAckPayload = self.generateFullAckMessage(ackdata, TTL)
ackdata, toStreamNumber, TTL)
payload += encodeVarint(len(fullAckPayload)) payload += encodeVarint(len(fullAckPayload))
payload += fullAckPayload payload += fullAckPayload
dataToSign = pack('>Q', embeddedTime) + '\x00\x00\x00\x02' + \ dataToSign = pack('>Q', embeddedTime) + '\x00\x00\x00\x02' + \
@ -1190,8 +1172,7 @@ class singleWorker(StoppableThread):
# We have assembled the data that will be encrypted. # We have assembled the data that will be encrypted.
try: try:
encrypted = highlevelcrypto.encrypt( encrypted = highlevelcrypto.encrypt(
payload, "04" + hexlify(pubEncryptionKeyBase256) payload, "04" + hexlify(pubEncryptionKeyBase256))
)
except: except:
sqlExecute( sqlExecute(
'''UPDATE sent SET status='badkey' WHERE ackdata=? AND folder='sent' ''', '''UPDATE sent SET status='badkey' WHERE ackdata=? AND folder='sent' ''',
@ -1199,12 +1180,11 @@ class singleWorker(StoppableThread):
) )
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Problem: The recipient\'s encryption key is" "Problem: The recipient\'s encryption key is"
" no good. Could not encrypt message. %1" " no good. Could not encrypt message. {0}"
).arg(l10n.formatTimestamp())) ).format(l10n.formatTimestamp()))
)) ))
continue continue
@ -1268,21 +1248,19 @@ class singleWorker(StoppableThread):
not protocol.checkBitfield(behaviorBitfield, protocol.BITFIELD_DOESACK): not protocol.checkBitfield(behaviorBitfield, protocol.BITFIELD_DOESACK):
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate( "MainWindow", "Message sent. Sent at {0}"
"MainWindow", ).format(l10n.formatTimestamp()))
"Message sent. Sent at %1" ))
).arg(l10n.formatTimestamp()))))
else: else:
# not sending to a chan or one of my addresses # not sending to a chan or one of my addresses
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Message sent. Waiting for acknowledgement." "Message sent. Waiting for acknowledgement."
" Sent on %1" " Sent on {0}"
).arg(l10n.formatTimestamp())) ).format(l10n.formatTimestamp()))
)) ))
self.logger.info( self.logger.info(
'Broadcasting inv for my msg(within sendmsg function): %s', 'Broadcasting inv for my msg(within sendmsg function): %s',
@ -1411,8 +1389,7 @@ class singleWorker(StoppableThread):
queues.UISignalQueue.put(('updateStatusBar', statusbar)) queues.UISignalQueue.put(('updateStatusBar', statusbar))
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByToAddress', ( 'updateSentItemStatusByToAddress', (
toAddress, toAddress, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Doing work necessary to request encryption key.")) "Doing work necessary to request encryption key."))
)) ))
@ -1436,30 +1413,31 @@ class singleWorker(StoppableThread):
int(time.time()), retryNumber + 1, sleeptill, toAddress) int(time.time()), retryNumber + 1, sleeptill, toAddress)
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateStatusBar', 'updateStatusBar', _translate(
tr._translate(
"MainWindow", "MainWindow",
"Broadcasting the public key request. This program will" "Broadcasting the public key request. This program will"
" auto-retry if they are offline.") " auto-retry if they are offline.")
)) ))
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByToAddress', ( 'updateSentItemStatusByToAddress', (
toAddress, toAddress, _translate(
tr._translate(
"MainWindow", "MainWindow",
"Sending public key request. Waiting for reply." "Sending public key request. Waiting for reply."
" Requested at %1" " Requested at {0}"
).arg(l10n.formatTimestamp())) ).format(l10n.formatTimestamp()))
)) ))
def generateFullAckMessage(self, ackdata, _, TTL): def generateFullAckMessage(self, ackdata, TTL):
""" """Create ACK packet"""
It might be perfectly fine to just use the same TTL for the ackdata that we use for the message. But I would # It might be perfectly fine to just use the same TTL for
rather it be more difficult for attackers to associate ackData with the associated msg object. However, users # the ackdata that we use for the message. But I would rather
would want the TTL of the acknowledgement to be about the same as they set for the message itself. So let's set # it be more difficult for attackers to associate ackData with
the TTL of the acknowledgement to be in one of three 'buckets': 1 hour, 7 days, or 28 days, whichever is # the associated msg object. However, users would want the TTL
relatively close to what the user specified. # of the acknowledgement to be about the same as they set
""" # for the message itself. So let's set the TTL of the
# acknowledgement to be in one of three 'buckets': 1 hour, 7
# days, or 28 days, whichever is relatively close to what the
# user specified.
if TTL < 24 * 60 * 60: # 1 day if TTL < 24 * 60 * 60: # 1 day
TTL = 24 * 60 * 60 # 1 day TTL = 24 * 60 * 60 # 1 day
elif TTL < 7 * 24 * 60 * 60: # 1 week elif TTL < 7 * 24 * 60 * 60: # 1 week

View File

@ -11,10 +11,10 @@ import socket
import sys import sys
import defaults import defaults
import tr # 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
from tr import _translate
configSection = "bitmessagesettings" configSection = "bitmessagesettings"
@ -22,7 +22,6 @@ configSection = "bitmessagesettings"
class RPCError(Exception): class RPCError(Exception):
"""Error thrown when the RPC call returns an error.""" """Error thrown when the RPC call returns an error."""
error = None error = None
def __init__(self, data): def __init__(self, data):
@ -47,8 +46,8 @@ class namecoinConnection(object):
def __init__(self, options=None): def __init__(self, options=None):
""" """
Initialise. If options are given, take the connection settings from Initialise. If options are given, take the connection settings from
them instead of loading from the configs. This can be used to test them instead of loading from the configs. This can be used to test
currently entered connection settings in the config dialog without currently entered connection settings in the config dialog without
actually changing the values (yet). actually changing the values (yet).
""" """
@ -73,7 +72,7 @@ class namecoinConnection(object):
def query(self, string): def query(self, string):
""" """
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.
""" """
@ -92,9 +91,9 @@ class namecoinConnection(object):
res = self.callRPC("data", ["getValue", string]) res = self.callRPC("data", ["getValue", string])
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 {0} was not found."
).arg(unicode(string)), None) ).format(string), None)
else: else:
assert False assert False
except RPCError as exc: except RPCError as exc:
@ -103,17 +102,17 @@ 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 ({0})"
).arg(unicode(errmsg)), None) ).format(errmsg), None)
except AssertionError: except AssertionError:
return (tr._translate( return (_translate(
"MainWindow", 'Unknown namecoin interface type: %1' "MainWindow", "Unknown namecoin interface type: {0}"
).arg(unicode(self.nmctype)), None) ).format(self.nmctype), 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:
res = json.loads(res) res = json.loads(res)
@ -130,14 +129,16 @@ 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 {0} has no associated Bitmessage address."
).arg(unicode(string)), None) ).format(string),
None
)
def test(self): def test(self):
""" """
Test the connection settings. This routine tries to query a "getinfo" Test the connection settings. This routine tries to query a "getinfo"
command, and builds either an error message or a success message with command, and builds either an error message or a success message with
some info from it. some info from it.
""" """
@ -157,33 +158,36 @@ class namecoinConnection(object):
versStr = "0.%d.%d" % (v1, v2) versStr = "0.%d.%d" % (v1, v2)
else: else:
versStr = "0.%d.%d.%d" % (v1, v2, v3) versStr = "0.%d.%d.%d" % (v1, v2, v3)
message = ( return (
'success', 'success', _translate(
tr._translate(
"MainWindow", "MainWindow",
'Success! Namecoind version %1 running.').arg( "Success! Namecoind version {0} running."
unicode(versStr))) ).format(versStr)
)
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', 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.')) return (
'failed', _translate(
"MainWindow", "Couldn\'t understand NMControl.")
)
else: else:
print "Unsupported Namecoin type" sys.exit("Unsupported Namecoin type")
sys.exit(1)
return message
except Exception: except Exception:
logger.info("Namecoin connection test failure") logger.info("Namecoin connection test failure")
return ( return (
'failed', 'failed', _translate(
tr._translate(
"MainWindow", "The connection to namecoin failed.") "MainWindow", "The connection to namecoin failed.")
) )
@ -243,7 +247,9 @@ 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)

View File

@ -139,9 +139,10 @@ class TCPConnection(BMProto, TLSDispatcher):
'updateStatusBar', 'updateStatusBar',
_translate( _translate(
"MainWindow", "MainWindow",
"The time on your computer, %1, may be wrong. " "The time on your computer, {0}, may be wrong. "
"Please verify your settings." "Please verify your settings."
).arg(l10n.formatTimestamp()))) ).format(l10n.formatTimestamp())
))
def state_connection_fully_established(self): def state_connection_fully_established(self):
""" """

View File

@ -269,9 +269,12 @@ class uPnPThread(StoppableThread):
with knownnodes.knownNodesLock: with knownnodes.knownNodesLock:
knownnodes.addKnownNode( knownnodes.addKnownNode(
1, self_peer, is_self=True) 1, self_peer, is_self=True)
queues.UISignalQueue.put(('updateStatusBar', tr._translate( queues.UISignalQueue.put((
"MainWindow", 'UPnP port mapping established on port %1' 'updateStatusBar', tr._translate(
).arg(str(self.extPort)))) "MainWindow",
"UPnP port mapping established on port {0}"
).format(self.extPort)
))
break break
except socket.timeout: except socket.timeout:
pass pass