#NEWLINE# def run_with_tempfile( content , function , mode = 'w' ) : #NEWLINE# #INDENT# 'Create a temporary file with the given content, and execute tbe\n    given function after the temporary file has been closed.\n\n    The file is guaranteed to be deleted whether function succeeds or not\n    ' #NEWLINE# f = NamedTemporaryFile ( mode = mode , delete = False ) #NEWLINE# try : #NEWLINE# #INDENT# f . write ( content ) #NEWLINE# f . close ( ) #NEWLINE# return function ( f . name ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# f . close ( ) #NEWLINE# os . remove ( f . name )