#NEWLINE# def get_match_for_text( matcher , text , first ) : #NEWLINE# #INDENT# result = [ ] #NEWLINE# COLOR_MAP = { #NEWLINE# #INDENT# 'delete' : RED , #NEWLINE# 'insert' : GREEN , #NEWLINE# 'replace' : YELLOW , #NEWLINE# #UNINDENT# } #NEWLINE# for ( tag , i1 , i2 , j1 , j2 ) in matcher . get_opcodes ( ) : #NEWLINE# #INDENT# ( start , stop ) = ( ( i1 , i2 ) if first else ( j1 , j2 ) ) #NEWLINE# to_append = text [ start : stop ] #NEWLINE# if ( tag in COLOR_MAP ) : #NEWLINE# #INDENT# to_append = '' . join ( ( COLOR_MAP [ tag ] , to_append , RESET ) ) #NEWLINE# #UNINDENT# result . append ( to_append ) #NEWLINE# #UNINDENT# return '' . join ( result )