Browse Source

function rename: base_proto_tw_subclass() -> base_proto_subclass()

The MMGen Project 3 years ago
parent
commit
ef13359519
7 changed files with 17 additions and 14 deletions
  1. 2 2
      mmgen/addrdata.py
  2. 1 1
      mmgen/main_addrimport.py
  3. 2 2
      mmgen/tw/addrs.py
  4. 2 2
      mmgen/tw/bal.py
  5. 2 2
      mmgen/tw/ctl.py
  6. 2 2
      mmgen/tw/unspent.py
  7. 6 3
      mmgen/util.py

+ 2 - 2
mmgen/addrdata.py

@@ -20,7 +20,7 @@
 addrdata.py: MMGen AddrData and related classes
 addrdata.py: MMGen AddrData and related classes
 """
 """
 
 
-from .util import vmsg,base_proto_tw_subclass,fmt,die
+from .util import vmsg,base_proto_subclass,fmt,die
 from .base_obj import AsyncInit
 from .base_obj import AsyncInit
 from .obj import MMGenObject,MMGenDict,get_obj
 from .obj import MMGenObject,MMGenDict,get_obj
 from .addr import MMGenID,AddrListID
 from .addr import MMGenID,AddrListID
@@ -69,7 +69,7 @@ class AddrData(MMGenObject):
 class TwAddrData(AddrData,metaclass=AsyncInit):
 class TwAddrData(AddrData,metaclass=AsyncInit):
 
 
 	def __new__(cls,proto,*args,**kwargs):
 	def __new__(cls,proto,*args,**kwargs):
-		return MMGenObject.__new__(base_proto_tw_subclass(cls,proto,'common'))
+		return MMGenObject.__new__(base_proto_subclass(cls,proto,'tw','common'))
 
 
 	async def __init__(self,proto,wallet=None):
 	async def __init__(self,proto,wallet=None):
 		from .rpc import rpc_init
 		from .rpc import rpc_init

+ 1 - 1
mmgen/main_addrimport.py

@@ -163,7 +163,7 @@ def make_args_list(tw,al,batch,rescan):
 async def main():
 async def main():
 	from .tw.ctl import TrackingWallet
 	from .tw.ctl import TrackingWallet
 	if opt.token_addr:
 	if opt.token_addr:
-		proto.tokensym = 'foo' # hack to trigger 'Token' in base_proto_tw_subclass()
+		proto.tokensym = 'foo' # hack to trigger 'Token' in base_proto_subclass()
 
 
 	tw = await TrackingWallet(
 	tw = await TrackingWallet(
 		proto      = proto,
 		proto      = proto,

+ 2 - 2
mmgen/tw/addrs.py

@@ -21,7 +21,7 @@ twaddrs: Tracking wallet listaddresses class for the MMGen suite
 """
 """
 
 
 from ..color import green
 from ..color import green
-from ..util import msg,die,base_proto_tw_subclass
+from ..util import msg,die,base_proto_subclass
 from ..base_obj import AsyncInit
 from ..base_obj import AsyncInit
 from ..obj import MMGenDict,TwComment
 from ..obj import MMGenDict,TwComment
 from ..addr import CoinAddr,MMGenID
 from ..addr import CoinAddr,MMGenID
@@ -30,7 +30,7 @@ from .common import TwCommon
 class TwAddrList(MMGenDict,TwCommon,metaclass=AsyncInit):
 class TwAddrList(MMGenDict,TwCommon,metaclass=AsyncInit):
 
 
 	def __new__(cls,proto,*args,**kwargs):
 	def __new__(cls,proto,*args,**kwargs):
-		return MMGenDict.__new__(base_proto_tw_subclass(cls,proto,'addrs'),*args,**kwargs)
+		return MMGenDict.__new__(base_proto_subclass(cls,proto,'tw','addrs'),*args,**kwargs)
 
 
 	def raw_list(self):
 	def raw_list(self):
 		return [((k if k.type == 'mmgen' else 'Non-MMGen'),self[k]['addr'],self[k]['amt']) for k in self]
 		return [((k if k.type == 'mmgen' else 'Non-MMGen'),self[k]['addr'],self[k]['amt']) for k in self]

+ 2 - 2
mmgen/tw/bal.py

@@ -21,7 +21,7 @@ twbal: Tracking wallet getbalance class for the MMGen suite
 """
 """
 
 
 from ..color import red,green
 from ..color import red,green
-from ..util import base_proto_tw_subclass
+from ..util import base_proto_subclass
 from ..base_obj import AsyncInit
 from ..base_obj import AsyncInit
 from ..objmethods import MMGenObject
 from ..objmethods import MMGenObject
 from ..rpc import rpc_init
 from ..rpc import rpc_init
@@ -29,7 +29,7 @@ from ..rpc import rpc_init
 class TwGetBalance(MMGenObject,metaclass=AsyncInit):
 class TwGetBalance(MMGenObject,metaclass=AsyncInit):
 
 
 	def __new__(cls,proto,*args,**kwargs):
 	def __new__(cls,proto,*args,**kwargs):
-		return MMGenObject.__new__(base_proto_tw_subclass(cls,proto,'bal'))
+		return MMGenObject.__new__(base_proto_subclass(cls,proto,'tw','bal'))
 
 
 	async def __init__(self,proto,minconf,quiet):
 	async def __init__(self,proto,minconf,quiet):
 
 

+ 2 - 2
mmgen/tw/ctl.py

@@ -21,7 +21,7 @@ twctl: Tracking wallet control class for the MMGen suite
 """
 """
 
 
 from ..globalvars import g
 from ..globalvars import g
-from ..util import msg,dmsg,write_mode,base_proto_tw_subclass,die
+from ..util import msg,dmsg,write_mode,base_proto_subclass,die
 from ..base_obj import AsyncInit
 from ..base_obj import AsyncInit
 from ..objmethods import MMGenObject
 from ..objmethods import MMGenObject
 from ..obj import TwComment,get_obj
 from ..obj import TwComment,get_obj
@@ -38,7 +38,7 @@ class TrackingWallet(MMGenObject,metaclass=AsyncInit):
 	importing = False
 	importing = False
 
 
 	def __new__(cls,proto,*args,**kwargs):
 	def __new__(cls,proto,*args,**kwargs):
-		return MMGenObject.__new__(base_proto_tw_subclass(cls,proto,'ctl'))
+		return MMGenObject.__new__(base_proto_subclass(cls,proto,'tw','ctl'))
 
 
 	async def __init__(self,proto,mode='r',token_addr=None):
 	async def __init__(self,proto,mode='r',token_addr=None):
 
 

+ 2 - 2
mmgen/tw/unspent.py

@@ -33,7 +33,7 @@ from ..util import (
 	fmt,
 	fmt,
 	keypress_confirm,
 	keypress_confirm,
 	line_input,
 	line_input,
-	base_proto_tw_subclass
+	base_proto_subclass
 )
 )
 from ..base_obj import AsyncInit
 from ..base_obj import AsyncInit
 from ..objmethods import MMGenObject
 from ..objmethods import MMGenObject
@@ -45,7 +45,7 @@ from .common import TwCommon,TwMMGenID,get_tw_label
 class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
 class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
 
 
 	def __new__(cls,proto,*args,**kwargs):
 	def __new__(cls,proto,*args,**kwargs):
-		return MMGenObject.__new__(base_proto_tw_subclass(cls,proto,'unspent'))
+		return MMGenObject.__new__(base_proto_subclass(cls,proto,'tw','unspent'))
 
 
 	txid_w = 64
 	txid_w = 64
 	print_hdr_fs = '{a} (block #{b}, {c} UTC)\n{d}Sort order: {e}\n{f}\n\nTotal {g}: {h}\n'
 	print_hdr_fs = '{a} (block #{b}, {c} UTC)\n{d}Sort order: {e}\n{f}\n\nTotal {g}: {h}\n'

+ 6 - 3
mmgen/util.py

@@ -650,18 +650,21 @@ def get_subclasses(cls,names=False):
 				yield j
 				yield j
 	return tuple((c.__name__ for c in gen(cls)) if names else gen(cls))
 	return tuple((c.__name__ for c in gen(cls)) if names else gen(cls))
 
 
-def base_proto_tw_subclass(cls,proto,modname):
+def base_proto_subclass(cls,proto,subdir,modname):
 	"""
 	"""
 	magic module loading and class selection
 	magic module loading and class selection
 	"""
 	"""
-	modname = f'mmgen.base_proto.{proto.base_proto.lower()}.tw.{modname}'
+	modpath = 'mmgen.base_proto.{}.{}{}'.format(
+		proto.base_proto.lower(),
+		subdir + '.' if subdir else '',
+		modname )
 	clsname = (
 	clsname = (
 		proto.mod_clsname
 		proto.mod_clsname
 		+ ('Token' if proto.tokensym else '')
 		+ ('Token' if proto.tokensym else '')
 		+ cls.__name__ )
 		+ cls.__name__ )
 
 
 	import importlib
 	import importlib
-	return getattr(importlib.import_module(modname),clsname)
+	return getattr(importlib.import_module(modpath),clsname)
 
 
 # decorator for TrackingWallet
 # decorator for TrackingWallet
 def write_mode(orig_func):
 def write_mode(orig_func):