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

[minion-cvs] Improve englishSequence to allow disjunctions (or) as w...



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

Modified Files:
	Common.py 
Log Message:
Improve englishSequence to allow disjunctions (or) as well as conjunctions (and)

Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -d -r1.109 -r1.110
--- Common.py	31 Aug 2003 19:29:29 -0000	1.109
+++ Common.py	3 Sep 2003 15:49:25 -0000	1.110
@@ -10,7 +10,7 @@
             'MixFatalError', 'MixProtocolError', 'UIError', 'UsageError',
             'armorText', 'ceilDiv', 'checkPrivateDir', 'checkPrivateFile',
             'createPrivateDir', 'disp64', 
-            'encodeBase64', 'floorDiv', 'formatBase64',
+            'encodeBase64', 'englishSequence', 'floorDiv', 'formatBase64',
             'formatDate', 'formatFnameTime', 'formatTime',
             'installSIGCHLDHandler', 'isSMTPMailbox', 'openUnique',
             'previousMidnight', 'readFile', 'readPickled',
@@ -189,7 +189,7 @@
         s = s[:-1]
     return s
 
-def englishSequence(lst, empty="none"):
+def englishSequence(lst, empty="none", compound="and"):
     """Given a sequence of items, return the sequence formatted
        according to ordinary English conventions of punctuation.
 
@@ -202,17 +202,19 @@
 
     punc = ", "
     for item in lst:
-        if "," in item or stringContains(item, " and "):
+        if ("," in item or 
+            stringContains(item, " and ") or 
+            stringContains(item, " or ")):
             punc = "; "
             break
 
     if len(lst) == 2:
         if punc == ", ":
-            return "%s and %s" % tuple(lst)
+            return "%s %s %s" % (lst[0], compound, lst[1])
         else:
-            return "%s; and %s" % tuple(lst)
+            return "%s; %s %s" % (lst[0], compound, lst[1])
     else:
-        return "%s%sand %s" % (punc.join(lst[0:-1]), punc, lst[-1])
+        return "%s%s%s %s" % (punc.join(lst[0:-1]), punc, compound, lst[-1])
 
 #----------------------------------------------------------------------
 # Functions to generate and parse OpenPGP-style ASCII armor