Author: gstein
Date: Sat Jun  8 08:26:41 2013
New Revision: 1490933

URL: http://svn.apache.org/r1490933
Log:
Finish up the remaining couple functions.

* lib/steve.py:
  (randomize, ballots): implement. these make an assumption on the
    argument type. need to look at actual usage.

Modified:
    steve/trunk/lib/steve.py

Modified: steve/trunk/lib/steve.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/lib/steve.py?rev=1490933&r1=1490932&r2=1490933&view=diff
==============================================================================
--- steve/trunk/lib/steve.py (original)
+++ steve/trunk/lib/steve.py Sat Jun  8 08:26:41 2013
@@ -23,6 +23,7 @@ import os
 import hashlib
 import re
 import time
+import random
 
 SCRIPT = os.path.basename(sys.argv[0])
 
@@ -115,19 +116,41 @@ def not_valid(votes, valid):
   return False
 
 
+_RE_CHOICE = re.compile('\\s*\\[([a-z0-9])\\]\\s')
+
 def randomize(text):
-  ### todo
+  "Break TEXT into a prolog, randomized set of choices, and an epilog."
+  ### assumes TEXT is a list of strings. correct?
+
+  found = False
 
   prolog = [ ]
   choices = [ ]
   epilog = [ ]
 
+  for line in text:
+    match = _RE_CHOICE.match(line)
+    if match:
+      found = True
+      choices.append(line)
+    elif found:
+      epilog.append(line)
+    else:
+      prolog.append(line)
+
+  random.shuffle(choices)
   return prolog, choices, epilog
 
 
 def ballots(text):
-  ### todo
+  "Return the list of possible ballot choices within TEXT."
+  ### assumes TEXT is a list of strings. correct?
+
+  choices = [ ]
 
-  ballots = [ ]
+  for line in text:
+    match = _RE_CHOICE.match(line)
+    if match:
+      choices.append(match.group(1))
 
-  return ballots
+  return choices


Reply via email to