import re


def parseExcludeAgentCases(spec):
   """
   Parses "exclude-agent-cases" from the spec into a list of pairs
   of agent pattern and case pattern list.
   """
   if spec.has_key("exclude-agent-cases"):
      ee = spec["exclude-agent-cases"]
      pats1 = []
      for e in ee:
         s1 = "^" + e.replace('.', '\.').replace('*', '.*') + "$"
         p1 = re.compile(s1)
         pats2 = []
         for z in ee[e]:
            s2 = "^" + z.replace('.', '\.').replace('*', '.*') + "$"
            p2 = re.compile(s2)
            pats2.append(p2)
         pats1.append((p1, pats2))
      return pats1
   else:
      return []