- def _mkcmd(me, cmd, map):
- """Construct the command to be executed, by substituting placeholders."""
- if map is None: return cmd
- return [me.R_PAT.sub(lambda m: me._subst(m.group(1), map), arg)
- for arg in cmd]
+ ## No command map, so assume someone's already done the hard word.
+ if argmap is None: return cmd
+
+ ## Start on building a list of arguments.
+ ww = []
+
+ ## Work through each template argument in turn...
+ for w in cmd:
+
+ ## Firstly, build a list of lists. We'll then take the cartesian
+ ## product of these, and concatenate each of the results.
+ pc = []
+ last = 0
+ for m in me.R_PAT.finditer(w):
+ start, end = m.start(0), m.end(0)
+ if start > last: pc.append([w[last:start]])
+ ch = m.group(1)
+ if ch == '%':
+ pc.append(['%'])
+ else:
+ try: pc.append(argmap[m.group(1)])
+ except KeyError: raise U.ExpectedError, (
+ 500, "Unknown placeholder `%%%s' in command `%s'" % (ch, cmd))
+ last = end
+ if last < len(w): pc.append([w[last:]])
+
+ ## If any of the components is empty then there's nothing to do for
+ ## this word.
+ if not all(pc): continue
+
+ ## Now do all the substitutions.
+ ii = len(pc)*[0]
+ while True:
+ ww.append(''.join(map(lambda v, i: v[i], pc, ii)))
+ i = len(ii) - 1
+ while i >= 0:
+ ii[i] += 1
+ if ii[i] < len(pc[i]): break
+ ii[i] = 0
+ i -= 1
+ else:
+ break
+
+ ## And finally we're done.
+ return ww