#NEWLINE# def find_delims( s , delim = '"' , match = None ) : #NEWLINE# #INDENT# 'find matching delimeters (quotes, braces, etc) in a string.\n    returns\n      True, index1, index2 if a match is found\n      False, index1, len(s) if a match is not found\n    the delimiter can be set with the keyword arg delim,\n    and the matching delimiter with keyword arg match.\n\n    if match is None (default), match is set to delim.\n\n    >>> find_delims(mystr, delim=":")\n    >>> find_delims(mystr, delim=\'<\', match=\'>\')\n    ' #NEWLINE# ( esc , dbesc ) = ( '\\' , '\\\\' ) #NEWLINE# if ( match is None ) : #NEWLINE# #INDENT# match = delim #NEWLINE# #UNINDENT# j = s . find ( delim ) #NEWLINE# if ( ( j > ( - 1 ) ) and ( s [ j : ( j + len ( delim ) ) ] == delim ) ) : #NEWLINE# #INDENT# ( p1 , p2 , k ) = ( None , None , j ) #NEWLINE# while ( k < ( j + len ( s [ ( j + 1 ) : ] ) ) ) : #NEWLINE# #INDENT# k = ( k + 1 ) #NEWLINE# if ( k > 0 ) : #NEWLINE# #INDENT# p1 = s [ ( k - 1 ) : k ] #NEWLINE# #UNINDENT# if ( k > 1 ) : #NEWLINE# #INDENT# p2 = s [ ( k - 2 ) : k ] #NEWLINE# #UNINDENT# if ( ( s [ k : ( k + len ( match ) ) ] == match ) and ( not ( ( p1 == esc ) and ( p2 != dbesc ) ) ) ) : #NEWLINE# #INDENT# return ( True , j , ( ( k + len ( match ) ) - 1 ) ) #NEWLINE# #UNINDENT# p1 = s [ k : ( k + 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# return ( False , j , len ( s ) )