Copies the src file into dst applying the replacements dict

def _copy_replace(src, dst, replacements):
    """Copies the src file into dst applying the replacements dict"""
    with src.open() as infile, dst.open('w') as outfile:
        outfile.write(re.sub(
            '|'.join(re.escape(k) for k in replacements),
            lambda m: str(replacements[m.group(0)]),
            infile.read()
        ))