From b80b0598156cee2c4846c0e0ea2f2ff958d2d64b Mon Sep 17 00:00:00 2001 From: MMGen Date: Wed, 7 Mar 2018 09:55:06 +0000 Subject: [PATCH] Use map() instead of list comprehension where possible --- mmgen/crypto.py | 2 +- mmgen/main.py | 2 +- mmgen/main_addrgen.py | 2 +- mmgen/main_passgen.py | 2 +- mmgen/obj.py | 4 ++-- mmgen/opts.py | 6 ++---- mmgen/protocol.py | 4 ++-- mmgen/seed.py | 8 ++++---- mmgen/tx.py | 4 ++-- scripts/test-release.sh | 1 - test/test.py | 20 ++++++++++---------- test/tooltest.py | 2 +- 12 files changed, 27 insertions(+), 30 deletions(-) diff --git a/mmgen/crypto.py b/mmgen/crypto.py index 2bcd9749..c1e6b9ab 100755 --- a/mmgen/crypto.py +++ b/mmgen/crypto.py @@ -145,7 +145,7 @@ def _get_random_data_from_user(uchars): if opt.quiet: msg_r('\r') else: msg_r("\rThank you. That's enough.{}\n\n".format(' '*18)) - fmt_time_data = ['{:.22f}'.format(i) for i in time_data] + fmt_time_data = map('{:.22f}'.format,time_data) dmsg('\nUser input:\n{}\nKeystroke time intervals:\n{}\n'.format(key_data,'\n'.join(fmt_time_data))) prompt = 'User random data successfully acquired. Press ENTER to continue' prompt_and_get_char(prompt,'',enter_ok=True) diff --git a/mmgen/main.py b/mmgen/main.py index ad694685..2390469c 100755 --- a/mmgen/main.py +++ b/mmgen/main.py @@ -30,7 +30,7 @@ def launch(what): sys.exit(2) import sys - sys.argv = [my_dec(a) for a in sys.argv] + sys.argv = map(my_dec,sys.argv) if what in ('walletgen','walletchk','walletconv','passchg'): what = 'wallet' diff --git a/mmgen/main_addrgen.py b/mmgen/main_addrgen.py index 7048f5e7..af045626 100755 --- a/mmgen/main_addrgen.py +++ b/mmgen/main_addrgen.py @@ -77,7 +77,7 @@ opts_data = lambda: { -v, --verbose Produce more verbose output -x, --b16 Print secret keys in hexadecimal too """.format( - seed_lens=', '.join([str(i) for i in g.seed_lens]), + seed_lens=', '.join(map(str,g.seed_lens)), pnm=g.proj_name, kgs=' '.join(['{}:{}'.format(n,k) for n,k in enumerate(g.key_generators,1)]), kg=g.key_generator, diff --git a/mmgen/main_passgen.py b/mmgen/main_passgen.py index 1e1594e0..6ee85627 100755 --- a/mmgen/main_passgen.py +++ b/mmgen/main_passgen.py @@ -66,7 +66,7 @@ opts_data = lambda: { -S, --stdout Print passwords to stdout -v, --verbose Produce more verbose output """.format( - seed_lens=', '.join([str(i) for i in g.seed_lens]), + seed_lens=', '.join(map(str,g.seed_lens)), g=g,pnm=g.proj_name,d58=dfl_len['b58'],d32=dfl_len['b32'],dhex=dfl_len['hex'], kgs=' '.join(['{}:{}'.format(n,k) for n,k in enumerate(g.key_generators,1)]) ), diff --git a/mmgen/obj.py b/mmgen/obj.py index 84fada25..c3ca0a30 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -667,12 +667,12 @@ class MMGenLabel(unicode,Hilite,InitErrors): class MMGenWalletLabel(MMGenLabel): max_len = 48 - allowed = [unichr(i+32) for i in range(95)] + allowed = map(unichr,range(32,127)) desc = 'wallet label' class TwComment(MMGenLabel): max_len = 32 - allowed = [unichr(i+32) for i in range(95)] + allowed = map(unichr,range(32,127)) desc = 'tracking wallet comment' class MMGenTXLabel(MMGenLabel): diff --git a/mmgen/opts.py b/mmgen/opts.py index 9f3a8785..62954003 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -379,10 +379,8 @@ def check_opts(usr_opts): # Returns false if any check fails def opt_is_in_list(val,lst,desc): if val not in lst: q,sep = (('',','),("'","','"))[type(lst[0]) == str] - msg('{q}{v}{q}: invalid {w}\nValid choices: {q}{o}{q}'.format( - v=val,w=desc,q=q, - o=sep.join([str(i) for i in sorted(lst)]) - )) + fs = '{q}{v}{q}: invalid {w}\nValid choices: {q}{o}{q}' + msg(fs.format(v=val,w=desc,q=q,o=sep.join(map(str,sorted(lst))))) return False return True diff --git a/mmgen/protocol.py b/mmgen/protocol.py index 2d052e5e..6da49aba 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -137,7 +137,7 @@ class BitcoinProtocol(MMGenObject): msg('{}: Invalid witness version number'.format(ret[0])) elif ret[1]: return { - 'hex': ''.join([chr(b) for b in ret[1]]).encode('hex'), + 'hex': ''.join(map(chr,ret[1])).encode('hex'), 'format': 'bech32' } if return_dict else True return False @@ -187,7 +187,7 @@ class BitcoinProtocol(MMGenObject): @classmethod def pubhash2bech32addr(cls,pubhash): - d = [ord(b) for b in pubhash.decode('hex')] + d = map(ord,pubhash.decode('hex')) return bech32.bech32_encode(cls.bech32_hrp,[cls.witness_vernum]+bech32.convertbits(d,8,5)) class BitcoinTestnetProtocol(BitcoinProtocol): diff --git a/mmgen/seed.py b/mmgen/seed.py index 175d8ab4..d1879022 100755 --- a/mmgen/seed.py +++ b/mmgen/seed.py @@ -199,7 +199,7 @@ class SeedSource(MMGenObject): d = [(c.__name__,('.'+c.ext if c.ext else c.ext),','.join(c.fmt_codes)) for c in cls.get_subclasses() if hasattr(c,'fmt_codes')] - w = max([len(a) for a,b,c in d]) + w = max(len(i[0]) for i in d) ret = ['{:<{w}} {:<9} {}'.format(a,b,c,w=w) for a,b,c in [ ('Format','FileExt','Valid codes'), ('------','-------','-----------') @@ -443,8 +443,8 @@ class Mnemonic (SeedSourceUnenc): mn = self.fmt_data.split() if len(mn) not in self.mn_lens: - msg('Invalid mnemonic (%i words). Allowed numbers of words: %s' % - (len(mn),', '.join([str(i) for i in self.mn_lens]))) + msg('Invalid mnemonic ({} words). Valid numbers of words: {}'.format( + (len(mn),', '.join(map(str,self.mn_lens))))) return False for n,w in enumerate(mn,1): @@ -680,7 +680,7 @@ class Wallet (SeedSourceEnc): if uhp != hp: qmsg("Warning: ignoring user-requested hash preset '%s'" % uhp) - hash_params = [int(i) for i in hpdata[1:]] + hash_params = map(int,hpdata[1:]) if hash_params != get_hash_params(d.hash_preset): msg("Hash parameters '%s' don't match hash preset '%s'" % diff --git a/mmgen/tx.py b/mmgen/tx.py index d0c1b2ff..79a0264e 100755 --- a/mmgen/tx.py +++ b/mmgen/tx.py @@ -528,7 +528,7 @@ class MMGenTX(MMGenObject): def decode_io_oldfmt(self,data): tr = {'amount':'amt', 'address':'addr', 'confirmations':'confs','comment':'label'} - tr_rev = dict([(v,k) for k,v in tr.items()]) + tr_rev = dict(map(reversed,tr.items())) copy_keys = [tr_rev[k] if k in tr_rev else k for k in self.MMGenTxInput.__dict__] ret = MMGenList(self.MMGenTxInput(**dict([(tr[k] if k in tr else k,d[k]) for k in copy_keys if k in d and d[k] != ''])) for d in data) @@ -1152,7 +1152,7 @@ class MMGenTX(MMGenObject): while True: m = 'Enter a range or space-separated list of outputs to spend: ' sel_nums = select_unspent(tw.unspent,m) - msg('Selected output%s: %s' % (suf(sel_nums,'s'),' '.join(str(i) for i in sel_nums))) + msg('Selected output{}: {}'.format(suf(sel_nums,'s'),' '.join(map(str,sel_nums)))) sel_unspent = tw.MMGenTwOutputList([tw.unspent[i-1] for i in sel_nums]) diff --git a/scripts/test-release.sh b/scripts/test-release.sh index 49a6a825..487e5812 100755 --- a/scripts/test-release.sh +++ b/scripts/test-release.sh @@ -361,7 +361,6 @@ tests=$dfl_tests [ "$NO_PAUSE" ] || PAUSE=1 check_args - echo "Running tests: $tests" run_tests "$tests" rm -rf /tmp/mmgen-test-release-* diff --git a/test/test.py b/test/test.py index 9beb246a..0185d5af 100755 --- a/test/test.py +++ b/test/test.py @@ -53,10 +53,10 @@ ref_wallet_incog_offset = 123 from mmgen.obj import MMGenTXLabel,PrivKey from mmgen.addr import AddrGenerator,KeyGenerator,AddrList,AddrData,AddrIdxList -ref_tx_label = ''.join([unichr(i) for i in range(65,91) + - range(1040,1072) + # cyrillic - range(913,939) + # greek - range(97,123)])[:MMGenTXLabel.max_len] +ref_tx_label = ''.join(map(unichr, range(65,91) + + range(1040,1072) + # cyrillic + range(913,939) + # greek + range(97,123)))[:MMGenTXLabel.max_len] ref_bw_hash_preset = '1' ref_bw_file = 'wallet.mmbrain' ref_bw_file_spc = 'wallet-spaced.mmbrain' @@ -990,7 +990,7 @@ if opt.list_cmds: fs = ' {:<{w}} - {}' Msg(green('AVAILABLE COMMANDS:')) - w = max([len(i) for i in cmd_data]) + w = max(map(len,cmd_data)) for cmd in cmd_data: if cmd[:5] == 'info_': m = capfirst(cmd_data[cmd][0]) @@ -999,7 +999,7 @@ if opt.list_cmds: Msg(' '+fs.format(cmd,cmd_data[cmd][1],w=w)) for cl,lbl in ((meta_cmds,'METACOMMANDS'),(cmd_list,'COMMAND GROUPS')): - w = max([len(i) for i in cl]) + w = max(map(len,cl)) Msg('\n'+green('AVAILABLE {}:'.format(lbl))) for cmd in cl: ft = format_par(' '.join(cl[cmd]),width=tw,indent=4,as_list=True) @@ -1007,7 +1007,7 @@ if opt.list_cmds: Msg(' {}{}{}'.format(yellow(cmd+':'),sep,'\n'.join(ft).lstrip())) Msg('\n'+green('AVAILABLE UTILITIES:')) - w = max([len(i) for i in utils]) + w = max(map(len,utils)) for cmd in sorted(utils): Msg(fs.format(cmd,utils[cmd],w=w)) @@ -1320,7 +1320,7 @@ def check_deps(cmds): check_needs_rerun(ts,cmd,build=False) - w = max(len(i) for i in rebuild_list) + 1 + w = max(map(len,rebuild_list)) + 1 for cmd in rebuild_list: c = rebuild_list[cmd] m = 'Rebuild' if (c[0] and c[1]) else 'Build' if c[0] else 'OK' @@ -2629,8 +2629,8 @@ class MMGenTestSuite(object): def regtest_bob_split2(self,name): addrs = read_from_tmpfile(cfg,'non-mmgen.addrs').split() - amts = (a for a in (1.12345678,2.87654321,3.33443344,4.00990099,5.43214321)) - outputs1 = ['{},{}'.format(a,amts.next()) for a in addrs] + amts = (1.12345678,2.87654321,3.33443344,4.00990099,5.43214321) + outputs1 = map('{},{}'.format,addrs,amts) sid = self.regtest_user_sid('bob') l1,l2 = (':S',':B') if 'B' in g.proto.mmtypes else (':S',':S') if g.proto.cap('segwit') else (':L',':L') outputs2 = [sid+':C:2,6.333', sid+':L:3,6.667',sid+l1+':4,0.123',sid+l2+':5'] diff --git a/test/tooltest.py b/test/tooltest.py index a52b9d82..1026a98b 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -175,7 +175,7 @@ add_spawn_args = ['--data-dir='+cfg['tmpdir']] + ['--{}{}'.format( if opt.list_cmds: fs = ' {:<{w}} - {}' Msg('Available commands:') - w = max([len(i) for i in cmd_data]) + w = max(map(len,cmd_data)) for cmd in cmd_data: Msg(fs.format(cmd,cmd_data[cmd]['desc'],w=w)) Msg('\nAvailable utilities:')