From f626fc2e050b499081a32031978031a298ea094e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 3 Oct 2023 14:27:57 +0000 Subject: [PATCH] missing import fixes throughout --- mmgen/cfgfile.py | 2 +- mmgen/crypto.py | 1 + mmgen/main_msg.py | 2 +- mmgen/main_txsign.py | 2 +- mmgen/proto/btc/tx/completed.py | 2 +- mmgen/proto/btc/tx/new.py | 2 +- mmgen/proto/btc/tx/online.py | 2 +- mmgen/proto/btc/tx/unsigned.py | 2 +- mmgen/proto/eth/contract.py | 2 +- mmgen/proto/eth/tx/new.py | 2 +- mmgen/proto/eth/tx/online.py | 2 +- mmgen/seed.py | 2 +- mmgen/seedsplit.py | 3 ++- mmgen/tool/filecrypt.py | 1 + mmgen/tool/mnemonic.py | 1 + mmgen/tw/bal.py | 2 +- mmgen/tx/__init__.py | 2 +- mmgen/tx/bump.py | 2 +- mmgen/util2.py | 6 +++--- mmgen/wallet/incog_base.py | 2 +- scripts/create-token.py | 2 +- scripts/uninstall-mmgen.py | 2 +- test/gentest.py | 2 +- test/objtest.py | 4 ++-- test/scrambletest.py | 2 +- test/test.py | 8 ++++++-- test/test_py_d/common.py | 2 +- test/tooltest.py | 5 +++-- test/tooltest2.py | 2 +- test/unit_tests.py | 2 +- 30 files changed, 41 insertions(+), 32 deletions(-) diff --git a/mmgen/cfgfile.py b/mmgen/cfgfile.py index 9c97c3b8..4a0056d2 100755 --- a/mmgen/cfgfile.py +++ b/mmgen/cfgfile.py @@ -24,7 +24,7 @@ import os,re from collections import namedtuple from .cfg import gc -from .util import msg,ymsg,suf,fmt,fmt_list,oneshot_warning,strip_comment,capfirst +from .util import msg,ymsg,suf,fmt,fmt_list,oneshot_warning,strip_comment,capfirst,die def mmgen_cfg_file(cfg,id_str): return cfg_file.get_cls_by_id(id_str)(cfg) diff --git a/mmgen/crypto.py b/mmgen/crypto.py index 3341db5f..46310627 100755 --- a/mmgen/crypto.py +++ b/mmgen/crypto.py @@ -27,6 +27,7 @@ from .cfg import gc from .util import ( msg, msg_r, + ymsg, fmt, die, make_chksum_8, diff --git a/mmgen/main_msg.py b/mmgen/main_msg.py index 785b281a..866c12b3 100755 --- a/mmgen/main_msg.py +++ b/mmgen/main_msg.py @@ -16,7 +16,7 @@ import sys import mmgen.opts as opts from .cfg import Config from .base_obj import AsyncInit -from .util import msg,suf,async_run +from .util import msg,suf,async_run,die from .msg import ( NewMsg, CompletedMsg, diff --git a/mmgen/main_txsign.py b/mmgen/main_txsign.py index 065256bb..bd0d3a74 100755 --- a/mmgen/main_txsign.py +++ b/mmgen/main_txsign.py @@ -22,7 +22,7 @@ mmgen-txsign: Sign a transaction generated by 'mmgen-txcreate' import mmgen.opts as opts from .cfg import gc,Config -from .util import msg,ymsg,die,async_run +from .util import msg,ymsg,suf,die,async_run from .subseed import SubSeedIdxRange from .wallet import Wallet from .color import orange diff --git a/mmgen/proto/btc/tx/completed.py b/mmgen/proto/btc/tx/completed.py index 80a4e93d..2f43fe6b 100755 --- a/mmgen/proto/btc/tx/completed.py +++ b/mmgen/proto/btc/tx/completed.py @@ -15,7 +15,7 @@ proto.btc.tx.completed: Bitcoin completed transaction class import mmgen.tx.completed as TxBase from .base import Base,scriptPubKey2addr from ....obj import HexStr -from ....util import msg +from ....util import msg,die class Completed(Base,TxBase.Completed): fn_fee_unit = 'satoshi' diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index cf63d267..cb6e059c 100755 --- a/mmgen/proto/btc/tx/new.py +++ b/mmgen/proto/btc/tx/new.py @@ -15,7 +15,7 @@ proto.btc.tx.new: Bitcoin new transaction class import mmgen.tx.new as TxBase from .base import Base from ....obj import HexStr,MMGenTxID -from ....util import msg,make_chksum_6,die +from ....util import msg,fmt,make_chksum_6,die class New(Base,TxBase.New): usr_fee_prompt = 'Enter transaction fee: ' diff --git a/mmgen/proto/btc/tx/online.py b/mmgen/proto/btc/tx/online.py index cab6fceb..41d79acd 100755 --- a/mmgen/proto/btc/tx/online.py +++ b/mmgen/proto/btc/tx/online.py @@ -14,7 +14,7 @@ proto.btc.tx.online: Bitcoin online signed transaction class import mmgen.tx.online as TxBase from .signed import Signed -from ....util import msg,ymsg,rmsg +from ....util import msg,ymsg,rmsg,die class OnlineSigned(Signed,TxBase.OnlineSigned): diff --git a/mmgen/proto/btc/tx/unsigned.py b/mmgen/proto/btc/tx/unsigned.py index f9a50bf8..e8a41f23 100755 --- a/mmgen/proto/btc/tx/unsigned.py +++ b/mmgen/proto/btc/tx/unsigned.py @@ -15,7 +15,7 @@ proto.btc.tx.unsigned: Bitcoin unsigned transaction class import mmgen.tx.unsigned as TxBase from .completed import Completed from ....obj import HexStr,CoinTxID,MMGenDict -from ....util import msg,msg_r,ymsg,suf +from ....util import msg,msg_r,ymsg,suf,die class Unsigned(Completed,TxBase.Unsigned): desc = 'unsigned transaction' diff --git a/mmgen/proto/eth/contract.py b/mmgen/proto/eth/contract.py index e77d56b0..5a68c09f 100755 --- a/mmgen/proto/eth/contract.py +++ b/mmgen/proto/eth/contract.py @@ -24,7 +24,7 @@ from decimal import Decimal from . import rlp from . import erigon_sleep -from ...util import msg,pp_msg +from ...util import msg,pp_msg,die from ...base_obj import AsyncInit from ...obj import MMGenObject,CoinTxID from ...addr import CoinAddr,TokenAddr diff --git a/mmgen/proto/eth/tx/new.py b/mmgen/proto/eth/tx/new.py index dcdd5c35..1b71de2c 100755 --- a/mmgen/proto/eth/tx/new.py +++ b/mmgen/proto/eth/tx/new.py @@ -17,7 +17,7 @@ import json import mmgen.tx.new as TxBase from .base import Base,TokenBase from ....obj import Int,ETHNonce,MMGenTxID,Str,HexStr -from ....util import msg,is_int,is_hex_str,make_chksum_6 +from ....util import msg,is_int,is_hex_str,make_chksum_6,suf,die from ....tw.ctl import TwCtl from ....addr import is_mmgen_id,is_coin_addr from ..contract import Token diff --git a/mmgen/proto/eth/tx/online.py b/mmgen/proto/eth/tx/online.py index 3d6bfc2b..386c2f95 100755 --- a/mmgen/proto/eth/tx/online.py +++ b/mmgen/proto/eth/tx/online.py @@ -15,7 +15,7 @@ proto.eth.tx.online: Ethereum online signed transaction class import mmgen.tx.online as TxBase from .signed import Signed,TokenSigned from .. import erigon_sleep -from ....util import msg,rmsg +from ....util import msg,rmsg,die class OnlineSigned(Signed,TxBase.OnlineSigned): diff --git a/mmgen/seed.py b/mmgen/seed.py index 1d51a705..a71c0d2f 100755 --- a/mmgen/seed.py +++ b/mmgen/seed.py @@ -20,7 +20,7 @@ seed: Seed-related classes and methods for the MMGen suite """ -from .util import make_chksum_8,hexdigits_uc +from .util import make_chksum_8,hexdigits_uc,die from .objmethods import Hilite,InitErrors,MMGenObject from .obj import ImmutableAttr,get_obj diff --git a/mmgen/seedsplit.py b/mmgen/seedsplit.py index d0fffb0c..4f285f5f 100755 --- a/mmgen/seedsplit.py +++ b/mmgen/seedsplit.py @@ -21,7 +21,8 @@ seedsplit: Seed split classes and methods for the MMGen suite """ from .color import yellow -from .obj import MMGenPWIDString,MMGenIdx +from .util import msg,die +from .obj import MMGenPWIDString,MMGenIdx,get_obj from .subseed import * from .crypto import Crypto diff --git a/mmgen/tool/filecrypt.py b/mmgen/tool/filecrypt.py index f38bf7b8..5edc6b99 100755 --- a/mmgen/tool/filecrypt.py +++ b/mmgen/tool/filecrypt.py @@ -51,6 +51,7 @@ class tool_cmd(tool_cmd_base): dec_d = Crypto(self.cfg).mmgen_decrypt( enc_d, 'data', hash_preset ) if dec_d: break + from ..util import msg msg('Trying again...') if not outfile: from ..util import remove_extension diff --git a/mmgen/tool/mnemonic.py b/mmgen/tool/mnemonic.py index ce9e4b18..ee137f59 100755 --- a/mmgen/tool/mnemonic.py +++ b/mmgen/tool/mnemonic.py @@ -64,6 +64,7 @@ class tool_cmd(tool_cmd_base): from ..protocol import init_proto proto = init_proto( self.cfg, 'xmr' ) if len(bytestr) != proto.privkey_len: + from ..util import die die(1,'{!r}: invalid bit length for Monero private key (must be {})'.format( len(bytestr*8), proto.privkey_len*8 )) diff --git a/mmgen/tw/bal.py b/mmgen/tw/bal.py index 7810828f..ea30f8ad 100755 --- a/mmgen/tw/bal.py +++ b/mmgen/tw/bal.py @@ -69,7 +69,7 @@ class TwGetBalance(MMGenObject,metaclass=AsyncInit): return len(str(int(max(v[colname] for v in self.data.values())))) + iwidth_adj def make_col(label,col): - return(self.data[label][col].fmt(iwidth=iwidths[col],color=color)) + return self.data[label][col].fmt( iwidth=iwidths[col], color=color ) if color: from ..color import red,green,yellow diff --git a/mmgen/tx/__init__.py b/mmgen/tx/__init__.py index 73001247..f2c89e80 100755 --- a/mmgen/tx/__init__.py +++ b/mmgen/tx/__init__.py @@ -41,7 +41,7 @@ def _get_cls_info(clsname,modname,args,kwargs): f"{clsname} must be instantiated with 'proto','data' or 'filename' keyword" ) if clsname == 'Completed': - from ..util import get_extension + from ..util import get_extension,die from .completed import Completed ext = get_extension( kwargs['filename'] ) cls = Completed.ext_to_cls( ext, proto ) diff --git a/mmgen/tx/bump.py b/mmgen/tx/bump.py index 2d0d6030..c58a91d0 100755 --- a/mmgen/tx/bump.py +++ b/mmgen/tx/bump.py @@ -14,7 +14,7 @@ tx.bump: transaction bump class from .new import New from .completed import Completed -from ..util import is_int +from ..util import msg,is_int,die class Bump(Completed,New): desc = 'fee-bumped transaction' diff --git a/mmgen/util2.py b/mmgen/util2.py index 4d45ddb9..d51dfb9f 100755 --- a/mmgen/util2.py +++ b/mmgen/util2.py @@ -13,7 +13,7 @@ util2: Less frequently-used variables, classes and utility functions for the MMG """ import re,time -from .util import msg,suf,hexdigits +from .util import msg,suf,hexdigits,die def die_wait(delay,ev=0,s=''): assert isinstance(delay,int) @@ -80,7 +80,7 @@ def int2bytespec(n,spec,fmt,print_sym=True,strip=False,add_space=False): if k == spec: return v else: - die('{spec}: unrecognized bytespec') + die(1,f'{spec!r}: unrecognized bytespec') if strip: ret = '{:{}f}'.format(n/spec2int(spec),fmt).rstrip('0') @@ -120,7 +120,7 @@ def format_elapsed_hr(t,now=None,cached={}): def pretty_format(s,width=80,pfx=''): out = [] - while(s): + while s: if len(s) <= width: out.append(s) break diff --git a/mmgen/wallet/incog_base.py b/mmgen/wallet/incog_base.py index 857cfa13..3cc456cc 100755 --- a/mmgen/wallet/incog_base.py +++ b/mmgen/wallet/incog_base.py @@ -13,7 +13,7 @@ wallet.incog_base: incognito wallet base class """ from ..seed import Seed -from ..util import msg,make_chksum_8 +from ..util import msg,make_chksum_8,die from .enc import wallet class wallet(wallet): diff --git a/scripts/create-token.py b/scripts/create-token.py index ae9969c4..8c5ca1ea 100755 --- a/scripts/create-token.py +++ b/scripts/create-token.py @@ -197,7 +197,7 @@ def create_src(cfg,template,token_data): if not field.test(val): die(1,f'{val!r}: invalid parameter for option --{k}') - yield(k,field.conversion(val)) + yield (k, field.conversion(val)) from string import Template return Template(template).substitute(**dict(gen())) diff --git a/scripts/uninstall-mmgen.py b/scripts/uninstall-mmgen.py index 820f682e..97338f48 100755 --- a/scripts/uninstall-mmgen.py +++ b/scripts/uninstall-mmgen.py @@ -29,7 +29,7 @@ curdir = normalize_path(os.curdir) for n in reversed(range(len(sys.path))): if normalize_path(sys.path[n]) == curdir: - del(sys.path[n]) + del sys.path[n] try: import mmgen.main diff --git a/test/gentest.py b/test/gentest.py index 0f5d4b6f..65b50d12 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -28,7 +28,7 @@ import include.test_init import mmgen.opts as opts from mmgen.cfg import gc,Config from mmgen.color import green,red,purple -from mmgen.util import msg,capfirst,is_int,die +from mmgen.util import msg,ymsg,capfirst,is_int,die results_file = 'gentest.out.json' diff --git a/test/objtest.py b/test/objtest.py index caa6db72..409dc2aa 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -31,8 +31,8 @@ if not os.getenv('MMGEN_DEVTOOLS'): init_dev() from mmgen.cfg import Config -from mmgen.util import msg,msg_r,gmsg,capfirst -from mmgen.color import yellow,blue,green,orange,purple,gray,nocolor +from mmgen.util import msg,msg_r,gmsg,capfirst,die +from mmgen.color import red,yellow,blue,green,orange,purple,gray,nocolor from mmgen.obj import get_obj opts_data = { diff --git a/test/scrambletest.py b/test/scrambletest.py index 0668f196..381443bf 100755 --- a/test/scrambletest.py +++ b/test/scrambletest.py @@ -28,7 +28,7 @@ import include.test_init import mmgen.opts as opts from mmgen.cfg import gc,Config -from mmgen.util import msg,msg_r,bmsg +from mmgen.util import msg,msg_r,bmsg,die opts_data = { 'text': { diff --git a/test/test.py b/test/test.py index 5d1d562e..7eb49199 100755 --- a/test/test.py +++ b/test/test.py @@ -89,7 +89,7 @@ else: repo_root = include.test_init.repo_root from mmgen.cfg import Config,gc -from mmgen.color import red,yellow,green,blue,cyan,nocolor +from mmgen.color import red,yellow,green,blue,cyan,nocolor,init_color from mmgen.util import Msg,bmsg,die,suf,make_timestr,async_run from test.include.common import ( @@ -104,6 +104,7 @@ from test.include.common import ( ok, start_test_daemons, stop_test_daemons, + init_coverage, ) try: @@ -198,7 +199,10 @@ cfg = Config(opts_data=opts_data) set_globals(cfg) -from test.test_py_d.common import get_file_with_ext # this must be loaded after set_globals() +from test.test_py_d.common import ( # this must be loaded after set_globals() + get_file_with_ext, + confirm_continue +) type(cfg)._reset_ok += ( 'no_daemon_autostart', diff --git a/test/test_py_d/common.py b/test/test_py_d/common.py index 6d348750..9e3ecdfb 100755 --- a/test/test_py_d/common.py +++ b/test/test_py_d/common.py @@ -23,7 +23,7 @@ test.test_py_d.common: Shared routines and data for the test.py test suite import sys,os from mmgen.cfg import gc -from mmgen.color import green +from mmgen.color import green,blue from mmgen.util import msg from ..include.common import cfg,getrand,text_jp,text_zh,ascii_cyr_gr,lat_cyr_gr diff --git a/test/tooltest.py b/test/tooltest.py index 8b580514..69ac5c83 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -26,7 +26,7 @@ from subprocess import run,PIPE import include.test_init from mmgen.cfg import Config,gc -from mmgen.color import green,cyan,yellow,blue +from mmgen.color import red,yellow,green,blue,cyan from mmgen.util import msg,msg_r,Msg,die opts_data = { @@ -65,7 +65,8 @@ from test.include.common import ( cmp_or_die, getrand, getrandhex, - end_msg + end_msg, + init_coverage ) set_globals(cfg) diff --git a/test/tooltest2.py b/test/tooltest2.py index 41ad6a4b..6abcecbd 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -29,7 +29,7 @@ from decimal import Decimal import include.test_init -from test.include.common import set_globals,end_msg,sample_text +from test.include.common import set_globals,end_msg,sample_text,init_coverage from mmgen.cfg import Config,gc from mmgen.color import green,blue,purple,cyan diff --git a/test/unit_tests.py b/test/unit_tests.py index 1cda163c..e9b76ce8 100755 --- a/test/unit_tests.py +++ b/test/unit_tests.py @@ -31,7 +31,7 @@ if not os.getenv('MMGEN_DEVTOOLS'): init_dev() from mmgen.cfg import Config,gc -from mmgen.color import gray +from mmgen.color import green,gray from mmgen.util import msg,gmsg,ymsg,Msg,die,async_run from test.include.common import set_globals,end_msg