#NEWLINE# @ contextmanager #NEWLINE# def capture( ) : #NEWLINE# #INDENT# old_stdout = sys . stdout #NEWLINE# with StringIO ( ) as tmp : #NEWLINE# #INDENT# sys . stdout = tmp #NEWLINE# try : #NEWLINE# #INDENT# ( yield tmp ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# sys . stdout = old_stdout