[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Make nicknames case-insensitive



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

Modified Files:
	ClientMain.py ServerInfo.py test.py 
Log Message:
Make nicknames case-insensitive

Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- ClientMain.py	6 Jan 2003 05:03:34 -0000	1.30
+++ ClientMain.py	6 Jan 2003 07:03:24 -0000	1.31
@@ -55,7 +55,8 @@
     #   second element indicates whether the ServerInfo comes from a
     #   directory or a file.
     # digestMap: Map of (Digest -> 'D'|'I:filename').
-    # byNickname: Map from nickname to list of (ServerInfo, source) tuples.
+    # byNickname: Map from nickname.lower() to list of (ServerInfo, source)
+    #   tuples.
     # byCapability: Map from capability ('mbox'/'smtp'/'relay'/None) to
     #    list of (ServerInfo, source) tuples.
     # allServers: Same as byCapability[None]
@@ -258,6 +259,7 @@
         info = ServerInfo(string=contents, validatedDigests=self.digestMap)
 
         nickname = info.getNickname()
+        lcnickname = nickname.lower()
         identity = info.getIdentity()
         # Make sure that the identity key is consistent with what we know.
         for s, _ in self.serverList:
@@ -276,8 +278,8 @@
             raise MixError("Server desciptor is expired")
 
         # Is the server superseded?
-        if self.byNickname.has_key(nickname):
-            if info.isSupersededBy([s for s, _ in self.byNickname[nickname]]):
+        if self.byNickname.has_key(lcnickname):
+            if info.isSupersededBy([s for s,_ in self.byNickname[lcnickname]]):
                 raise MixError("Server descriptor is superseded")
 
         # Copy the server into DIR/servers.
@@ -295,12 +297,12 @@
 
     def expungeByNickname(self, nickname):
         """Remove all imported (non-directory) server nicknamed 'nickname'."""
-
+        lcnickname = nickname.lower()
         n = 0 # number removed
         newList = [] # replacement for serverList.
 
         for info, source in self.serverList:
-            if source == 'D' or info.getNickname() != nickname:
+            if source == 'D' or info.getNickname().lower() != lcnickname:
                 newList.append((info, source))
                 continue
             n += 1
@@ -330,7 +332,7 @@
                               None: self.allServers }
 
         for info, where in self.serverList:
-            nn = info.getNickname()
+            nn = info.getNickname().lower()
             lists = [ self.allServers, self.byNickname.setdefault(nn, []) ]
             for c in info.getCaps():
                 lists.append( self.byCapability[c] )
@@ -350,7 +352,8 @@
         fmtlen = min(longestnamelen, 20)
         format = "%"+str(fmtlen)+"s:"
         for n in nicknames:
-            lines.append(format%n)
+            nnreal = self.byNickname[n][0][0].getNickname()
+            lines.append(format%nnreal)
             for info, where in self.byNickname[n]:
                 caps = info.getCaps()
                 va = formatDate(info['Server']['Valid-After'])
@@ -383,11 +386,11 @@
         # XXXX their nicknames are different.  The logic should probably
         # XXXX go into directory, though.
 
-        u = {} # Map from nickname -> latest-expiring info encountered in lst
+        u = {} # Map from lcnickname -> latest-expiring info encountered in lst
         for info, _  in lst:
             if not info.isValidFrom(startAt, endAt):
                 continue
-            n = info.getNickname()
+            n = info.getNickname().lower()
             if u.has_key(n):
                 if u[n].isNewerThan(info):
                     continue
@@ -404,9 +407,10 @@
 
         newServers = []
         for info, where in self.serverList:
-            others = [ s for s, _ in self.byNickname[info.getNickname()] ]
+            lcnickname = info.getNickname().lower()
+            others = [ s for s, _ in self.byNickname[lcnickname] ]
             inDirectory = [ s.getDigest()
-                            for s, w in self.byNickname[info.getNickname()]
+                            for s, w in self.byNickname[lcnickname]
                             if w == 'D' ]
             if (where != 'D'
                 and (info.isExpiredAt(cutoff)
@@ -446,8 +450,8 @@
                 return name
             else:
                 LOG.error("Server is not currently valid")
-        elif self.byNickname.has_key(name):
-            s = self.__findOne(self.byNickname[name], startAt, endAt)
+        elif self.byNickname.has_key(name.lower()):
+            s = self.__findOne(self.byNickname[name.lower()], startAt, endAt)
             if not s:
                 raise MixError("Couldn't find valid descriptor %s" % name)
             return s
@@ -511,9 +515,9 @@
             if not endList:
                 raise MixError("No %s servers known" % endCap)
             # ... and pick one that hasn't been used, if possible.
-            used = [ info.getNickname() for info in startServers ]
+            used = [ info.getNickname().lower() for info in startServers ]
             unusedEndList = [ info for info in endList
-                              if info.getNickname() not in used ]
+                              if info.getNickname().lower() not in used ]
             if unusedEndList:
                 endServers = [ prng.pick(unusedEndList) ]
             else:
@@ -538,11 +542,11 @@
         # Find our candidate servers.
         midList = self.__find(self.byCapability[midCap],startAt,endAt)
         # Which of them are we using now?
-        used = [ info.getNickname()
+        used = [ info.getNickname().lower()
                  for info in list(startServers)+list(endServers) ]
         # Which are left?
         unusedMidList = [ info for info in midList
-                          if info.getNickname() not in used ]
+                          if info.getNickname().lower() not in used ]
         if len(unusedMidList) >= nNeeded:
             # We have enough enough servers to choose without replacement.
             midServers = prng.shuffle(unusedMidList, nNeeded)
@@ -554,17 +558,17 @@
 
             midServers = []
             if startServers:
-                prevNickname = startServers[-1].getNickname()
+                prevNickname = startServers[-1].getNickname().lower()
             else:
                 prevNickname = " (impossible nickname) "
             if endServers:
-                endNickname = endServers[0].getNickname()
+                endNickname = endServers[0].getNickname().lower()
             else:
                 endNickname = " (impossible nickname) "
 
             while nNeeded:
                 info = prng.pick(midList)
-                n = info.getNickname()
+                n = info.getNickname().lower()
                 if n != prevNickname and (nNeeded > 1 or n != endNickname):
                     midServers.append(info)
                     prevNickname = n

Index: ServerInfo.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ServerInfo.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- ServerInfo.py	5 Jan 2003 13:19:53 -0000	1.35
+++ ServerInfo.py	6 Jan 2003 07:03:24 -0000	1.36
@@ -266,10 +266,14 @@
            A ServerInfo is superseded when, for all time it is valid,
            a more-recently-published descriptor with the same nickname
            is also valid.
+
+           This function is only accurate when called with two valid
+           server descriptors.
         """
         valid = self.getIntervalSet()
         for o in others:
-            if o.isNewerThan(self) and o.getNickname() == self.getNickname():
+            if (o.isNewerThan(self) and
+                o.getNickname().lower() == self.getNickname().lower()):
                 valid -= o.getIntervalSet()
         return valid.isEmpty()
 

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- test.py	6 Jan 2003 05:42:07 -0000	1.66
+++ test.py	6 Jan 2003 07:03:24 -0000	1.67
@@ -3309,10 +3309,10 @@
         # Now, check whether the guts of lst are correct.
         eq(len(lst.servers), 4)
         eq(len(lst.serversByNickname), 2)
-        eq(len(lst.serversByNickname['Fred']), 2)
-        eq(len(lst.serversByNickname['Lola']), 2)
+        eq(len(lst.serversByNickname['fred']), 2)
+        eq(len(lst.serversByNickname['lola']), 2)
         eq(readFile(os.path.join(baseDir, "servers",
-                                 lst.serversByNickname['Fred'][0])),
+                                 lst.serversByNickname['fred'][0])),
            examples["Fred"][1])
         # Now generate a directory...
         lst.generateDirectory(now, dayLater, 0,
@@ -3358,8 +3358,8 @@
         lst = ServerList(baseDir)
         eq(len(lst.servers), 4)
         eq(len(lst.serversByNickname), 2)
-        eq(len(lst.serversByNickname['Fred']), 2)
-        eq(len(lst.serversByNickname['Lola']), 2)
+        eq(len(lst.serversByNickname['fred']), 2)
+        eq(len(lst.serversByNickname['lola']), 2)
         lst.generateDirectory(now, dayLater, 0,
                               identity)
         d2 = readFile(lst.getDirectoryFilename())
@@ -3388,11 +3388,11 @@
         # But we _do_ remove expired servers if others exist.
         lst.importServerInfo(examples["Lisa"][2]) # Valid from 5...7.
         eq(2, len(lst.servers))
-        eq(2, len(lst.serversByNickname["Lisa"]))
+        eq(2, len(lst.serversByNickname["lisa"]))
         lst.clean(now=now+60*60*24*100) # Very far in the future.
         eq(1, len(lst.servers))
-        eq(1, len(lst.serversByNickname["Lisa"]))
-        eq(readFile(os.path.join(serverDir, lst.serversByNickname["Lisa"][0])),
+        eq(1, len(lst.serversByNickname["lisa"]))
+        eq(readFile(os.path.join(serverDir, lst.serversByNickname["lisa"][0])),
            examples["Lisa"][2])
         eq(1, len(os.listdir(archiveDir)))
         eq(1, len(os.listdir(serverDir)))
@@ -3416,24 +3416,24 @@
         # Right now, nothing is superceded or expired
         lst.clean()
         eq(5, len(os.listdir(serverDir)))
-        eq(4, len(lst.serversByNickname["Bob"]))
+        eq(4, len(lst.serversByNickname["bob"]))
         lst.importServerInfo(examples["Bob"][4]) # Newer, from 4 to 7.
         # Now "Bob1" is superseded.
         lst.clean()
         eq(1, len(os.listdir(archiveDir)))
-        eq(4, len(lst.serversByNickname["Bob"]))
+        eq(4, len(lst.serversByNickname["bob"]))
         eq(5, len(os.listdir(serverDir)))
         eq(5, len(lst.servers))
-        eq(4, len(lst.serversByNickname["Bob"]))
+        eq(4, len(lst.serversByNickname["bob"]))
         eq(readFile(os.path.join(archiveDir, os.listdir(archiveDir)[0])),
            examples["Bob"][1])
-        for fn in lst.serversByNickname["Bob"]:
+        for fn in lst.serversByNickname["bob"]:
             fn = os.path.join(serverDir, fn)
             self.assertNotEquals(readFile(fn), examples["Bob"][1])
         # Now try rescanning...
         lst = ServerList(baseDir)
         eq(5, len(lst.servers))
-        eq(4, len(lst.serversByNickname["Bob"]))
+        eq(4, len(lst.serversByNickname["bob"]))
         # ... adding a new bob...
         lst.importServerInfo(examples["Bob"][5])
         eq(6, len(lst.servers))