#NEWLINE# def split_lines_wrapping( text , width = 74 , threshold = 82 ) : #NEWLINE# #INDENT# lines = text . splitlines ( ) #NEWLINE# if all ( ( ( len ( line ) <= threshold ) for line in lines ) ) : #NEWLINE# #INDENT# return lines #NEWLINE# #UNINDENT# result = [ ] #NEWLINE# for line in lines : #NEWLINE# #INDENT# if ( len ( line ) <= threshold ) : #NEWLINE# #INDENT# result . append ( line ) #NEWLINE# continue #NEWLINE# #UNINDENT# line_width = 0 #NEWLINE# line_buffer = [ ] #NEWLINE# for piece in _ws_split_re . split ( line ) : #NEWLINE# #INDENT# line_width += len ( piece ) #NEWLINE# if ( line_width > width ) : #NEWLINE# #INDENT# result . append ( '' . join ( line_buffer ) ) #NEWLINE# line_buffer = [ ] #NEWLINE# if ( not piece . isspace ( ) ) : #NEWLINE# #INDENT# line_buffer . append ( piece ) #NEWLINE# line_width = len ( piece ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# line_width = 0 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# line_buffer . append ( piece ) #NEWLINE# #UNINDENT# #UNINDENT# if line_buffer : #NEWLINE# #INDENT# result . append ( '' . join ( line_buffer ) ) #NEWLINE# #UNINDENT# #UNINDENT# return result