[Nym3-commit] r186 - in trunk/nym3: . Server

laurent at conuropsis.org laurent at conuropsis.org
Sun Apr 10 18:32:41 CEST 2005


Author: laurent
Date: 2005-04-10 18:32:34 +0200 (Sun, 10 Apr 2005)
New Revision: 186

Modified:
   trunk/nym3/Message.py
   trunk/nym3/Server/Main.py
Log:
Correct minor errors in Message.py, reindent as we go along.


Modified: trunk/nym3/Message.py
===================================================================
--- trunk/nym3/Message.py	2005-04-10 16:18:33 UTC (rev 185)
+++ trunk/nym3/Message.py	2005-04-10 16:32:34 UTC (rev 186)
@@ -106,140 +106,139 @@
 """The length of message ID in bytes"""
 
 class StrReader:
-	"""wraps a string and gives method to read it chunk by chunk"""
-	def __init__(self, s):
-	    """initialize by wrapping a string"""
-	    self.s = s
-	    self.a = 0
-	    self.b = 0
+    """wraps a string and gives method to read it chunk by chunk"""
+    def __init__(self, s):
+	"""initialize by wrapping a string"""
+	self.s = s
+	self.a = 0
+	self.b = 0
 	    
-	def isEnd(self):
-		"""True if we have read the whole string"""
-		return (b == len(s))
+    def isEnd(self):
+	"""True if we have read the whole string"""
+	return (self.b == len(self.s))
 
-	def next(self, n):
-		"""return the next n characters"""
-		if n < 0:
-			raise BadArgument("StrReader.next : n < 0")
-		if self.b + n > len(self.s):
-			raise IndexError("StrReader.next : n too long")
-		self.a = self.b
-		self.b = self.b + n
-		return self.s[self.a:self.b]
+    def next(self, n):
+	"""return the next n characters"""
+	if n < 0: raise BadArgument("StrReader.next : n < 0")
+	if self.b + n > len(self.s):
+	    raise IndexError("StrReader.next : n too long")
+	self.a = self.b
+	self.b = self.b + n
+	return self.s[self.a:self.b]
 
-	def readHeader(self):
-		"""Read next header from the string"""
-		h = Header()
-		h.fromStrReader(self)
-		return h
+    def readHeader(self):
+    	"""Read next header from the string"""
+    	h = Header()
+    	h.fromStrReader(self)
+    	return h
 
-	def readCommandCToS(self):
-		"""Read next CommandCToS from string"""
-		try:
-			ct = ord(self.next(1))
-			cs = strToIntBE(self.next(3))
-			if (ct == CToSCODE['Create']):
-				a = Create()
-			elif (ct == CToSCODE['Create2']):
-				a = Create2()
-			elif (ct == CToSCODE['Surb']):
-				a = Surb()
-			elif (ct == CToSCODE['Newpk']):
-				a = Newpk()
-			elif (ct == CToSCODE['Relay']):
-				a = Relay()
-			elif (ct == CToSCODE['Get']):
-				a = Get()
-			elif (ct == CToSCODE['Summarize']):
-				a = Summarize()
-			elif (ct == CToSCODE['Delete']):
-				a = Delete()
-			elif (ct == CToSCODE['Policy']):
-				a = Policy()
-			else:
-				raise ParseError("Undefined Command Type")
-			a.fromStrReader(self, cs)
-			return a
-		except IndexError: #is it really necessary? is it not considered in the various fromStrReader ?
-			raise ParseError("Bad Formed Command")
+    def readCommandCToS(self):
+    	"""Read next CommandCToS from string"""
+    	try:
+    		ct = ord(self.next(1))
+    		cs = strToIntBE(self.next(3))
+    		if (ct == CToSCODE['Create']):
+    			a = Create()
+    		elif (ct == CToSCODE['Create2']):
+    			a = Create2()
+    		elif (ct == CToSCODE['Surb']):
+    			a = Surb()
+    		elif (ct == CToSCODE['Newpk']):
+    			a = Newpk()
+    		elif (ct == CToSCODE['Relay']):
+    			a = Relay()
+    		elif (ct == CToSCODE['Get']):
+    			a = Get()
+    		elif (ct == CToSCODE['Summarize']):
+    			a = Summarize()
+    		elif (ct == CToSCODE['Delete']):
+    			a = Delete()
+    		elif (ct == CToSCODE['Policy']):
+    			a = Policy()
+    		else:
+    			raise ParseError("Undefined Command Type")
+    		a.fromStrReader(self, cs)
+    		return a
+    	except IndexError: #is it really necessary? is it not considered in the various fromStrReader ?
+    		raise ParseError("Bad Formed Command")
 
-	def readCommandCToSList(self):
-		"""Read a list of CommandSToC from string, until
-		the string is completely read"""
-		l = []
-		while (not self.isEnd()):
-			l.append(self.readCommandCToS)
-		return l
+    def readCommandCToSList(self):
+    	"""Read a list of CommandSToC from string, until
+    	the string is completely read"""
+    	l = []
+    	while (not self.isEnd()):
+    		l.append(self.readCommandCToS())
+    	return l
 
-	def readCommandSToC(self):
-		"""Read next CommandSToC from string"""
-		try:
-			ct = ord(self.next(1))
-			cs = strToIntBE(self.next(3))
-			if (ct == SToCCODE['Created']):
-				a = Created()
-			elif (ct == SToCCODE['Status']):
-				a = Status()
-			elif (ct == SToCCODE['Summary']):
-				a = Summary()
-			elif (ct == SToCCODE['Msg']):
-				a = Msg()
-			elif (ct == SToCCODE['Dropped']):
-				a = Dropped()
-			elif (ct == SToCCODE['Error']):
-				a = Error()
-			else:
-				raise ParseError("Undefined Command Type")
-			a.fromStrReader(self, cs)
-			return a
-		except IndexError: #is it really necessary? is it not considered in the various fromStrReader ?
-			#it should, if not consider it a bug
-			raise ParseError("Bad Formed Command")
+    def readCommandSToC(self):
+    	"""Read next CommandSToC from string"""
+    	try:
+    		ct = ord(self.next(1))
+    		cs = strToIntBE(self.next(3))
+    		if (ct == SToCCODE['Created']):
+    			a = Created()
+    		elif (ct == SToCCODE['Status']):
+    			a = Status()
+    		elif (ct == SToCCODE['Summary']):
+    			a = Summary()
+    		elif (ct == SToCCODE['Msg']):
+    			a = Msg()
+    		elif (ct == SToCCODE['Dropped']):
+    			a = Dropped()
+    		elif (ct == SToCCODE['Error']):
+    			a = Error()
+    		else:
+    			raise ParseError("Undefined Command Type")
+    		a.fromStrReader(self, cs)
+    		return a
+    	except IndexError: #is it really necessary? is it not considered in the various fromStrReader ?
+    		#it should, if not consider it a bug
+    		raise ParseError("Bad Formed Command")
 
-	def readCommandSToCList(self):
-		"""Read a list of CommandSToC from string, until
-		the string is completely read"""
-		l = []
-		while (not self.isEnd()):
-			l.append(self.readCommandSToC)
-		return l
+    def readCommandSToCList(self):
+    	"""Read a list of CommandSToC from string, until
+    	the string is completely read"""
+    	l = []
+    	while (not self.isEnd()):
+    		l.append(self.readCommandSToC)
+    	return l
 
-	def readNym(self, start, cs):
-		"""Read a Nym length + a nym
-		Raise ParseError if it takes more characters from the string that previously advertised"""
-		nl = ord(self.next(1))
-		if(self.b + nl - start > cs):
-			raise ParseError("Bad Formed Command")
-		return self.next(nl)
+    def readNym(self, start, cs):
+    	"""Read a Nym length + a nym
+    	Raise ParseError if it takes more characters from the string that previously advertised"""
+    	nl = ord(self.next(1))
+    	if(self.b + nl - start > cs):
+    		raise ParseError("Bad Formed Command")
+    	return self.next(nl)
 
-	def readNymList(self, start, cs):
-		"""Read a list of (Nym length + a nym)
-		Raise ParseError if it takes more characters from the string that previously advertised"""
-		try:
-			l = []
-			while(self.b < start + cs):
-				l.append(self.readNym(start, cs))
-			return l
-		except ParseError: #is it really necessary?
-			raise
+    def readNymList(self, start, cs):
+    	"""Read a list of (Nym length + a nym)
+    	Raise ParseError if it takes more characters from the string that previously advertised"""
+    	try:
+    		l = []
+    		while(self.b < start + cs):
+    			l.append(self.readNym(start, cs))
+    		return l
+    	except ParseError: #is it really necessary?
+    		raise
 
-	def readMid(self, length, start, cs):
-		"""Read a str of len = length
-		Raise ParseError if it takes more characters from the string that previously advertised, in that case, doesn't read the StrReader"""
-		if(self.b + length - start > cs):
-			raise ParseError("Bad Formed Command")
-		return self.next(length)
+    def readMid(self, length, start, cs):
+    	"""Read a str of len = length
+    	Raise ParseError if it takes more characters from the string that previously advertised, in that case, doesn't read the StrReader"""
+    	if(self.b + length - start > cs):
+    		raise ParseError("Bad Formed Command")
+    	return self.next(length)
 
-	def readMidList(self, length, start, cs):
-		"""Read a list of str of len length
-		Raise ParseError if it takes more characters from the string that previously advertised"""
-		try:
-			l = []
-			while(self.b < start + cs):
-				l.append(self.readMid(length, start, cs))
-			return l
-		except ParseError: #is it really necessary?
-			raise
+    def readMidList(self, length, start, cs):
+    	"""Read a list of str of len length
+    	Raise ParseError if it takes more characters from the string that previously advertised"""
+    	try:
+    		l = []
+    		while(self.b < start + cs):
+    			l.append(self.readMid(length, start, cs))
+    		return l
+    	except ParseError: #is it really necessary?
+    		raise
 	
 class Header:
     """Header Object

Modified: trunk/nym3/Server/Main.py
===================================================================
--- trunk/nym3/Server/Main.py	2005-04-10 16:18:33 UTC (rev 185)
+++ trunk/nym3/Server/Main.py	2005-04-10 16:32:34 UTC (rev 186)
@@ -130,7 +130,7 @@
             try:
                 nymUser = User.User(h.nym)
             except User.NoSuchUser:
-                print "No such user"
+                print "No such user %s" % h.nym
                 sys.exit(73) #TODO is it the smart error code
             if(not nymUser.checkMessageSign(msg[Message.sigLength:],h.sig)):
                return



More information about the Nym3-commit mailing list