[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Make status-fd logic less abstruse



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv24983/lib/mixminion

Modified Files:
	ClientMain.py Common.py test.py 
Log Message:
Make status-fd logic less abstruse

Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.179
retrieving revision 1.180
diff -u -d -r1.179 -r1.180
--- ClientMain.py	14 May 2004 23:44:09 -0000	1.179
+++ ClientMain.py	17 May 2004 22:39:17 -0000	1.180
@@ -1384,7 +1384,7 @@
     address.setHeaders(parseMessageAndHeaders(headerStr+"\n")[1])
     if address and inFile == '-' and not address.hasPayload():
         print "1 packet needed"
-        STATUS.log("COUNT_PACKETS", 1)
+        STATUS.log("COUNT_PACKETS", "1")
         return
     else:
         if address and not address.hasPayload():
@@ -1411,7 +1411,7 @@
 
         n = mixminion.BuildMessage.getNPacketsToEncode(message, 0, prefix)
         print "%d packets needed" % n
-        STATUS.log("COUNT_PACKETS", n)
+        STATUS.log("COUNT_PACKETS", str(n))
 
 _PING_USAGE = """\
 Usage: mixminion ping [options] serverName
@@ -1942,9 +1942,10 @@
                     used = surblog.isSURBUsed(surb) and "yes" or "no"
                     print surb.format()
                     print "Used:", used
-                    STATUS.log("INSPECT_SURB", surb.getHexDigest(),
-                               surb.timestamp,
-                               surblog.isSURBUsed(surb) and "1" or "0")
+                    STATUS.log("INSPECT_SURB",
+                               "%s %s %s"%(surb.getHexDigest(),
+                                           surb.timestamp,
+                                   surblog.isSURBUsed(surb) and "1" or "0"))
             except ParseError, e:
                 print "Error while parsing: %s"%e
     finally:

Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- Common.py	14 May 2004 23:44:09 -0000	1.139
+++ Common.py	17 May 2004 22:39:17 -0000	1.140
@@ -1100,12 +1100,10 @@
             A space,
             A 'message type' consisting only of capital letters, digits,
                 and underscores,
-            Optionally, a space, and a space-separated list of arguments,
+            Optionally, a space followed by a sequence of printing non-newline
+                characters.
             A newline.
 
-       If an argument contains a space, a newline, or a backslash,
-       these characters are escaped with a backslash.
-
        To maintain compatibility, arguments must only be added, never
        removed, moved, or changed.  Messages should be emitted by
        importing the global STATUS instance from this module and calling:
@@ -1115,10 +1113,11 @@
        Each message type should be independent (it seems safer to not
        assume any particular ordering between messages).
 
-       Keep machine-parseability in mind when adding these message types:
-       make sure the name is unique, and separate arguments with colons.
+       Keep machine-parseability in mind when adding these message
+       types: make sure the name is unique.  When possible, separate
+       arguments with a character that cannot occur in the arguments:
+       colons, spaces, or so on.
     """
-    _ESC_PAT = re.compile(r'([ \n\\])')
     def __init__(self):
         """DOCDOC"""
         self.fd = None
@@ -1126,13 +1125,13 @@
 
     def setFD(self, fdnum):
         """DOCDOC"""
-        # this will fail if the invoking user did not actually open the file
+        # This will fail if the invoking user did not actually open the file
         # descriptor they ask us to use, for example if they did:
         #  mixminion send --status-fd=3
         # instead of:
         #  mixminion send --status-fd=3 3>somewhere.txt
         #
-        # remember, this is not meant for use by a shell, it is for
+        # Remember, this is not meant for use by a shell. It is for
         # front-end programs that are running mixminion in a child process.
         # There will be a pipe connected to this fd which the parent process
         # will be reading from.
@@ -1142,14 +1141,14 @@
         else:
             self.fd = fdnum
 
-    def msg(self, name, args):
+    def msg(self, name, args=""):
         """DOCDOC"""
-        r = [ "[MIXMINION:]", name ]
-        for arg in args:
-            r.append(self._ESC_PAT.sub(r"\\\1",str(arg)))
-        return "%s\n"%(" ".join(r))
+        if args:
+            return "[MIXMINION:] %s %s\n" % (name,args)
+        else:
+            return "[MIXMINION:] %s\n"%(name)
 
-    def log(self, name, *args):
+    def log(self, name, args=""):
         """DOCDOC"""
         if self.fd is None:
             return
@@ -1165,25 +1164,6 @@
 # should be emitted with STATUS.log()
 STATUS = StatusLog()
 
-_STATUS_LINE_RE = re.compile(r'^\[MIXMINION:\] ([A-Z_]+)(?: (.*))?', re.S)
-_ARG_RE = re.compile(r'^((?:[^ \n\\]+|\\[ \n\\])+)[ \n]?')
-_UNESC_ARG_RE = re.compile(r'\\([ \n\\])')
-def parseStatusLogLine(s):
-    """DOCDOC"""
-    m = _STATUS_LINE_RE.match(s)
-    if not m:
-        return None,None
-    name = m.group(1)
-    s = m.group(2)
-    res = []
-    while s:
-        m = _ARG_RE.match(s)
-        if not m:
-            return None,None
-        res.append(_UNESC_ARG_RE.sub(r'\1', m.group(1)))
-        s = s[m.end():]
-    return name, res
-
 #----------------------------------------------------------------------
 # Time processing
 

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.198
retrieving revision 1.199
diff -u -d -r1.198 -r1.199
--- test.py	17 May 2004 05:19:07 -0000	1.198
+++ test.py	17 May 2004 22:39:17 -0000	1.199
@@ -3632,33 +3632,19 @@
     def testStatusLog(self):
         SL = mixminion.Common.StatusLog()
         self.assertEquals("[MIXMINION:] ABC\n",
-                          SL.msg("ABC", []))
+                          SL.msg("ABC", ""))
         self.assertEquals("[MIXMINION:] ABC 42 HELLO\n",
-                          SL.msg("ABC", [42, "HELLO"]))
-        self.assertEquals("[MIXMINION:] ABC A A\\ BC\\ D\n",
-                          SL.msg("ABC", ["A", "A BC D"]))
-        self.assertEquals("[MIXMINION:] A_BCD A\\\nB\\\\X\n",
-                          SL.msg("A_BCD", ["A\nB\\X"]))
+                          SL.msg("ABC", "42 HELLO"))
         tmpfile = mix_mktemp()
         f = open(tmpfile, 'w')
         SL.setFD(f.fileno())
-        SL.log("REVOLUTION_9", "number nine", "number nine")
+        SL.log("REVOLUTION_9", "number nine number nine")
         SL.log("REVOLUTION_9", "take this brother")
         SL.setFD(None)
         f.close()
         self.assertEquals(readFile(tmpfile),
-                   "[MIXMINION:] REVOLUTION_9 number\\ nine number\\ nine\n"
-                   "[MIXMINION:] REVOLUTION_9 take\\ this\\ brother\n")
-
-        PSL = mixminion.Common.parseStatusLogLine
-        self.assertEquals(PSL("[MIXMINION:] ABC 42 HELLO\n"),
-                          ("ABC",["42", "HELLO"]))
-        self.assertEquals(PSL("[MIXMINION:] ABC 42 HELLO\\ \n"),
-                          ("ABC",["42", "HELLO "]))
-        self.assertEquals(PSL("[MIXMINION:] ABC\n"),
-                          ("ABC",[]))
-        self.assertEquals(PSL("[MIXMINION:] ABC X\\\nYZ 03.1\\\\\n"),
-                          ("ABC",["X\nYZ", "03.1\\"]))
+                   "[MIXMINION:] REVOLUTION_9 number nine number nine\n"
+                   "[MIXMINION:] REVOLUTION_9 take this brother\n")
 
 #----------------------------------------------------------------------
 # File paranoia
@@ -7757,7 +7743,7 @@
     loader = unittest.TestLoader()
     tc = loader.loadTestsFromTestCase
 
-    if 1:
+    if 0:
         suite.addTest(tc(QueueTests))
         return suite
     testClasses = [MiscTests,