[Nym3-commit] r104 - trunk

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Fri, 06 Aug 2004 14:00:37 +0200


Author: laurent
Date: 2004-08-06 14:00:17 +0200 (Fri, 06 Aug 2004)
New Revision: 104

Modified:
   trunk/Message.py
Log:
Use assert.


Modified: trunk/Message.py
===================================================================
--- trunk/Message.py	2004-08-05 22:37:00 UTC (rev 103)
+++ trunk/Message.py	2004-08-06 12:00:17 UTC (rev 104)
@@ -314,8 +314,7 @@
 		s = chr(len(self.list)) + self.pw
 		for i in range(len(self.list)):
 			s = s + chr(len(self.list[i])) + self.list[i]
-		if len(s) >= pow(256, 3): #should not be possible, otherwise, bug
-			raise BadArgument("Create.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(0) + intToStrBE(len(s), 3) + s
 		
 class Create2(CommandCToS):
@@ -345,8 +344,7 @@
 	def __str__(self):
 		"""Give the string of the Command that would be sent in a control message"""
 		s = self.cr
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Create2.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(1) + intToStrBE(len(s), 3) + s
 	
 class Surb(CommandCToS):
@@ -381,8 +379,7 @@
 	def __str__(self):
 		"""Give the string of the Command that would be sent in a control message"""
 		s = self.surbs
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Surb.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(2) + intToStrBE(len(s), 3) + s
 	
 class Newpk(CommandCToS):
@@ -426,8 +423,7 @@
 		"""Give the string of the Command that would be sent in a control message"""
 		#TODO check assuming len(kid)=128 or 256
 		s = intToStrBE(len(self.kid), 2) + self.kid + self.kenc
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Newpk.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(3) + intToStrBE(len(s), 3) + s
 	
 class Relay(CommandCToS):
@@ -471,8 +467,7 @@
 	def __str__(self):
 		"""Give the string of the Command that would be sent in a control message"""
 		s = intToStrBE(self.rs, 2) + self.rt + self.ri + self.body
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Relay.__str__ : Command Body too long")
+		assert len(s) < pow(256, 3)
 		return chr(4) + intToStrBE(len(s), 3) + s
 	
 class Get(CommandCToS):
@@ -509,8 +504,7 @@
 		s = ""
 		for i in range(len(self.l)):
 			s = s + self.l[i]
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Get.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(5) + intToStrBE(len(s), 3) + s
 	
 class Summarize(CommandCToS):
@@ -549,8 +543,7 @@
 	def __str__(self):
 		"""Give the string of the Command that would be sent in a control message"""
 		s = intToStrBE(self.num, 2) + self.after
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Summarize.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(6) + intToStrBE(len(s), 3) + s
 	
 class Delete(CommandCToS):
@@ -587,8 +580,7 @@
 		s = ""
 		for i in range(len(self.l)):
 			s = s + self.l[i]
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Delete.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(7) + intToStrBE(len(s), 3) + s
 	
 class Policy(CommandCToS):
@@ -681,8 +673,7 @@
 			s = s + intToStrBE(self.val, 2)
 		if self.opt in Common.userPolicy[5:]:
 			s = s + self.val
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Policy.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(8) + intToStrBE(len(s), 3) + s
 		
 	
@@ -725,8 +716,7 @@
 	def __str__(self):
 		"""Give the string of the Command that would be sent in a control message"""
 		s = chr(len(self.nym)) + self.nym + self.challenge
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Created.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(0) + intToStrBE(len(s), 3) + s
 
 class Status(CommandSToC):
@@ -786,8 +776,7 @@
 		    intToStrBE(self.quota, 4) + intToStrBE(self.used, 4)
 		for i in range(len(self.acks)):
 			s = s + self.acks[i]
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Status.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(1) + intToStrBE(len(s), 3) + s
 
 class Summary(CommandSToC):
@@ -824,8 +813,7 @@
 	def __str__(self):
 		"""Give the string of the Command that would be sent in a control message"""
 		s = self.bf + self.synSet
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Summary.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(2) + intToStrBE(len(s), 3) + s
 
 class Msg(CommandSToC):
@@ -863,8 +851,7 @@
 	def __str__(self):
 		"""Give the string of the Command that would be sent in a control message"""
 		s = self.mid + self.msg
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Msg.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(3) + intToStrBE(len(s), 3) + s
 
 class Dropped(CommandSToC):
@@ -901,8 +888,7 @@
 		s = ""
 		for i in range(len(self.list)):
 			s = s + self.list[i]
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("DroppedCreated.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(4) + intToStrBE(len(s), 3) + s
 
 class Error(CommandSToC):
@@ -940,8 +926,7 @@
 	def __str__(self):
 		"""Give the string of the Command that would be sent in a control message"""
 		s = self.nonce + self.error
-		if len(s) >= pow(256, 3): #should not be possible, otherwise bug
-			raise BadArgument("Error.__str__ : command body too long")
+		assert len(s) < pow(256, 3)
 		return chr(5) + intToStrBE(len(s), 3) + s
 
 def buildMessage(comList):