#NEWLINE# def toString( self , * args ) : #NEWLINE# #INDENT# if ( len ( args ) == 0 ) : #NEWLINE# #INDENT# programName = self . DEFAULT_PROGRAM_NAME #NEWLINE# start = self . MIN_TOKEN_INDEX #NEWLINE# end = ( self . size ( ) - 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( args ) == 1 ) : #NEWLINE# #INDENT# programName = args [ 0 ] #NEWLINE# start = self . MIN_TOKEN_INDEX #NEWLINE# end = ( self . size ( ) - 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( args ) == 2 ) : #NEWLINE# #INDENT# programName = self . DEFAULT_PROGRAM_NAME #NEWLINE# start = args [ 0 ] #NEWLINE# end = args [ 1 ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( start is None ) : #NEWLINE# #INDENT# start = self . MIN_TOKEN_INDEX #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( start , int ) ) : #NEWLINE# #INDENT# start = start . index #NEWLINE# #UNINDENT# #UNINDENT# if ( end is None ) : #NEWLINE# #INDENT# end = ( len ( self . tokens ) - 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( end , int ) ) : #NEWLINE# #INDENT# end = end . index #NEWLINE# #UNINDENT# #UNINDENT# if ( end >= len ( self . tokens ) ) : #NEWLINE# #INDENT# end = ( len ( self . tokens ) - 1 ) #NEWLINE# #UNINDENT# if ( start < 0 ) : #NEWLINE# #INDENT# start = 0 #NEWLINE# #UNINDENT# rewrites = self . programs . get ( programName ) #NEWLINE# if ( ( rewrites is None ) or ( len ( rewrites ) == 0 ) ) : #NEWLINE# #INDENT# return self . toOriginalString ( start , end ) #NEWLINE# #UNINDENT# buf = StringIO ( ) #NEWLINE# indexToOp = self . reduceToSingleOperationPerIndex ( rewrites ) #NEWLINE# i = start #NEWLINE# while ( ( i <= end ) and ( i < len ( self . tokens ) ) ) : #NEWLINE# #INDENT# op = indexToOp . get ( i ) #NEWLINE# try : #NEWLINE# #INDENT# del indexToOp [ i ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# t = self . tokens [ i ] #NEWLINE# if ( op is None ) : #NEWLINE# #INDENT# buf . write ( t . text ) #NEWLINE# i += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# i = op . execute ( buf ) #NEWLINE# #UNINDENT# #UNINDENT# if ( end == ( len ( self . tokens ) - 1 ) ) : #NEWLINE# #INDENT# for i in sorted ( indexToOp . keys ( ) ) : #NEWLINE# #INDENT# op = indexToOp [ i ] #NEWLINE# if ( op . index >= ( len ( self . tokens ) - 1 ) ) : #NEWLINE# #INDENT# buf . write ( op . text ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return buf . getvalue ( )