[Nym3-commit] r477 - trunk/nymbaron/Server

laurent at conuropsis.org laurent at conuropsis.org
Wed Mar 15 22:21:31 CET 2006


Author: laurent
Date: 2006-03-15 22:21:29 +0100 (Wed, 15 Mar 2006)
New Revision: 477

Modified:
   trunk/nymbaron/Server/Main.py
Log:
Use an exception name more specific than `MyException'.


Modified: trunk/nymbaron/Server/Main.py
===================================================================
--- trunk/nymbaron/Server/Main.py	2006-03-13 22:05:38 UTC (rev 476)
+++ trunk/nymbaron/Server/Main.py	2006-03-15 21:21:29 UTC (rev 477)
@@ -53,6 +53,8 @@
     \tclean-surbs\tRemove used or outdated surbs from account surb files
     \tencode-synopses\tEncrypt synopses that are still in clear"""
 
+class MalformedControlMessage(Exception): pass
+
 # Forward declarations
 logger = None
 config = None
@@ -125,8 +127,6 @@
     - parse the message into header + sequence on control commands
     - run appropriate actions"""
     
-    class MyException(Exception): pass
-    
     logger.debug("Processing control message:\n%s" % base64.encodestring(msg))
     sr = Message.StrReader(msg)
     try:
@@ -135,7 +135,7 @@
             comList = sr.readCommandCToSList()
             try:
                 if (len(comList) != 3):
-                    raise MyException()
+                    raise MalformedControlMessage()
                 #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
@@ -173,14 +173,14 @@
                             #TODO send an Error message to the client when surbs become available?
                             #for the time being just ignore
                             logger.info("All nyms proposed in the list were already attributed")
-                            raise MyException()
+                            raise MalformedControlMessage()
                         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
                     logger.info("No Create Command")
-                    raise MyException()
+                    raise MalformedControlMessage()
                         
                 #phase 2 we look for the command surb
                 for idx, com in enumerate(comList):
@@ -188,21 +188,21 @@
                         nymUser.addSurbs(com.surbs)
                         if nymUser['nSurbs'] < 3:
                             logger.info("Not Enough Surbs")
-                            raise MyException()
+                            raise MalformedControlMessage()
                         del comList[idx]
                         break
                 if(len(comList) != 1):
                     nymUser.abort()
-                    raise MyException()
+                    raise MalformedControlMessage()
                 #phase 3 the last command should be a Newpk
                 com = comList[0]
                 if(com.ct() != 3): # TODO : evil numeric litteral
                     nymUser.abort()
-                    raise MyException()
+                    raise MalformedControlMessage()
                 nymUser.setKeys(com.ekid, com.ekenc)
                 if(not nymUser.checkMessageSign(msg[Message.sigLength:], h.sig)):
                     nymUser.abort()
-                    raise MyException()
+                    raise MalformedControlMessage()
                 else: # Valid account creation request. Send CREATED
                     #remember we received this register request
                     nymUser['inidgst'] = mdgst
@@ -215,7 +215,7 @@
                     #TODO non empty challenge?
                     created.fromData(nymUser.username, "")
                     nymUser.advanced_send(Message.buildMessage([created]))
-            except MyException:
+            except MalformedControlMessage:
                 #if you come here something went wrong during the account
                 #initialization
                 logger.debug("Bad formed account creation message")
@@ -371,8 +371,7 @@
         try:
             msg = readMessage(options.file)
             processMessage(msg)
-        except Exception: #TODO catch a more detailed exception
-            #since it is currently masking exceptions due to bugs
+        except MalformedControlMessage:
             # see if we got a base64 encoded message.
             m = re.search("binary\\n\\n(.*)\\n---", msg, re.S)
             if m:



More information about the Nym3-commit mailing list