[Nym3-commit] r249 - trunk/nym3/Server

laurent at conuropsis.org laurent at conuropsis.org
Sat May 7 15:29:11 CEST 2005


Author: laurent
Date: 2005-05-07 15:29:08 +0200 (Sat, 07 May 2005)
New Revision: 249

Modified:
   trunk/nym3/Server/Main.py
Log:
Indentation.


Modified: trunk/nym3/Server/Main.py
===================================================================
--- trunk/nym3/Server/Main.py	2005-05-07 13:28:33 UTC (rev 248)
+++ trunk/nym3/Server/Main.py	2005-05-07 13:29:08 UTC (rev 249)
@@ -62,64 +62,63 @@
     - verifies signature
     - parse the message into header + sequence on control commands
     - run appropriate actions"""
-    #TODO prendre le numero de sequence pour pouvoir l'aquitter
     
     class MyException(Exception): pass
     
     sr = Message.StrReader(msg)
     try:
 	h = sr.readHeader()
-        if (h.nym == ""):
-            comList = sr.readCommandCToSList()
-            try:
-                if (len(comList) != 3):
-                    raise MyException()
-	        #this may be an account setup message
+	if (h.nym == ""):
+	    comList = sr.readCommandCToSList()
+	    try:
+		if (len(comList) != 3):
+		    raise MyException()
+		#this may be an account setup message
 		#we suppose there is a exactly 1 Create Command in the message,
 		# 1 Newpk, and 1 surb. more will raise an error
 
-                nymUser = None
-	        #phase 1 we look for the command create
-                for idx, com in enumerate(comList):
-                    if(com.ct() == 0): # TODO : evil numeric litteral
-		        #the Create command
-                        for pnym in com.list:
-                            try:
-                                nymUser = User.User(pnym,1)
-                            except User.AlreadySuchUser: pass
-                            if(nymUser != None):
-                                break
-                        if (nymUser == None):
-                            #TODO send an Error message to the client when surbs become available?
-                            #for the time being just ignore
-                            print "All nyms proposed in the list were already attributed"
-                            raise MyException()
-                        del(comList[idx])
-                        break
-                if(nymUser == None):
-                    #TODO send an Error message to the client when surbs become available?
-                    #for the time being just ignore
-                    print "No Create Command"
-                    raise MyException()
-                        
-	        #phase 2 we look for the command surb
-                for idx, com in enumerate(comList):
-                    if(com.ct()==2): # TODO : evil numeric litteral
-                        nymUser.addSurbs(com.surbs)
-                        del (comList[idx])
-                        break
-                if(len(comList) != 1):
-                    nymUser.abort()
-                    raise MyException()
-	        #phase 3 the last command should be a Newpk
-                com = comList[0]
-                if(com.ct() != 3): # TODO : evil numeric litteral
-                    nymUser.abort()
-                    raise MyException()
-                nymUser.setKeys(com.ekid, com.ekenc)
-                if(not nymUser.checkMessageSign(msg[Message.sigLength:],h.sig)):
-                   nymUser.abort()
-                   raise MyException()
+		nymUser = None
+		#phase 1 we look for the command create
+		for idx, com in enumerate(comList):
+		    if(com.ct() == 0): # TODO : evil numeric litteral
+			#the Create command
+			for pnym in com.list:
+			    try:
+				nymUser = User.User(pnym,1)
+			    except User.AlreadySuchUser: pass
+			    if(nymUser != None):
+				break
+			if (nymUser == None):
+			    #TODO send an Error message to the client when surbs become available?
+			    #for the time being just ignore
+			    print "All nyms proposed in the list were already attributed"
+			    raise MyException()
+			del(comList[idx])
+			break
+		if(nymUser == None):
+		    #TODO send an Error message to the client when surbs become available?
+		    #for the time being just ignore
+		    print "No Create Command"
+		    raise MyException()
+			
+		#phase 2 we look for the command surb
+		for idx, com in enumerate(comList):
+		    if(com.ct()==2): # TODO : evil numeric litteral
+			nymUser.addSurbs(com.surbs)
+			del (comList[idx])
+			break
+		if(len(comList) != 1):
+		    nymUser.abort()
+		    raise MyException()
+		#phase 3 the last command should be a Newpk
+		com = comList[0]
+		if(com.ct() != 3): # TODO : evil numeric litteral
+		    nymUser.abort()
+		    raise MyException()
+		nymUser.setKeys(com.ekid, com.ekenc)
+		if(not nymUser.checkMessageSign(msg[Message.sigLength:],h.sig)):
+		   nymUser.abort()
+		   raise MyException()
 		else: # Valid account creation request. Send CREATED
 		    nymUser.received(h.seqNo)
 		    created = Message.Created()
@@ -127,104 +126,105 @@
 		    nymUser.setUp()
 		    nymUser.advanced_send(Message.buildMessage([created]))
 	    except MyException:
-                   #if you come here something went wrong during the account
-                   #initialization
-                   print "Bad formed account creation message"
-                   sys.exit(2) #TODO smart error code
-        else: # NYM is not empty
-            try:
-                nymUser = User.User(h.nym)
-            except User.NoSuchUser:
-                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)):
+		   #if you come here something went wrong during the account
+		   #initialization
+		   print "Bad formed account creation message"
+		   sys.exit(2) #TODO smart error code
+	else: # NYM is not empty
+	    try:
+		nymUser = User.User(h.nym)
+	    except User.NoSuchUser:
+		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
 	    #The message comes from a known nick and is authenticated
 	    #register the seqNo as received
 	    #TODO is it ok?
 	    nymUser.received(h.seqNo)
-            comList = sr.readCommandCToSList()
-            for com in comList:
-                if (com.ct() == Message.CToSCODE['Create']):
+	    comList = sr.readCommandCToSList()
+	    for com in comList:
+		if (com.ct() == Message.CToSCODE['Create']):
 		    #we ignore the Create command if it comes from the nymholder of an account, should we rise an error?
-                    pass
-                #if the account is not initialized, or if it is already up we ignore Create2 messages
-                elif (com.ct() == Message.CToSCODE['Create2']):
-                    if (nymUser.isInitialized() and (not nymUser.isUp())):
-                        if(nymUser.checkChallenge(com.cr)):
-                            nymUser.setUp()
+		    pass
+		#if the account is not initialized, or if it is already up we ignore Create2 messages
+		elif (com.ct() == Message.CToSCODE['Create2']):
+		    if (nymUser.isInitialized() and (not nymUser.isUp())):
+			if(nymUser.checkChallenge(com.cr)):
+			    nymUser.setUp()
 		#other commands are only taken into account if the account is up
-                elif (nymUser.isUp()):
-                    if (com.ct() == Message.CToSCODE['Surb']):
-                        if (len(com.surbs) == 0):
-                            nymUser.delSurbs()
-                        else:
-                            nymUser.addSurbs(com.surbs)
-                    elif (com.ct() == Message.CToSCODE['Newpk']):
-                        nymUser.setKeys(com.kid,com.kenc)
-                    elif (com.ct() == Message.CToSCODE['Relay']):
-                        ec = Mail.relay(h.nym, com.rt, com.ri,
+		elif (nymUser.isUp()):
+		    if (com.ct() == Message.CToSCODE['Surb']):
+			if (len(com.surbs) == 0):
+			    nymUser.delSurbs()
+			else:
+			    nymUser.addSurbs(com.surbs)
+		    elif (com.ct() == Message.CToSCODE['Newpk']):
+			nymUser.setKeys(com.kid,com.kenc)
+		    elif (com.ct() == Message.CToSCODE['Relay']):
+			ec = Mail.relay(h.nym, com.rt, com.ri,
 					Config.serverName, com.body)
-                        if (ec != 0):
-                            print "mixminion exited abnormally with error code %d" % ec
-                            sys.exit(2)
-                            
-                    elif (com.ct() == Message.CToSCODE['Get']):
-                        msgList = []
-                        sendList = []
-                        for m in com.l:
-                            if nymUser.hasMail(m):
-                                msgCom = Message.Msg()
-                                msgCom.fromData(m,nymUser.getMail(m))
-                                msgList.append(msgCom)
-                                sendList.append(m)
-                        ec = nymUser.advanced_send(
+			if (ec != 0):
+			    print "mixminion exited abnormally with error code %d" % ec
+			    sys.exit(2)
+			    
+		    elif (com.ct() == Message.CToSCODE['Get']):
+			msgList = []
+			sendList = []
+			for m in com.l:
+			    if nymUser.hasMail(m):
+				msgCom = Message.Msg()
+				msgCom.fromData(m,nymUser.getMail(m))
+				msgList.append(msgCom)
+				sendList.append(m)
+			ec = nymUser.advanced_send(
 				Message.buildMessage(msgList))
-                        if (ec == 0):
-                            nymUser.markMid(sendList,lifeCycle['sent-in-full'])
-                            if(nymUser['HoldUntilAck'] == 'never'):
-                                map(nymUser.delete_msg,sendList)
-                            
-                        else:
-                            print "mixminion exited abnormally with error code %d" % ec
-                            sys.exit(2)
-                                
-                    elif (com.ct() == Message.CToSCODE['Summarize']):
-                        comList = []
-                        sendList = nymUser.prepareSummary(com.num, com.after)
-                        mList = []
+			print "EC is " + str(ec)
+			if (ec == 0):
+			    nymUser.markMid(sendList,lifeCycle['sent-in-full'])
+			    if(nymUser['HoldUntilAck'] == 'never'):
+				map(nymUser.delete_msg,sendList)
+			    
+			else:
+			    print "mixminion exited abnormally with error code %d" % ec
+			    sys.exit(2)
+				
+		    elif (com.ct() == Message.CToSCODE['Summarize']):
+			comList = []
+			sendList = nymUser.prepareSummary(com.num, com.after)
+			mList = []
 			print str(sendList)
-                        for (ml, bf, blob) in sendList:
-                            sumCom = Message.Summary()
-                            sumCom.fromData(bf, blob)
-                            comList.append(sumCom)
-                            mList = mList + ml
-                        ec = nymUser.send(Message.buildMessage(comList))
-                        if (ec == 0):
-                            nymUser.markMid(mList, lifeCycle['synopsis-sent'])
-                        else:
-                            print "mixminion exited abnormally with error code %d" % ec
-                            sys.exit(2)
+			for (ml, bf, blob) in sendList:
+			    sumCom = Message.Summary()
+			    sumCom.fromData(bf, blob)
+			    comList.append(sumCom)
+			    mList = mList + ml
+			ec = nymUser.send(Message.buildMessage(comList))
+			if (ec == 0):
+			    nymUser.markMid(mList, lifeCycle['synopsis-sent'])
+			else:
+			    print "mixminion exited abnormally with error code %d" % ec
+			    sys.exit(2)
 
-                    elif (com.ct() == Message.CToSCODE['Delete']):
-                        for mid in com.l:
-                            nymUser.delete_msg(mid)
-                    elif (com.ct() == Message.CToSCODE['Policy']):
-                        if(com.opt in Common.userPolicy):
-                            nymUser[com.opt] = com.val
-                    else:
-                        pass
+		    elif (com.ct() == Message.CToSCODE['Delete']):
+			for mid in com.l:
+			    nymUser.delete_msg(mid)
+		    elif (com.ct() == Message.CToSCODE['Policy']):
+			if(com.opt in Common.userPolicy):
+			    nymUser[com.opt] = com.val
+		    else:
+			pass
     except Message.ParseError, inst:
 	print inst
-	sys.exit(2) #TODO error code                
+	sys.exit(2) #TODO error code		
 	      
     
 if __name__ == '__main__':
     optlist, pholder = getopt.getopt(sys.argv[1:], 'D:d:m')
     for o, a in optlist:
-        if o == "-D":
-            Config.DEBUG = True
-        
+	if o == "-D":
+	    Config.DEBUG = True
+	
     for o, a in optlist:
 	if o == "-d": # mail delivery
 	    processIncoming(a, sys.stdin.read())



More information about the Nym3-commit mailing list