#NEWLINE# def clip( text , max_len = 80 ) : #NEWLINE# #INDENT# 'Return text clipped at the last space before or after max_len\n    ' #NEWLINE# end = None #NEWLINE# if ( len ( text ) > max_len ) : #NEWLINE# #INDENT# space_before = text . rfind ( ' ' , 0 , max_len ) #NEWLINE# if ( space_before >= 0 ) : #NEWLINE# #INDENT# end = space_before #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# space_after = text . rfind ( ' ' , max_len ) #NEWLINE# if ( space_after >= 0 ) : #NEWLINE# #INDENT# end = space_after #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( end is None ) : #NEWLINE# #INDENT# end = len ( text ) #NEWLINE# #UNINDENT# return text [ : end ] . rstrip ( )