Browse Source

obj.py: cleanups

The MMGen Project 3 years ago
parent
commit
2bbf186de5
1 changed files with 36 additions and 38 deletions
  1. 36 38
      mmgen/obj.py

+ 36 - 38
mmgen/obj.py

@@ -24,10 +24,8 @@ import sys,os,re,unicodedata
 from decimal import *
 from decimal import *
 from string import hexdigits,ascii_letters,digits
 from string import hexdigits,ascii_letters,digits
 
 
-from .exception import *
-from .globalvars import *
-from .color import *
 from .objmethods import *
 from .objmethods import *
+from .exception import BadTwComment
 
 
 def get_obj(objname,*args,**kwargs):
 def get_obj(objname,*args,**kwargs):
 	"""
 	"""
@@ -93,38 +91,6 @@ class MMGenList(list,MMGenObject):
 class MMGenDict(dict,MMGenObject):
 class MMGenDict(dict,MMGenObject):
 	pass
 	pass
 
 
-class Str(str,Hilite):
-	pass
-
-class Int(int,Hilite,InitErrors):
-	min_val = None
-	max_val = None
-	max_digits = None
-	color = 'red'
-
-	def __new__(cls,n,base=10):
-		if type(n) == cls:
-			return n
-		try:
-			me = int.__new__(cls,str(n),base)
-			if cls.min_val != None:
-				assert me >= cls.min_val, f'is less than cls.min_val ({cls.min_val})'
-			if cls.max_val != None:
-				assert me <= cls.max_val, f'is greater than cls.max_val ({cls.max_val})'
-			if cls.max_digits != None:
-				assert len(str(me)) <= cls.max_digits, f'has more than {cls.max_digits} digits'
-			return me
-		except Exception as e:
-			return cls.init_fail(e,n)
-
-	@classmethod
-	def fmtc(cls,*args,**kwargs):
-		cls.method_not_implemented()
-
-	@classmethod
-	def colorize(cls,n,color=True):
-		return super().colorize(repr(n),color=color)
-
 class ImmutableAttr: # Descriptor
 class ImmutableAttr: # Descriptor
 	"""
 	"""
 	For attributes that are always present in the data instance
 	For attributes that are always present in the data instance
@@ -253,9 +219,6 @@ class MMGenListItem(MMGenObject):
 	def _asdict(self):
 	def _asdict(self):
 		return dict((k,v) for k,v in self.__dict__.items() if k in self.valid_attrs)
 		return dict((k,v) for k,v in self.__dict__.items() if k in self.valid_attrs)
 
 
-class MMGenIdx(Int):
-	min_val = 1
-
 class MMGenRange(tuple,InitErrors,MMGenObject):
 class MMGenRange(tuple,InitErrors,MMGenObject):
 
 
 	min_idx = None
 	min_idx = None
@@ -299,6 +262,41 @@ class MMGenRange(tuple,InitErrors,MMGenObject):
 	def items(self):
 	def items(self):
 		return list(self.iterate())
 		return list(self.iterate())
 
 
+class Int(int,Hilite,InitErrors):
+	min_val = None
+	max_val = None
+	max_digits = None
+	color = 'red'
+
+	def __new__(cls,n,base=10):
+		if type(n) == cls:
+			return n
+		try:
+			me = int.__new__(cls,str(n),base)
+			if cls.min_val != None:
+				assert me >= cls.min_val, f'is less than cls.min_val ({cls.min_val})'
+			if cls.max_val != None:
+				assert me <= cls.max_val, f'is greater than cls.max_val ({cls.max_val})'
+			if cls.max_digits != None:
+				assert len(str(me)) <= cls.max_digits, f'has more than {cls.max_digits} digits'
+			return me
+		except Exception as e:
+			return cls.init_fail(e,n)
+
+	@classmethod
+	def fmtc(cls,*args,**kwargs):
+		cls.method_not_implemented()
+
+	@classmethod
+	def colorize(cls,n,color=True):
+		return super().colorize(repr(n),color=color)
+
+class MMGenIdx(Int):
+	min_val = 1
+
+class Str(str,Hilite):
+	pass
+
 class HexStr(str,Hilite,InitErrors):
 class HexStr(str,Hilite,InitErrors):
 	color = 'red'
 	color = 'red'
 	width = None
 	width = None