Commits

anatoly techtonik committed d0c9227

Check rule result for errors

Comments (0)

Files changed (1)

 # [ ] indented prints after every step
 
 def wikify(text, rules):
+  """
+  Replaces text according to the given rules. Guarantees
+  that replacements won't affect each other.
+
+  Raises TypeError when rule returns invalid result.
+  """
   texts = []  # store processed pieces
   subst = []  # store replacements
 
       res = rule(part)
       if res == None:
         continue
+      elif len(res) != 3:
+        raise TypeError(
+          "Rule '%s' returned %d element(s) instead of 3"
+            % (rule.__name__, len(res)))
       else:
         subst.append(res[1])
         # replacing current text with three elements