def subst_vars(target, source, d):
var = re.compile('<STR_LIT>')<EOL>fs = open(source, '<STR_LIT:r>')<EOL>try:<EOL><INDENT>ft = open(target, '<STR_LIT:w>')<EOL>try:<EOL><INDENT>for l in fs:<EOL><INDENT>m = var.search(l)<EOL>if m:<EOL><INDENT>ft.write(l.replace('<STR_LIT>' % m.group(<NUM_LIT:1>), d[m.group(<NUM_LIT:1>)]))<EOL><DEDENT>else:<EOL><INDENT>ft.write(l)<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>ft.close()<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>fs.close()<EOL><DEDENT>
Substitute any occurence of @foo@ by d['foo'] from source file into
    target.