#NEWLINE# def modify_document( self , doc ) : #NEWLINE# #INDENT# if self . failed : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# module = self . _runner . new_module ( ) #NEWLINE# if ( not hasattr ( doc , '_CodeHandler__modules' ) ) : #NEWLINE# #INDENT# setattr ( doc , '_CodeHandler__modules' , [ ] ) #NEWLINE# #UNINDENT# doc . __modules . append ( module ) #NEWLINE# old_doc = curdoc ( ) #NEWLINE# set_curdoc ( doc ) #NEWLINE# old_io = self . _monkeypatch_io ( ) #NEWLINE# try : #NEWLINE# #INDENT# def post_check( ) : #NEWLINE# #INDENT# newdoc = curdoc ( ) #NEWLINE# if ( newdoc is not doc ) : #NEWLINE# #INDENT# raise RuntimeError ( ( "%s at '%s' replaced the output document" % ( self . _origin , self . _runner . path ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . _runner . run ( module , post_check ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# self . _unmonkeypatch_io ( old_io ) #NEWLINE# set_curdoc ( old_doc )