def substitute(self, src, names):
        def subs(m):
            indent_level = int(m.group(1))
            args = m.group(0)[:-1].split(',')[1:]
            args = [i.strip() for i in m.group(0)[:-2].split(',')[1:]]
            name, args = args[0], args[1:]
            if name in short_names:
                return short_names[name]
            try:
                repl = getattr(self, 'repl_%s' % name, None)(*args)
            except:
                print 'repl name:', name, args
                raise
            lines = ['%s%s' % (
                '    ' * indent_level,
                line,
            ) for line in repl.split('\n')]
            return "\n".join(lines)
        dst = self.re_p.sub(subs, src)
        for name in names:
            if isinstance(names[name], basestring):
                dst = dst.replace('${%s}' % name, names[name])
        return dst
dataset/ETHPy150Open anandology/pyjamas/pyjs/src/pyjs/builtin/mkbuiltin.py/Replacement.substitute/original