@contextlib.contextmanager<EOL>def tempfile_writer(target):
tmp = target.parent / ('<STR_LIT>' % target.name)<EOL>try:<EOL><INDENT>with tmp.open('<STR_LIT:wb>') as fd:<EOL><INDENT>yield fd<EOL><DEDENT><DEDENT>except:<EOL><INDENT>tmp.unlink()<EOL>raise<EOL><DEDENT>LOG.debug('<STR_LIT>', tmp, target)<EOL>tmp.rename(target)<EOL>
write cache data to a temporary location.  when writing is
    complete, rename the file to the actual location.  delete
    the temporary file on any error