Browse Source

minor fixes, changes

MMGen 5 years ago
parent
commit
94d26212f6
5 changed files with 20 additions and 10 deletions
  1. 5 2
      mmgen/seed.py
  2. 8 5
      mmgen/tool.py
  3. 6 2
      mmgen/util.py
  4. 1 0
      test/test.py
  5. 0 1
      test/unit_tests_d/ut_bip39.py

+ 5 - 2
mmgen/seed.py

@@ -25,7 +25,6 @@ import os
 from mmgen.common import *
 from mmgen.obj import *
 from mmgen.crypto import *
-from mmgen.bip39 import bip39
 
 pnm = g.proj_name
 
@@ -892,7 +891,11 @@ class BIP39Mnemonic(MMGenMnemonic):
 	mn_name = 'BIP39'
 	ext = 'bip39'
 	wl_id = 'bip39'
-	conv_cls = bip39
+
+	def __init__(self,*args,**kwargs):
+		from mmgen.bip39 import bip39
+		self.conv_cls = bip39
+		super().__init__(*args,**kwargs)
 
 class SeedFile (SeedSourceUnenc):
 

+ 8 - 5
mmgen/tool.py

@@ -24,7 +24,6 @@ from mmgen.protocol import hash160
 from mmgen.common import *
 from mmgen.crypto import *
 from mmgen.addr import *
-from mmgen.bip39 import bip39
 
 NL = ('\n','\r\n')[g.platform=='win']
 
@@ -225,10 +224,14 @@ def init_generators(arg=None):
 		kg = KeyGenerator(at)
 		ag = AddrGenerator(at)
 
+def conv_cls_bip39():
+	from mmgen.bip39 import bip39
+	return bip39
+
 dfl_mnemonic_fmt = 'mmgen'
 mnemonic_fmts = {
-	'mmgen': { 'fmt': 'words', 'conv_cls': baseconv },
-	'bip39': { 'fmt': 'bip39', 'conv_cls': bip39 },
+	'mmgen': { 'fmt': 'words', 'conv_cls': lambda: baseconv },
+	'bip39': { 'fmt': 'bip39', 'conv_cls': conv_cls_bip39 },
 }
 mn_opts_disp = "(valid options: '{}')".format("', '".join(mnemonic_fmts))
 
@@ -512,7 +515,7 @@ class MMGenToolCmdMnemonic(MMGenToolCmdBase):
 
 	def mn_stats(self, fmt:mn_opts_disp = dfl_mnemonic_fmt ):
 		"show stats for mnemonic wordlist"
-		conv_cls = mnemonic_fmts[fmt]['conv_cls']
+		conv_cls = mnemonic_fmts[fmt]['conv_cls']()
 		fmt in conv_cls.digits or die(1,"'{}': not a valid format".format(fmt))
 		conv_cls.check_wordlist(fmt)
 		return True
@@ -520,7 +523,7 @@ class MMGenToolCmdMnemonic(MMGenToolCmdBase):
 	def mn_printlist( self, fmt:mn_opts_disp = dfl_mnemonic_fmt, enum=False, pager=False ):
 		"print mnemonic wordlist"
 		self._get_mnemonic_fmt(fmt) # perform check
-		ret = mnemonic_fmts[fmt]['conv_cls'].digits[fmt]
+		ret = mnemonic_fmts[fmt]['conv_cls']().digits[fmt]
 		if enum:
 			ret = ['{:>4} {}'.format(n,e) for n,e in enumerate(ret)]
 		return '\n'.join(ret)

+ 6 - 2
mmgen/util.py

@@ -89,13 +89,17 @@ def Die(ev=0,s=''):
 
 def rdie(ev=0,s=''): die(ev,red(s))
 def ydie(ev=0,s=''): die(ev,yellow(s))
-def hi(): ymsg('hi')
 
 def pformat(d):
 	import pprint
 	return pprint.PrettyPrinter(indent=4,compact=True).pformat(d)
 def pmsg(*args):
 	msg(pformat(args if len(args) > 1 else args[0]))
+def Pmsg(*args):
+	sys.stdout.write(ppformat(args if len(args) > 1 else args[0]) + '\n')
+def pdie(*args,exit_val=1):
+	sys.stderr.write(ppformat(args if len(args) > 1 else args[0]))
+	sys.exit(exit_val)
 
 def set_for_type(val,refval,desc,invert_bool=False,src=None):
 	src_str = (''," in '{}'".format(src))[bool(src)]
@@ -376,7 +380,7 @@ class baseconv(object):
 
 	@classmethod
 	def fromhex(cls,hexnum,wl_id,pad=None,tostr=False):
-		if wl_id in ('mmgen','tirosh'):
+		if wl_id in ('mmgen','tirosh','bip39'):
 			assert tostr == False,"'tostr' must be False for '{}'".format(wl_id)
 
 		if not is_hex_str(hexnum):

+ 1 - 0
test/test.py

@@ -891,5 +891,6 @@ except Exception:
 		import traceback
 		print(''.join(traceback.format_exception(*sys.exc_info())))
 		msg(blue('Test script exited with error'))
+	raise
 except:
 	raise

+ 0 - 1
test/unit_tests_d/ut_bip39.py

@@ -5,7 +5,6 @@ test/unit_tests_d/ut_bip39: BIP39 unit test for the MMGen suite
 
 from mmgen.common import *
 from mmgen.exception import *
-from mmgen.bip39 import *
 
 class unit_test(object):