def _write_temp(lines, dirpath, fname):
basedir_replacement = _DataSourceFormatMapping(basedir=dirpath)<EOL>derived_attributes_replacement = _DataSourceFormatMapping(<EOL>**{"<STR_LIT>": "<STR_LIT:U+002CU+0020>".join(DERIVED_COLNAMES)}<EOL>)<EOL>filepath = os.path.join(dirpath, fname)<EOL>data_source_formatter = string.Formatter()<EOL>num_lines = <NUM_LIT:0><EOL>with open(filepath, '<STR_LIT:w>') as tmpf:<EOL><INDENT>for l in lines:<EOL><INDENT>if "<STR_LIT>" in l:<EOL><INDENT>out = data_source_formatter.vformat(<EOL>l, (), basedir_replacement)<EOL><DEDENT>elif "<STR_LIT>" in l:<EOL><INDENT>out = data_source_formatter.vformat(<EOL>l, (), derived_attributes_replacement)<EOL><DEDENT>else:<EOL><INDENT>out = l<EOL><DEDENT>tmpf.write(out)<EOL>num_lines += <NUM_LIT:1><EOL><DEDENT><DEDENT>_LOGGER.debug("<STR_LIT>", num_lines, filepath)<EOL>return filepath<EOL>
Note that delete flag is a required argument since it's potentially
dangerous. When writing to a directory path generated by pytest tmpdir
fixture, the file will be deleted after the requesting class/function/etc.
completes execution anyway, but otherwise failure to set the delete flag
could leave lingering files. Perhaps that is desired and intended, but
in general such responsibility should be delegated to the caller.

:param collections.abc.Iterable(str) lines: sequence of
    lines to write to file
:param str dirpath: path to directory in which to place the tempfile
:param str fname: name for file in `dirpath` to which to write `lines`
:return str: full path to written file