Browse Source

obj.py: move TwLabel and TwMMGenID to tw.py

The MMGen Project 3 years ago
parent
commit
d08503129e
5 changed files with 51 additions and 52 deletions
  1. 1 1
      mmgen/addrdata.py
  2. 1 1
      mmgen/main_addrimport.py
  3. 0 48
      mmgen/obj.py
  4. 48 1
      mmgen/tw.py
  5. 1 1
      test/test_py_d/ts_main.py

+ 1 - 1
mmgen/addrdata.py

@@ -84,7 +84,7 @@ class TwAddrData(AddrData,metaclass=AsyncInit):
 
 	async def __init__(self,proto,wallet=None):
 		from .rpc import rpc_init
-		from .obj import TwLabel
+		from .tw import TwLabel
 		from .globalvars import g
 		from .seed import SeedID
 		self.proto = proto

+ 1 - 1
mmgen/main_addrimport.py

@@ -24,7 +24,7 @@ import time
 
 from .common import *
 from .addrlist import AddrList,KeyAddrList
-from .obj import TwLabel
+from .tw import TwLabel
 
 ai_msgs = lambda k: {
 	'rescan': """

+ 0 - 48
mmgen/obj.py

@@ -299,54 +299,6 @@ class MMGenRange(tuple,InitErrors,MMGenObject):
 	def items(self):
 		return list(self.iterate())
 
-class TwMMGenID(str,Hilite,InitErrors,MMGenObject):
-	color = 'orange'
-	width = 0
-	trunc_ok = False
-	def __new__(cls,proto,id_str):
-		if type(id_str) == cls:
-			return id_str
-		ret = None
-		from .addr import MMGenID
-		try:
-			ret = MMGenID(proto,id_str)
-			sort_key,idtype = ret.sort_key,'mmgen'
-		except Exception as e:
-			try:
-				assert id_str.split(':',1)[0] == proto.base_coin.lower(),(
-					f'not a string beginning with the prefix {proto.base_coin.lower()!r}:' )
-				assert set(id_str[4:]) <= set(ascii_letters+digits),'contains non-alphanumeric characters'
-				assert len(id_str) > 4,'not more that four characters long'
-				ret,sort_key,idtype = str(id_str),'z_'+id_str,'non-mmgen'
-			except Exception as e2:
-				return cls.init_fail(e,id_str,e2=e2)
-
-		me = str.__new__(cls,ret)
-		me.obj = ret
-		me.sort_key = sort_key
-		me.type = idtype
-		me.proto = proto
-		return me
-
-# non-displaying container for TwMMGenID,TwComment
-class TwLabel(str,InitErrors,MMGenObject):
-	exc = BadTwLabel
-	passthru_excs = (BadTwComment,)
-	def __new__(cls,proto,text):
-		if type(text) == cls:
-			return text
-		try:
-			ts = text.split(None,1)
-			mmid = TwMMGenID(proto,ts[0])
-			comment = TwComment(ts[1] if len(ts) == 2 else '')
-			me = str.__new__( cls, mmid + (' ' + comment if comment else '') )
-			me.mmid = mmid
-			me.comment = comment
-			me.proto = proto
-			return me
-		except Exception as e:
-			return cls.init_fail(e,text)
-
 class HexStr(str,Hilite,InitErrors):
 	color = 'red'
 	width = None

+ 48 - 1
mmgen/tw.py

@@ -47,10 +47,57 @@ from .util import (
 )
 from .base_obj import AsyncInit
 from .objmethods import Hilite,InitErrors,MMGenObject
-from .obj import ImmutableAttr,ListItemAttr,MMGenListItem,MMGenList,MMGenDict,TwComment,get_obj,TwLabel,TwMMGenID
+from .obj import ImmutableAttr,ListItemAttr,MMGenListItem,MMGenList,MMGenDict,TwComment,get_obj
 from .addr import CoinAddr,MMGenID,AddrIdx,is_mmgen_id,is_coin_addr
 from .rpc import rpc_init
 
+class TwMMGenID(str,Hilite,InitErrors,MMGenObject):
+	color = 'orange'
+	width = 0
+	trunc_ok = False
+	def __new__(cls,proto,id_str):
+		if type(id_str) == cls:
+			return id_str
+		ret = None
+		try:
+			ret = MMGenID(proto,id_str)
+			sort_key,idtype = ret.sort_key,'mmgen'
+		except Exception as e:
+			try:
+				assert id_str.split(':',1)[0] == proto.base_coin.lower(),(
+					f'not a string beginning with the prefix {proto.base_coin.lower()!r}:' )
+				assert set(id_str[4:]) <= set(ascii_letters+digits),'contains non-alphanumeric characters'
+				assert len(id_str) > 4,'not more that four characters long'
+				ret,sort_key,idtype = str(id_str),'z_'+id_str,'non-mmgen'
+			except Exception as e2:
+				return cls.init_fail(e,id_str,e2=e2)
+
+		me = str.__new__(cls,ret)
+		me.obj = ret
+		me.sort_key = sort_key
+		me.type = idtype
+		me.proto = proto
+		return me
+
+# non-displaying container for TwMMGenID,TwComment
+class TwLabel(str,InitErrors,MMGenObject):
+	exc = BadTwLabel
+	passthru_excs = (BadTwComment,)
+	def __new__(cls,proto,text):
+		if type(text) == cls:
+			return text
+		try:
+			ts = text.split(None,1)
+			mmid = TwMMGenID(proto,ts[0])
+			comment = TwComment(ts[1] if len(ts) == 2 else '')
+			me = str.__new__( cls, mmid + (' ' + comment if comment else '') )
+			me.mmid = mmid
+			me.comment = comment
+			me.proto = proto
+			return me
+		except Exception as e:
+			return cls.init_fail(e,text)
+
 def get_tw_label(proto,s):
 	"""
 	raise an exception on a malformed comment, return None on an empty or invalid label

+ 1 - 1
test/test_py_d/ts_main.py

@@ -477,7 +477,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared):
 		cmd_args = self._make_txcreate_cmdline(tx_data)
 
 		if cmdline_inputs:
-			from mmgen.tx import TwLabel
+			from mmgen.tw import TwLabel
 			cmd_args = [
 				'--inputs={},{},{},{},{},{}'.format(
 					TwLabel(self.proto,dfake[0][self.lbl_id]).mmid,dfake[1]['address'],