'Create a tempfile containing defined content'

def _create_content_tempfile(self, content):

    (fd, content_tempfile) = tempfile.mkstemp()
    f = os.fdopen(fd, 'wb')
    content = to_bytes(content)
    try:
        f.write(content)
    except Exception as err:
        os.remove(content_tempfile)
        raise Exception(err)
    finally:
        f.close()
    return content_tempfile
