[Nym3-commit] r461 - trunk/nymbaron

laurent at conuropsis.org laurent at conuropsis.org
Wed Mar 8 20:41:13 CET 2006


Author: laurent
Date: 2006-03-08 20:41:12 +0100 (Wed, 08 Mar 2006)
New Revision: 461

Modified:
   trunk/nymbaron/Message.py
Log:
Indentation, not finished with Message.py yet it's a tedious task

Modified: trunk/nymbaron/Message.py
===================================================================
--- trunk/nymbaron/Message.py	2006-03-08 19:20:31 UTC (rev 460)
+++ trunk/nymbaron/Message.py	2006-03-08 19:41:12 UTC (rev 461)
@@ -35,60 +35,60 @@
 
 # Every command type has a numerical code as described in nym-spec.
 CToSCODE = { 'Create': 0, 'Create2': 1, 'Surb': 2, 'Newpk': 3,
-	     'Relay': 4, 'Get': 5, 'Summarize': 6, 'Delete': 7,
-	     'Policy': 8 }
+             'Relay': 4, 'Get': 5, 'Summarize': 6, 'Delete': 7,
+             'Policy': 8 }
 # nym-spec says MSGS and later MSG. use Msg for consistency.
 SToCCODE = { 'Created': 0, 'Status': 1, 'Summary': 2, 'Msg': 3,
-	     'Dropped': 4, 'Error': 5 }
+             'Dropped': 4, 'Error': 5 }
 
 class ParseError(Exception):
-	"""ParseError : error raised if anything goes wrong during parsing"""
-	def __init__(self, value):
-		self.value = value
+    """ParseError : error raised if anything goes wrong during parsing"""
+    def __init__(self, value):
+        self.value = value
 
-	def __str__(self):
-		return repr(self.value)
+    def __str__(self):
+        return repr(self.value)
 
 class BadArgument(Exception):
-	"""BadArgument : error raised if a function is given an irrelevant argument"""
-	def __init__(self, value):
-		self.value = value
+    """BadArgument : error raised if a function is given an irrelevant argument"""
+    def __init__(self, value):
+        self.value = value
 
-	def __str__(self):
-		return repr(self.value)
+    def __str__(self):
+        return repr(self.value)
 
 def strToIntBE(s):
-	"""return the Int coded by the string s with the big endian convention"""
-	def aux(s, ac):
-		if(s == ""):
-			return ac
-		else:
-			return aux(s[1:], 256 * ac + ord(s[0]))
-	return aux(s, 0)
+    """return the Int coded by the string s with the big endian convention"""
+    def aux(s, ac):
+        if(s == ""):
+            return ac
+        else:
+            return aux(s[1:], 256 * ac + ord(s[0]))
+    return aux(s, 0)
 
 def intToStrBE(n,mod):
-	"""return a string coding the n modulo 256^mod in big endian"""
-	def aux(n, ac, mod):
-		if(mod == 0):
-			return ac
-		else:
-			return aux(n / 256, chr(n % 256) + ac, mod - 1)
-	return aux(n, "", mod)
+    """return a string coding the n modulo 256^mod in big endian"""
+    def aux(n, ac, mod):
+        if(mod == 0):
+            return ac
+        else:
+            return aux(n / 256, chr(n % 256) + ac, mod - 1)
+    return aux(n, "", mod)
 
 def nbBits(n):
-	"""return the number of bits of a strictly positive integer,
-	0 otherwise"""
-	res = 0
-	p = 1
-	while(n >= p):
-		p = 2 * p
-		res = res + 1
-	return res
+    """return the number of bits of a strictly positive integer,
+    0 otherwise"""
+    res = 0
+    p = 1
+    while(n >= p):
+        p = 2 * p
+        res = res + 1
+    return res
 
 def isMidList(l, n):
     """true if l is a list of strings of length n"""
     for i in l:
-	if ((len(i) != n) or (type(i) != types.StringType)): return False
+        if ((len(i) != n) or (type(i) != types.StringType)): return False
     return True
 
 sigLength = Common.sigLength
@@ -103,14 +103,14 @@
 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
+        """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 (self.b == len(self.s))
+        """True if we have read the whole string"""
+        return (self.b == len(self.s))
 
     def next(self, n):
 	"""return the next n characters"""
@@ -159,23 +159,23 @@
     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:
-		print "Got ct %u" % ct
-    		raise ParseError("Undefined Command Type")
-    	    a.fromStrReader(self, cs)
-    	    return a
+            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:
+                print "Got ct %u" % ct
+                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")
+            # 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
@@ -975,140 +975,140 @@
     return s
 
 if (__name__ == '__main__'):
-	import Mail
-	l = []
-	for i in range(3):
-		l.append(Mail.genMid(length = 20))
-	H = Header()
-	H.fromData("JR", "01234567890123456789")
-	print H
-	del H
-	print "test Create"
-	C = Create()
-	C.fromData(["Lolo_", "Marsux", "Azatoth_", "Keeh"])
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
-	print "test Create2"
-	C = Create2()
-	C.fromData("azertyuiop42")
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
-	print "test Surb"
-	C = Surb()
-	C.fromData("-" * 2104)
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
-	print "test Newpk"
-	C = Newpk()
-        k1 = _cr.pk_generate()
-        k2 = _cr.pk_generate()
-	C.fromData(k1, k2)
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
-	print "test Relay"
-	C = Relay()
-	C.fromData("ab", "too lazy to make real ones here", "this is the body of the email. It sholud contain some kind of header, but for testing the parser, who cares?")
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
-	print "test Get"
-	C = Get()
-	C.fromData(l)
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
-	print "test Summarize"
-	C = Summarize()
-	C.fromData(10, l[0])
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
-	print "test Delete"
-	C = Delete()
-	C.fromData(l)
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
-	print "test Policy"
-	C = Policy()
-	C.fromData("HoldUntilAck", "never")
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandCToS()
-	s2 = str(D)
-	assert s1 == s2
+    import Mail
+    l = []
+    for i in range(3):
+        l.append(Mail.genMid(length = 20))
+    H = Header()
+    H.fromData("JR", "01234567890123456789")
+    print H
+    del H
+    print "test Create"
+    C = Create()
+    C.fromData(["Lolo_", "Marsux", "Azatoth_", "Keeh"])
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
+    print "test Create2"
+    C = Create2()
+    C.fromData("azertyuiop42")
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
+    print "test Surb"
+    C = Surb()
+    C.fromData("-" * 2104)
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
+    print "test Newpk"
+    C = Newpk()
+    k1 = _cr.pk_generate()
+    k2 = _cr.pk_generate()
+    C.fromData(k1, k2)
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
+    print "test Relay"
+    C = Relay()
+    C.fromData("ab", "too lazy to make real ones here", "this is the body of the email. It sholud contain some kind of header, but for testing the parser, who cares?")
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
+    print "test Get"
+    C = Get()
+    C.fromData(l)
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
+    print "test Summarize"
+    C = Summarize()
+    C.fromData(10, l[0])
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
+    print "test Delete"
+    C = Delete()
+    C.fromData(l)
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
+    print "test Policy"
+    C = Policy()
+    C.fromData("HoldUntilAck", "never")
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandCToS()
+    s2 = str(D)
+    assert s1 == s2
 
-	print "test Created"
-	C = Created()
-	C.fromData("Marsux", "what is the answer to universe life and everything")
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandSToC()
-	s2 = str(D)
-	assert s1 == s2
+    print "test Created"
+    C = Created()
+    C.fromData("Marsux", "what is the answer to universe life and everything")
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandSToC()
+    s2 = str(D)
+    assert s1 == s2
 
-	print "test Status"
-	C = Status()
-	C.fromData(5, 10, 424242, 212121, l)
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandSToC()
-	s2 = str(D)
-	assert s1 == s2
+    print "test Status"
+    C = Status()
+    C.fromData(5, 10, 424242, 212121, l)
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandSToC()
+    s2 = str(D)
+    assert s1 == s2
 
-	print "test Summary"
-	C = Summary()
-	C.fromData("ab","this should be an encrypted set of synopses")
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandSToC()
-	s2 = str(D)
-	assert s1 == s2
+    print "test Summary"
+    C = Summary()
+    C.fromData("ab","this should be an encrypted set of synopses")
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandSToC()
+    s2 = str(D)
+    assert s1 == s2
 
-	print "test Msg"
-	C = Msg()
-	C.fromData(l[0], "Say something stupid, like, I am wearing female's underwear")
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandSToC()
-	s2 = str(D)
-	assert s1 == s2
+    print "test Msg"
+    C = Msg()
+    C.fromData(l[0], "Say something stupid, like, I am wearing female's underwear")
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandSToC()
+    s2 = str(D)
+    assert s1 == s2
 
-	print "test Dropped"
-	C = Dropped()
-	C.fromData(l)
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandSToC()
-	s2 = str(D)
-	assert s1 == s2
+    print "test Dropped"
+    C = Dropped()
+    C.fromData(l)
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandSToC()
+    s2 = str(D)
+    assert s1 == s2
 
-	print "test Error"
-	C = Msg()
-	C.fromData(l[0], "Help! Help! I am being repressed!")
-	s1 = str(C)
-	S = StrReader(s1)
-	D = S.readCommandSToC()
-	s2 = str(D)
-	assert s1 == s2
+    print "test Error"
+    C = Msg()
+    C.fromData(l[0], "Help! Help! I am being repressed!")
+    s1 = str(C)
+    S = StrReader(s1)
+    D = S.readCommandSToC()
+    s2 = str(D)
+    assert s1 == s2
 



More information about the Nym3-commit mailing list