#NEWLINE# @ contextmanager #NEWLINE# def modified_env( self , **env ) : #NEWLINE# #INDENT# originals = dict ( os . environ ) #NEWLINE# try : #NEWLINE# #INDENT# for ( key , val ) in env . items ( ) : #NEWLINE# #INDENT# os . environ [ key ] = val #NEWLINE# #UNINDENT# ( yield ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if ( type ( env ) is dict ) : #NEWLINE# #INDENT# for key in env : #NEWLINE# #INDENT# if ( key in originals ) : #NEWLINE# #INDENT# os . environ [ env ] = originals [ key ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( key in os . environ ) : #NEWLINE# #INDENT# del os . environ [ key ]