Browse Source

delete mmgen/common.py; import fixes and cleanups throughout (deglob)

The MMGen Project 1 year ago
parent
commit
e99950373a

+ 0 - 26
mmgen/common.py

@@ -1,26 +0,0 @@
-#!/usr/bin/env python3
-#
-# mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
-# Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-"""
-common: Common imports for all MMGen scripts
-"""
-
-import sys,os
-from .cfg import *
-import mmgen.opts as opts
-from .util import *

+ 2 - 0
mmgen/main_addrgen.py

@@ -22,6 +22,7 @@ mmgen-addrgen: Generate a series or range of addresses from an MMGen
 """
 
 import mmgen.opts as opts
+
 from .cfg import gc,Config
 from .addr import MMGenAddrType
 from .addrfile import AddrFile
@@ -172,6 +173,7 @@ af = al.file
 af.format()
 
 if al.gen_addrs and cfg.print_checksum:
+	from .util import Die
 	Die(0,al.checksum)
 
 from .ui import keypress_confirm

+ 1 - 1
mmgen/main_txsign.py

@@ -114,7 +114,7 @@ if not cfg.info and not cfg.terse_info:
 	from .ui import do_license_msg
 	do_license_msg(cfg,immed=True)
 
-from .tx.sign import *
+from .tx.sign import txsign,get_tx_files,get_seed_files,get_keylist,get_keyaddrlist
 
 tx_files   = get_tx_files(cfg,infiles)
 seed_files = get_seed_files(cfg,infiles)

+ 0 - 1
mmgen/mn_entry.py

@@ -22,7 +22,6 @@ mn_entry.py - Mnemonic user entry methods for the MMGen suite
 
 import time
 
-from .cfg import *
 from .util import msg,msg_r,fmt,fmt_list,capfirst,die,ascii_lowercase
 from .term import get_char,get_char_raw
 from .color import cyan

+ 1 - 1
mmgen/obj.py

@@ -22,7 +22,7 @@ obj: MMGen native classes
 
 import sys,os,re,unicodedata
 
-from .objmethods import *
+from .objmethods import MMGenObject,Hilite,InitErrors
 
 def get_obj(objname,*args,**kwargs):
 	"""

+ 4 - 2
mmgen/seedsplit.py

@@ -22,8 +22,10 @@ seedsplit: Seed split classes and methods for the MMGen suite
 
 from .color import yellow
 from .util import msg,die
-from .obj import MMGenPWIDString,MMGenIdx,get_obj
-from .subseed import *
+from .objmethods import MMGenObject,Hilite,InitErrors
+from .obj import ImmutableAttr,MMGenPWIDString,MMGenIdx,get_obj,IndexedDict
+from .seed import Seed,SeedBase
+from .subseed import SubSeedList,SubSeedIdx,SubSeed
 from .crypto import Crypto
 
 class SeedShareIdx(MMGenIdx):

+ 4 - 3
mmgen/subseed.py

@@ -21,9 +21,10 @@ subseed: Subseed classes and methods for the MMGen suite
 """
 
 from .color import green
-from .util import msg_r,msg,die
-from .obj import MMGenRange,IndexedDict
-from .seed import *
+from .util import msg_r,msg,die,make_chksum_8
+from .objmethods import MMGenObject,Hilite,InitErrors
+from .obj import MMGenRange,IndexedDict,ImmutableAttr
+from .seed import SeedBase,SeedID
 
 class SubSeedIdxRange(MMGenRange):
 	min_idx = 1

+ 1 - 1
mmgen/util.py

@@ -22,7 +22,7 @@ util: Frequently-used variables, classes and utility functions for the MMGen sui
 
 import sys,os,time,re
 
-from .color import *
+from .color import red,yellow,green,blue,purple
 from .cfg import gv,gc
 
 ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

+ 3 - 1
test/colortest.py

@@ -7,8 +7,10 @@
 test/colortest.py: test color handling for the MMGen suite
 """
 
+import os
+
 import include.test_init
-from include.common import *
+
 from mmgen.color import *
 from mmgen.util import msg,ymsg,gmsg
 import mmgen.color as color_mod

+ 2 - 1
test/gentest.py

@@ -541,7 +541,8 @@ def main():
 from subprocess import run,PIPE,DEVNULL
 from collections import namedtuple
 from mmgen.protocol import init_proto,CoinProtocol
-from mmgen.altcoin import init_genonly_altcoins,CoinInfo as cinfo
+from mmgen.altcoin import init_genonly_altcoins
+from mmgen.altcoin import CoinInfo as cinfo
 from mmgen.key import PrivKey
 from mmgen.addr import MMGenAddrType
 from mmgen.addrgen import KeyGenerator,AddrGenerator

+ 2 - 1
test/include/pexpect.py

@@ -21,7 +21,8 @@ test.include.pexpect: pexpect implementation for MMGen test suites
 """
 
 import sys,os,time
-from mmgen.util import msg,msg_r,rmsg,red,yellow,green,cyan,die
+from mmgen.color import red,yellow,green,cyan
+from mmgen.util import msg,msg_r,rmsg,die
 from .common import cfg,vmsg,vmsg_r,getrandstr,strip_ansi_escapes
 
 try:

+ 3 - 1
test/test_py_d/cfg.py

@@ -12,7 +12,9 @@
 test.test_py_d.cfg: configuration data for test.py
 """
 
-from .common import *
+import os
+
+from .common import pwfile,hincog_fn,incog_id_fn,randbool
 from ..include.common import cfg
 
 cmd_groups_dfl = {

+ 15 - 6
test/test_py_d/ts_autosign.py

@@ -26,13 +26,22 @@ from pathlib import Path
 
 from mmgen.cfg import gc
 from mmgen.color import red,green,blue,purple
-from mmgen.util import suf
+from mmgen.util import msg,suf,die
+
+from ..include.common import (
+	cfg,
+	omsg,
+	omsg_r,
+	start_test_daemons,
+	stop_test_daemons,
+	joinpath,
+	imsg,
+	read_from_file
+)
+from .common import ref_dir,dfl_words_file,dfl_bip39_file
 
-from ..include.common import *
-from .common import *
-from .ts_base import *
-from .ts_shared import *
-from .input import *
+from .ts_base import TestSuiteBase
+from .input import stealth_mnemonic_entry
 
 from mmgen.led import LEDControl
 from mmgen.autosign import Autosign,AutosignConfig

+ 5 - 2
test/test_py_d/ts_base.py

@@ -21,9 +21,12 @@ test.test_py_d.ts_base: Base class for the test.py test suite
 """
 
 import os
+
 from mmgen.cfg import gc
-from ..include.common import *
-from .common import *
+from mmgen.util import msg
+
+from ..include.common import cfg,write_to_file,read_from_file
+from .common import get_file_with_ext
 
 class TestSuiteBase:
 	'initializer class for the test.py test suite'

+ 5 - 4
test/test_py_d/ts_cfgfile.py

@@ -10,13 +10,14 @@
 test.test_py_d.ts_cfgfile: CfgFile tests for the MMGen test.py test suite
 """
 
-import time,shutil
+import os,time,shutil
 
-from ..include.common import *
-from .ts_base import *
+from ..include.common import cfg,read_from_file,write_to_file,imsg
+from .ts_base import TestSuiteBase
 
-from mmgen.cfgfile import *
+from mmgen.cfg import gc
 from mmgen.color import yellow
+from mmgen.cfgfile import CfgFileSampleSys,CfgFileSampleUsr,cfg_file_sample
 
 class TestSuiteCfgFile(TestSuiteBase):
 	'CfgFile API'

+ 4 - 5
test/test_py_d/ts_chainsplit.py

@@ -20,14 +20,13 @@
 test.test_py_d.ts_chainsplit: Forking scenario tests for the test.py test suite
 This module is unmaintained and currently non-functional
 """
+
 import os
+
 from mmgen.util import die
-from ..include.common import *
-from .common import *
 
-from .ts_base import *
-from .ts_shared import *
-from .ts_regtest import *
+from .common import get_file_with_ext
+from .ts_regtest import TestSuiteRegtest
 
 class TestSuiteChainsplit(TestSuiteRegtest):
 	'forking scenario tests for the test.py test suite'

+ 31 - 6
test/test_py_d/ts_ethdev.py

@@ -27,10 +27,38 @@ from subprocess import run,PIPE,DEVNULL
 
 from mmgen.cfg import gc
 from mmgen.color import yellow,blue,cyan,set_vt100
-from mmgen.util import die
+from mmgen.util import msg,rmsg,die
 from mmgen.protocol import CoinProtocol
-from ..include.common import *
-from .common import *
+
+from ..include.common import (
+	cfg,
+	check_solc_ver,
+	omsg,
+	imsg,
+	imsg_r,
+	joinpath,
+	read_from_file,
+	write_to_file,
+	cmp_or_die,
+	strip_ansi_escapes,
+	silence,
+	end_silence,
+	gr_uc,
+	stop_test_daemons
+)
+from .common import (
+	ref_dir,
+	dfl_words_file,
+	tx_comment_jp,
+	tx_comment_lat_cyr_gr,
+	tw_comment_zh,
+	tw_comment_lat_cyr_gr,
+	get_file_with_ext,
+	ok_msg,
+	Ctrl_U
+)
+from .ts_base import TestSuiteBase
+from .ts_shared import TestSuiteShared
 
 del_addrs = ('4','1')
 dfl_sid = '98831F3A'
@@ -116,9 +144,6 @@ token_bals_getbalance = {
 	'2': ('111.888877776666555545','888.111122223333444455')
 }
 
-from .ts_base import *
-from .ts_shared import *
-
 coin = cfg.coin
 
 class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):

+ 18 - 7
test/test_py_d/ts_input.py

@@ -10,13 +10,24 @@
 test.test_py_d.ts_input: user input tests for the MMGen test.py test suite
 """
 
-import time
-
-from ..include.common import *
-from .ts_base import *
-from .input import *
-
-from mmgen.util import capfirst,remove_whitespace
+import os,time
+
+from ..include.common import (
+	cfg,
+	imsg,
+	imsg_r,
+	sample_mn,
+	get_data_from_file,
+	read_from_file,
+	strip_ansi_escapes
+)
+from .common import Ctrl_U,ref_dir
+from .ts_base import TestSuiteBase
+from .input import stealth_mnemonic_entry,user_dieroll_entry
+
+from mmgen.cfg import gc
+from mmgen.color import set_vt100
+from mmgen.util import fmt,capfirst,remove_whitespace
 from mmgen.wallet import get_wallet_cls
 
 class TestSuiteInput(TestSuiteBase):

+ 30 - 6
test/test_py_d/ts_main.py

@@ -20,18 +20,42 @@
 test.test_py_d.ts_main: Basic operations tests for the test.py test suite
 """
 
-from mmgen.util import async_run,capfirst,get_extension
-from mmgen.color import green,cyan
+import sys,os
 
+from mmgen.util import msg,msg_r,async_run,capfirst,get_extension,die
+from mmgen.color import green,cyan
 from mmgen.fileutil import get_data_from_file,write_data_to_file
 from mmgen.wallet import get_wallet_cls
 from mmgen.wallet.mmgen import wallet as MMGenWallet
 from mmgen.wallet.incog import wallet as IncogWallet
 from mmgen.rpc import rpc_init
-from ..include.common import *
-from .common import *
-from .ts_base import *
-from .ts_shared import *
+
+from ..include.common import (
+	cfg,
+	vmsg,
+	joinpath,
+	silence,
+	end_silence,
+	getrand,
+	getrandnum,
+	getrandnum_range,
+	getrandhex,
+	strip_ansi_escapes
+)
+from .common import (
+	pwfile,
+	hincog_fn,
+	get_file_with_ext,
+	get_comment,
+	tx_comment_lat_cyr_gr,
+	hincog_offset,
+	hincog_bytes,
+	hincog_seedlen,
+	incog_id_fn,
+	non_mmgen_fn
+)
+from .ts_base import TestSuiteBase
+from .ts_shared import TestSuiteShared
 
 def make_brainwallet_file(fn):
 	# Print random words with random whitespace in between

+ 5 - 3
test/test_py_d/ts_misc.py

@@ -23,9 +23,11 @@ test.test_py_d.ts_misc: Miscellaneous test groups for the test.py test suite
 import re,time
 
 from mmgen.cfg import gc
-from ..include.common import *
-from .common import *
-from .ts_base import *
+from mmgen.util import ymsg
+
+from ..include.common import cfg,start_test_daemons,stop_test_daemons,imsg
+from .common import get_file_with_ext
+from .ts_base import TestSuiteBase
 from .ts_main import TestSuiteMain
 
 class TestSuiteMisc(TestSuiteBase):

+ 4 - 2
test/test_py_d/ts_opts.py

@@ -10,8 +10,10 @@
 test.test_py_d.ts_opts: options processing tests for the MMGen test.py test suite
 """
 
-from ..include.common import *
-from .ts_base import *
+import os
+
+from ..include.common import cfg
+from .ts_base import TestSuiteBase
 
 class TestSuiteOpts(TestSuiteBase):
 	'options processing'

+ 26 - 5
test/test_py_d/ts_ref.py

@@ -21,13 +21,34 @@ test.test_py_d.ts_ref: Reference file tests for the test.py test suite
 """
 
 import os
+
 from mmgen.util import capfirst
 from mmgen.wallet import get_wallet_cls
-from ..include.common import *
-from .common import *
-
-from .ts_base import *
-from .ts_shared import *
+from ..include.common import (
+	cfg,
+	imsg_r,
+	ok,
+	joinpath,
+	cmp_or_die,
+	ref_kafile_hash_preset,
+	ref_kafile_pass,
+	read_from_file,
+	sample_text
+)
+from .common import (
+	dfl_words_file,
+	ref_dir,
+	chksum_pat,
+	pwfile,
+	ref_bw_file_spc,
+	ref_enc_fn,
+	get_env_without_debug_vars,
+	tool_enc_passwd,
+	skip
+)
+
+from .ts_base import TestSuiteBase
+from .ts_shared import TestSuiteShared
 
 wpasswd = 'reference password'
 

+ 15 - 5
test/test_py_d/ts_ref_3seed.py

@@ -21,12 +21,22 @@ test.test_py_d.ts_ref_3seed: Saved and generated reference file tests for 128,
                              192 and 256-bit seeds for the test.py test suite
 """
 
-from mmgen.util import capfirst
+import os
+
+from mmgen.util import msg,capfirst
 from mmgen.wallet import get_wallet_cls
-from ..include.common import *
-from .common import *
-from .ts_base import *
-from .ts_shared import *
+
+from ..include.common import cfg,cmp_or_die,joinpath
+from .common import (
+	pwfile,
+	ref_wallet_hash_preset,
+	ref_wallet_brainpass,
+	ref_wallet_incog_offset,
+	ref_dir,
+	ok_msg
+)
+from .ts_base import TestSuiteBase
+from .ts_shared import TestSuiteShared
 from .ts_wallet import TestSuiteWalletConv
 
 class TestSuiteRef3Seed(TestSuiteBase,TestSuiteShared):

+ 4 - 4
test/test_py_d/ts_ref_altcoin.py

@@ -24,10 +24,10 @@ import os
 
 from mmgen.color import set_vt100
 
-from .common import *
-from ..include.common import cfg
-from .ts_ref import *
-from .ts_base import *
+from .common import pwfile,dfl_wpasswd,ref_dir,dfl_words_file,dfl_addr_idx_list
+from ..include.common import cfg,joinpath,start_test_daemons,stop_test_daemons,cmp_or_die
+from .ts_ref import TestSuiteRef
+from .ts_base import TestSuiteBase
 
 class TestSuiteRefAltcoin(TestSuiteRef,TestSuiteBase):
 	'saved and generated altcoin reference files'

+ 28 - 6
test/test_py_d/ts_regtest.py

@@ -22,12 +22,37 @@ test.test_py_d.ts_regtest: Regtest tests for the test.py test suite
 
 import os,json,time,re
 from decimal import Decimal
-from mmgen.util import die,gmsg,capfirst,fmt_list,async_run
+
+from mmgen.color import yellow
+from mmgen.util import msg_r,die,gmsg,capfirst,fmt_list,async_run
 from mmgen.protocol import init_proto
 from mmgen.addrlist import AddrList
 from mmgen.wallet import Wallet,get_wallet_cls
-from ..include.common import *
-from .common import *
+
+from ..include.common import (
+	cfg,
+	imsg,
+	omsg,
+	stop_test_daemons,
+	joinpath,
+	silence,
+	end_silence,
+	cmp_or_die,
+	strip_ansi_escapes,
+	gr_uc,
+	getrandhex
+)
+from .common import (
+	ok_msg,
+	get_file_with_ext,
+	get_comment,
+	tw_comment_lat_cyr_gr,
+	tw_comment_zh,
+	tx_comment_jp,
+	get_env_without_debug_vars
+)
+from .ts_base import TestSuiteBase
+from .ts_shared import TestSuiteShared
 
 pat_date = r'\b\d\d-\d\d-\d\d\b'
 pat_date_time = r'\b\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d\b'
@@ -138,9 +163,6 @@ def make_burn_addr(proto):
 		proto   = proto,
 		mmtype  = 'compressed' ).pubhash2addr('00'*20)
 
-from .ts_base import *
-from .ts_shared import *
-
 class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
 	'transacting and tracking wallet operations via regtest mode'
 	networks = ('btc','ltc','bch')

+ 5 - 1
test/test_py_d/ts_seedsplit.py

@@ -20,10 +20,14 @@
 test.test_py_d.ts_seedsplit: Seed split/join tests for the test.py test suite
 """
 
+import os
+
 from mmgen.wallet import get_wallet_cls
 from mmgen.util import capfirst
 
-from .ts_base import *
+from ..include.common import strip_ansi_escapes,cmp_or_die
+from .common import get_file_with_ext
+from .ts_base import TestSuiteBase
 
 ref_wf = 'test/ref/98831F3A.bip39'
 ref_sid = '98831F3A'

+ 3 - 2
test/test_py_d/ts_shared.py

@@ -21,11 +21,12 @@ test.test_py_d.ts_shared: Shared methods for the test.py test suite
 """
 
 import os
+
 from mmgen.util import ymsg,get_extension
 from mmgen.wallet import get_wallet_cls
 
-from ..include.common import *
-from .common import *
+from ..include.common import cmp_or_die,strip_ansi_escapes,joinpath
+from .common import ref_bw_file
 
 class TestSuiteShared(object):
 	'shared methods for the test.py test suite'

+ 14 - 2
test/test_py_d/ts_tool.py

@@ -10,11 +10,23 @@
 test.test_py_d.ts_tool: tool tests for the MMGen test.py test suite
 """
 
+import os
+
+from mmgen.cfg import gc
 from mmgen.util import suf
 from mmgen.color import cyan
 
-from ..include.common import *
-from .ts_base import *
+from ..include.common import (
+	cfg,
+	vmsg,
+	read_from_file,
+	write_to_file,
+	cmp_or_die,
+	joinpath,
+	getrand
+)
+from .common import hincog_fn,incog_id_fn,hincog_offset,tool_enc_passwd,ref_dir
+from .ts_base import TestSuiteBase
 from .ts_main import TestSuiteMain
 
 class TestSuiteTool(TestSuiteMain,TestSuiteBase):

+ 7 - 4
test/test_py_d/ts_wallet.py

@@ -21,11 +21,14 @@ test.test_py_d.ts_wallet: Wallet conversion tests for the test.py test suite
 """
 
 import os
-from mmgen.util import capfirst
+
+from mmgen.util import msg,capfirst,get_extension
 from mmgen.wallet import get_wallet_cls
-from .common import *
-from .ts_base import *
-from .ts_shared import *
+
+from ..include.common import cfg,joinpath,imsg
+from .common import ref_dir,ref_wallet_brainpass,ref_wallet_incog_offset,hincog_fn,hincog_bytes
+from .ts_base import TestSuiteBase
+from .ts_shared import TestSuiteShared
 
 class TestSuiteWalletConv(TestSuiteBase,TestSuiteShared):
 	'wallet conversion to and from reference data'

+ 17 - 1
test/test_py_d/ts_xmr_autosign.py

@@ -13,8 +13,23 @@
 test.test_py_d.ts_xmr_autosign: xmr autosigning tests for the test.py test suite
 """
 
-from .ts_xmrwallet import *
+import os,time,re,shutil
 from pathlib import Path
+
+from mmgen.color import yellow,purple,gray
+from mmgen.util import fmt,async_run
+
+from ..include.common import (
+	cfg,
+	oqmsg,
+	oqmsg_r,
+	imsg,
+	silence,
+	end_silence
+)
+from .common import get_file_with_ext
+
+from .ts_xmrwallet import TestSuiteXMRWallet
 from .ts_autosign import TestSuiteAutosignBase
 
 def make_burn_addr():
@@ -118,6 +133,7 @@ class TestSuiteXMRAutosign(TestSuiteXMRWallet,TestSuiteAutosignBase):
 		data = self.users['alice']
 		from mmgen.wallet import Wallet
 		from mmgen.xmrwallet import MoneroWalletOps,xmrwallet_uargs
+		from mmgen.addrlist import KeyAddrList
 		silence()
 		kal = KeyAddrList(
 			cfg       = self.cfg,

+ 18 - 4
test/test_py_d/ts_xmrwallet.py

@@ -20,17 +20,31 @@
 test.test_py_d.ts_xmrwallet: xmrwallet tests for the test.py test suite
 """
 
-import sys,os,atexit,asyncio,shutil
+import sys,os,time,re,atexit,asyncio,shutil
 from subprocess import run,PIPE
+from collections import namedtuple
 
 from mmgen.cfg import gc
+from mmgen.util import msg,fmt,async_run,capfirst,is_int,die,list_gen
 from mmgen.obj import MMGenRange
 from mmgen.amt import XMRAmt
 from mmgen.addrlist import ViewKeyAddrList,KeyAddrList,AddrIdxList
-from ..include.common import *
-from .common import *
 
-from .ts_base import *
+from ..include.common import (
+	cfg,
+	omsg,
+	oqmsg_r,
+	ok,
+	imsg,
+	imsg_r,
+	write_data_to_file,
+	read_from_file,
+	silence,
+	end_silence,
+	strip_ansi_escapes
+)
+from .common import get_file_with_ext
+from .ts_base import TestSuiteBase
 
 # atexit functions:
 def stop_daemons(self):

+ 1 - 2
test/tooltest2.py

@@ -36,9 +36,8 @@ from mmgen.color import green,blue,purple,cyan
 from mmgen.util import msg,msg_r,Msg,is_hex_str,async_run,die
 
 from mmgen.bip39 import is_bip39_mnemonic
-from mmgen.baseconv import is_mmgen_mnemonic
+from mmgen.baseconv import is_mmgen_mnemonic,is_b58_str
 from mmgen.xmrseed import is_xmrseed
-from mmgen.baseconv import *
 
 skipped_tests = ['mn2hex_interactive']
 

+ 1 - 1
test/unit_tests_d/ut_dep.py

@@ -10,7 +10,7 @@ test.unit_tests_d.ut_dep: dependency unit tests for the MMGen suite
 from subprocess import run,PIPE
 
 from mmgen.cfg import gc
-from mmgen.util import ymsg,gmsg
+from mmgen.util import msg,ymsg,gmsg
 from mmgen.exception import NoLEDSupport
 
 from ..include.common import cfg,vmsg,check_solc_ver

+ 1 - 1
test/unit_tests_d/ut_xmrseed.py

@@ -4,7 +4,7 @@
 test/unit_tests_d/ut_xmrseed: Monero mnemonic unit test for the MMGen suite
 """
 
-from mmgen.util import msg,msg_r
+from mmgen.util import msg,msg_r,ymsg
 
 from ..include.common import cfg,qmsg,vmsg