Browse Source

py3port: Exception as e: e.message -> e.args[0]

MMGen 6 years ago
parent
commit
25c31e8c32

+ 1 - 1
mmgen/addr.py

@@ -709,7 +709,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
 			data = self.parse_file_body(lines[1:-1])
 			assert issubclass(type(data),list),'Invalid file body data'
 		except Exception as e:
-			m = 'Invalid address list file ({})'.format(e.message)
+			m = 'Invalid address list file ({})'.format(e.args[0])
 			if exit_on_error: die(3,m)
 			msg(msg)
 			return False

+ 1 - 1
mmgen/altcoins/eth/obj.py

@@ -56,7 +56,7 @@ class ETHNonce(int,Hilite,InitErrors): # WIP
 			return me
 		except Exception as e:
 			m = "{!r}: value cannot be converted to ETH nonce ({})"
-			return cls.init_fail(m.format(n,e.message),on_fail)
+			return cls.init_fail(m.format(n,e.args[0]),on_fail)
 
 	@classmethod
 	def colorize(cls,s,color=True):

+ 2 - 2
mmgen/altcoins/eth/tx.py

@@ -300,7 +300,7 @@ class EthereumMMGenTX(MMGenTX):
 				self.token_addr = TokenAddr(hexlify(etx.creates))
 		except Exception as e:
 			m = "{!r}: transaction signing failed!"
-			msg(m.format(e.message))
+			msg(m.format(e.args[0]))
 			return False
 
 		return self.check_sigs()
@@ -462,7 +462,7 @@ class EthereumTokenMMGenTX(EthereumMMGenTX):
 			msg('OK')
 		except Exception as e:
 			m = "{!r}: transaction signing failed!"
-			msg(m.format(e.message))
+			msg(m.format(e.args[0]))
 			return False
 
 		return self.check_sigs()

+ 2 - 2
mmgen/main.py

@@ -45,8 +45,8 @@ def launch(what):
 			if os.getenv('MMGEN_TRACEBACK'):
 				raise
 			else:
-				try: m = '{}'.format(e.message)
-				except: m = repr(e.message)
+				try: m = '{}'.format(e.args[0])
+				except: m = repr(e.args[0])
 
 				from mmgen.util import die,ydie,rdie
 				d = [   (ydie,2,'\nMMGen Unhandled Exception ({n}): {m}'),

+ 2 - 2
mmgen/main_addrimport.py

@@ -83,7 +83,7 @@ try:
 	rpc_init()
 except UnrecognizedTokenSymbol as e:
 	m = "When importing addresses for a new token, the token must be specified by address, not symbol."
-	raise type(e)('{}\n{}'.format(e.message,m))
+	raise type(e)('{}\n{}'.format(e.args[0],m))
 
 if len(cmd_args) == 1:
 	infile = cmd_args[0]
@@ -124,7 +124,7 @@ def import_address(addr,label,rescan):
 	try: tw.import_address(addr,label,rescan)
 	except Exception as e:
 		global err_msg
-		err_msg = e.message
+		err_msg = e.args[0]
 
 w_n_of_m = len(str(al.num_addrs)) * 2 + 2
 w_mmid = 1 if opt.addrlist or opt.address else len(str(max(al.idxs()))) + 13

+ 1 - 1
mmgen/main_autosign.py

@@ -196,7 +196,7 @@ def sign_tx_file(txfile):
 		else:
 			return False
 	except Exception as e:
-		msg('An error occurred: {}'.format(e.message))
+		msg('An error occurred: {}'.format(e.args[0]))
 		return False
 	except:
 		return False

+ 1 - 1
mmgen/main_wallet.py

@@ -164,7 +164,7 @@ else:
 		m = 'Make this wallet your default and move it to the data directory?'
 		assert keypress_confirm(m,default_yes=True),'dw'
 	except Exception as e:
-		if e.message != 'dw': raise
+		if e.args[0] != 'dw': raise
 		ss_out.write_to_file()
 	else:
 		ss_out.write_to_file(outdir=g.data_dir)

+ 17 - 17
mmgen/obj.py

@@ -273,7 +273,7 @@ class AddrIdx(int,InitErrors):
 			return me
 		except Exception as e:
 			m = "{!r}: value cannot be converted to address index ({})"
-			return cls.init_fail(m.format(num,e.message),on_fail)
+			return cls.init_fail(m.format(num,e.args[0]),on_fail)
 
 class AddrIdxList(list,InitErrors,MMGenObject):
 	max_len = 1000000
@@ -303,7 +303,7 @@ class AddrIdxList(list,InitErrors,MMGenObject):
 				raise ValueError("{!r}: invalid range".format(i))
 		except Exception as e:
 			m = "{!r}: value cannot be converted to AddrIdxList ({})"
-			return type(self).init_fail(m.format(idx_list or fmt_str,e.message),on_fail)
+			return type(self).init_fail(m.format(idx_list or fmt_str,e.args[0]),on_fail)
 
 class UnknownCoinAmt(Decimal): pass
 
@@ -337,7 +337,7 @@ class BTCAmt(Decimal,Hilite,InitErrors):
 			return me
 		except Exception as e:
 			m = "{!r}: value cannot be converted to {} ({})"
-			return cls.init_fail(m.format(num,cls.__name__,e.message),on_fail)
+			return cls.init_fail(m.format(num,cls.__name__,e.args[0]),on_fail)
 
 	def toSatoshi(self):
 		return int(Decimal(self) // self.satoshi)
@@ -419,7 +419,7 @@ class CoinAddr(str,Hilite,InitErrors,MMGenObject):
 			return me
 		except Exception as e:
 			m = "{!r}: value cannot be converted to {} address ({})"
-			return cls.init_fail(m.format(s,g.proto.__name__,e.message),on_fail)
+			return cls.init_fail(m.format(s,g.proto.__name__,e.args[0]),on_fail)
 
 	@classmethod
 	def fmtc(cls,s,**kwargs):
@@ -488,7 +488,7 @@ class SeedID(str,Hilite,InitErrors):
 			raise ValueError('no arguments provided')
 		except Exception as e:
 			m = "{!r}: value cannot be converted to SeedID ({})"
-			return cls.init_fail(m.format(seed or sid,e.message),on_fail)
+			return cls.init_fail(m.format(seed or sid,e.args[0]),on_fail)
 
 class MMGenID(str,Hilite,InitErrors,MMGenObject):
 	color = 'orange'
@@ -511,7 +511,7 @@ class MMGenID(str,Hilite,InitErrors,MMGenObject):
 			return me
 		except Exception as e:
 			m = "{}\n{!r}: value cannot be converted to MMGenID"
-			return cls.init_fail(m.format(e.message,s),on_fail)
+			return cls.init_fail(m.format(e.args[0],s),on_fail)
 
 class TwMMGenID(str,Hilite,InitErrors,MMGenObject):
 	color = 'orange'
@@ -534,7 +534,7 @@ class TwMMGenID(str,Hilite,InitErrors,MMGenObject):
 				ret,sort_key,idtype = str(s),'z_'+s,'non-mmgen'
 			except Exception as f:
 				m = "{}\nValue is {}\n{!r}: value cannot be converted to TwMMGenID"
-				return cls.init_fail(m.format(e.message,f.message,s),on_fail)
+				return cls.init_fail(m.format(e.args[0],f.args[0],s),on_fail)
 
 		me = str.__new__(cls,ret)
 		me.obj = ret
@@ -557,7 +557,7 @@ class TwLabel(str,InitErrors,MMGenObject):
 			return me
 		except Exception as e:
 			m = "{}\n{!r}: value cannot be converted to TwLabel"
-			return cls.init_fail(m.format(e.message,s),on_fail)
+			return cls.init_fail(m.format(e.args[0],s),on_fail)
 
 class HexStr(str,Hilite,InitErrors):
 	color = 'red'
@@ -573,7 +573,7 @@ class HexStr(str,Hilite,InitErrors):
 			return str.__new__(cls,s)
 		except Exception as e:
 			m = "{!r}: value cannot be converted to {} (value is {})"
-			return cls.init_fail(m.format(s,cls.__name__,e.message),on_fail)
+			return cls.init_fail(m.format(s,cls.__name__,e.args[0]),on_fail)
 
 class Str(str,Hilite): pass
 class Int(int,Hilite): pass
@@ -591,7 +591,7 @@ class HexStrWithWidth(HexStr):
 			return ret
 		except Exception as e:
 			m = "{}\n{!r}: value cannot be converted to {}"
-			return cls.init_fail(m.format(e.message,s,cls.__name__),on_fail)
+			return cls.init_fail(m.format(e.args[0],s,cls.__name__),on_fail)
 
 class MMGenTxID(HexStrWithWidth):      color,width,hexcase = 'red',6,'upper'
 class MoneroViewKey(HexStrWithWidth):  color,width,hexcase = 'cyan',64,'lower'
@@ -610,7 +610,7 @@ class WifKey(str,Hilite,InitErrors):
 			g.proto.wif2hex(s) # raises exception on error
 			return str.__new__(cls,s)
 		except Exception as e:
-			m = '{!r}: invalid value for WIF key ({})'.format(s,e.message)
+			m = '{!r}: invalid value for WIF key ({})'.format(s,e.args[0])
 			return cls.init_fail(m,on_fail)
 
 class PubKey(HexStr,MMGenObject): # TODO: add some real checks
@@ -621,7 +621,7 @@ class PubKey(HexStr,MMGenObject): # TODO: add some real checks
 			me.compressed = compressed
 			return me
 		except Exception as e:
-			m = '{!r}: invalid value for pubkey ({})'.format(s,e.message)
+			m = '{!r}: invalid value for pubkey ({})'.format(s,e.args[0])
 			return cls.init_fail(m,on_fail)
 
 class PrivKey(str,Hilite,InitErrors,MMGenObject):
@@ -653,7 +653,7 @@ class PrivKey(str,Hilite,InitErrors,MMGenObject):
 				return me
 			except Exception as e:
 				fs = "Value {!r} cannot be converted to {} WIF key ({})"
-				return cls.init_fail(fs.format(wif,g.coin,e.message),on_fail)
+				return cls.init_fail(fs.format(wif,g.coin,e.args[0]),on_fail)
 
 		try:
 			assert s and type(compressed) == bool and pubkey_type,'Incorrect args for PrivKey()'
@@ -669,7 +669,7 @@ class PrivKey(str,Hilite,InitErrors,MMGenObject):
 			return me
 		except Exception as e:
 			fs = "Key={!r}\nCompressed={}\nValue pair cannot be converted to PrivKey\n({})"
-			return cls.init_fail(fs.format(s,compressed,e.message),on_fail)
+			return cls.init_fail(fs.format(s,compressed,e.args[0]),on_fail)
 
 
 class AddrListID(str,Hilite,InitErrors,MMGenObject):
@@ -687,7 +687,7 @@ class AddrListID(str,Hilite,InitErrors,MMGenObject):
 			me.mmtype = mmtype
 			return me
 		except Exception as e:
-			m = "Cannot create AddrListID ({})".format(e.message)
+			m = "Cannot create AddrListID ({})".format(e.args[0])
 			return cls.init_fail(m,on_fail)
 
 class MMGenLabel(str,Hilite,InitErrors):
@@ -722,7 +722,7 @@ class MMGenLabel(str,Hilite,InitErrors):
 			return str.__new__(cls,s)
 		except Exception as e:
 			m = "{!r}: value cannot be converted to {} ({})"
-			return cls.init_fail(m.format(s,cls.__name__,e.message),on_fail)
+			return cls.init_fail(m.format(s,cls.__name__,e.args[0]),on_fail)
 
 class MMGenWalletLabel(MMGenLabel):
 	max_len = 48
@@ -814,7 +814,7 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject):
 			raise ValueError('not found')
 		except Exception as e:
 			m = '{}{!r}: invalid value for {} ({})'.format(
-				('{!r}\n'.format(errmsg) if errmsg else ''),s,cls.__name__,e.message)
+				('{!r}\n'.format(errmsg) if errmsg else ''),s,cls.__name__,e.args[0])
 			return cls.init_fail(m,on_fail)
 
 	@classmethod

+ 1 - 1
mmgen/rpc.py

@@ -127,7 +127,7 @@ class CoinDaemonRPCConnection(object):
 			hc.request('POST','/',json.dumps(p,cls=MyJSONEncoder),http_hdr)
 		except Exception as e:
 			m = '{}\nUnable to connect to {} at {}:{}'
-			return do_fail(None,2,m.format(e.message,g.proto.daemon_name,self.host,self.port))
+			return do_fail(None,2,m.format(e.args[0],g.proto.daemon_name,self.host,self.port))
 
 		try:
 			r = hc.getresponse() # returns HTTPResponse instance

+ 2 - 2
mmgen/tool.py

@@ -648,9 +648,9 @@ def monero_wallet_ops(infile,op,blockheight=None,addrs=None):
 		rdie(2,'\nEnd of file\n')
 	except Exception as e:
 		try:
-			die(1,'Error: {}'.format(e.message))
+			die(1,'Error: {}'.format(e.args[0]))
 		except:
-			rdie(1,'Error: {!r}'.format(e.message))
+			rdie(1,'Error: {!r}'.format(e.args[0]))
 
 # ================ RPC commands ================== #
 

+ 1 - 1
mmgen/tw.py

@@ -562,7 +562,7 @@ class TrackingWallet(MMGenObject):
 			assert coinaddr,"{pn} address '{ma}' not found in tracking wallet"
 			assert self.is_in_wallet(coinaddr),"Address '{ca}' not found in tracking wallet"
 		except Exception as e:
-			msg(e.message.format(pn=g.proj_name,ma=mmaddr,ca=coinaddr))
+			msg(e.args[0].format(pn=g.proj_name,ma=mmaddr,ca=coinaddr))
 			return False
 
 		# Allow for the possibility that BTC addr of MMGen addr was entered.

+ 4 - 4
mmgen/tx.py

@@ -720,7 +720,7 @@ Selected non-{pnm} inputs: {{}}""".strip().format(pnm=g.proj_name,pnl=g.proj_nam
 					g.rpch.signrawtransaction(self.hex,sig_data,wifs,g.proto.sighash_type)
 		except Exception as e:
 			msg(yellow('This is not the BCH chain.\nRe-run the script without the --coin=bch option.'
-				if 'Invalid sighash param' in e.message else e.message))
+				if 'Invalid sighash param' in e.args[0] else e.args[0]))
 			return False
 
 		if not ret['complete']:
@@ -740,8 +740,8 @@ Selected non-{pnm} inputs: {{}}""".strip().format(pnm=g.proj_name,pnl=g.proj_nam
 			msg('OK')
 			return True
 		except Exception as e:
-			try: m = '{}'.format(e.message)
-			except: m = repr(e.message)
+			try: m = '{}'.format(e.args[0])
+			except: m = repr(e.args[0])
 			msg('\n'+yellow(m))
 			return False
 
@@ -1206,7 +1206,7 @@ Selected non-{pnm} inputs: {{}}""".strip().format(pnm=g.proj_name,pnl=g.proj_nam
 			desc = 'outputs data'
 			self.outputs = eval_io_data(outputs_data,'outputs')
 		except Exception as e:
-			die(2,'Invalid {} in transaction file: {}'.format(desc,e.message))
+			die(2,'Invalid {} in transaction file: {}'.format(desc,e.args[0]))
 
 		# test doesn't work for Ethereum: test and mainnet addrs have same format
 		if not self.chain and not self.inputs[0].addr.is_for_chain('testnet'):

+ 2 - 2
mmgen/util.py

@@ -864,7 +864,7 @@ def rpc_init_bitcoind():
 				assert conn.getblockhash(fork[0]) == fork[1], (
 					'Bad block hash at fork block {}. Is this the {} chain?'.format(fork[0],fork[2].upper()))
 		except Exception as e:
-			die(2,"{}\n'{c}' requested, but this is not the {c} chain!".format(e.message,c=g.coin))
+			die(2,"{}\n'{c}' requested, but this is not the {c} chain!".format(e.args[0],c=g.coin))
 
 	def check_chaintype_mismatch():
 		try:
@@ -872,7 +872,7 @@ def rpc_init_bitcoind():
 			if g.testnet: assert g.chain != 'mainnet','--testnet option selected, but chain is mainnet'
 			if not g.testnet: assert g.chain == 'mainnet','mainnet selected, but chain is not mainnet'
 		except Exception as e:
-			die(1,'{}\nChain is {}!'.format(e.message,g.chain))
+			die(1,'{}\nChain is {}!'.format(e.args[0],g.chain))
 
 	cfg = get_daemon_cfg_options(('rpcuser','rpcpassword'))
 

+ 1 - 1
test/gentest.py

@@ -273,7 +273,7 @@ else:
 			assert 1 <= b <= len(g.key_generators),'{}: invalid key generator'.format(b)
 		assert a != b,'Key generators are the same!'
 	except Exception as e:
-		die(1,'{}\n{}: invalid generator argument'.format(e.message,cmd_args[0]))
+		die(1,'{}\n{}: invalid generator argument'.format(e.args[0],cmd_args[0]))
 
 from mmgen.addr import KeyGenerator,AddrGenerator
 from mmgen.obj import PrivKey

+ 1 - 1
test/objtest.py

@@ -93,7 +93,7 @@ def run_test(test,arg,input_data):
 			msg('exitval: {}'.format(e.code))
 	except UserWarning as e:
 		msg('==> {!r}'.format(ret))
-		die(2,red('{}'.format(e.message)))
+		die(2,red('{}'.format(e.args[0])))
 
 r32,r24,r16,r17,r18 = os.urandom(32),os.urandom(24),os.urandom(16),os.urandom(17),os.urandom(18)
 tw_pfx = g.proto.base_coin.lower()+':'

+ 2 - 2
test/test.py

@@ -104,12 +104,12 @@ if not any(e in ('--skip-deps','--resume','-S','-r') for e in sys.argv+shortopts
 		try:
 			subprocess.call('rm -rf {}/{}*'.format(d,pfx),shell=True)
 		except Exception as e:
-			die(2,'Unable to delete directory tree {}/{}* ({})'.format(d,pfx,e.message))
+			die(2,'Unable to delete directory tree {}/{}* ({})'.format(d,pfx,e.args[0]))
 		try:
 			import tempfile
 			shm_dir = str(tempfile.mkdtemp('',pfx,d))
 		except Exception as e:
-			die(2,'Unable to create temporary directory in {} ({})'.format(d,e.message))
+			die(2,'Unable to create temporary directory in {} ({})'.format(d,e.args[0]))
 		for tdir in (data_dir,trash_dir):
 			dd = os.path.join(shm_dir,os.path.basename(tdir))
 			os.mkdir(dd,0o755)