def normalize_rest_paragraph(text, line_len=80, indent=''):
 toreport = ''
 lines = []
 line_len = (line_len - len(indent))
 for line in text.splitlines():
  line = (toreport + _NORM_SPACES_RGX.sub(' ', line.strip()))
  toreport = ''
  while (len(line) > line_len):
   (line, toreport) = splittext(line, line_len)
   lines.append((indent + line))
   if toreport:
    line = (toreport + ' ')
    toreport = ''
   else:
    line = ''
  if line:
   lines.append((indent + line.strip()))
 return linesep.join(lines)

def normalize_rest_paragraph ( text , line_len = 80 , indent = '' ) : toreport = '' lines = [ ] line_len = ( line_len - len ( indent ) ) for line in text . splitlines ( ) : line = ( toreport + _NORM_SPACES_RGX . sub ( ' ' , line . strip ( ) ) ) toreport = '' while ( len ( line ) > line_len ) : ( line , toreport ) = splittext ( line , line_len ) lines . append ( ( indent + line ) ) if toreport : line = ( toreport + ' ' ) toreport = '' else : line = '' if line : lines . append ( ( indent + line . strip ( ) ) ) return linesep . join ( lines )
normalize a rest text to display it with a maximum line size and optionally arbitrary indentation .