#NEWLINE# @ contextlib . contextmanager #NEWLINE# def tempdir( **kwargs ) : #NEWLINE# #INDENT# argdict = kwargs . copy ( ) #NEWLINE# if ( 'dir' not in argdict ) : #NEWLINE# #INDENT# argdict [ 'dir' ] = CONF . tempdir #NEWLINE# #UNINDENT# tmpdir = tempfile . mkdtemp ( ** argdict ) #NEWLINE# try : #NEWLINE# #INDENT# ( yield tmpdir ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# shutil . rmtree ( tmpdir ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# LOG . error ( _LE ( 'Could not remove tmpdir: %s' ) , e )