""" WordWrapping """ import os, sys, string, time, getopt import re def WordWrap(text, cols=70, detect_paragraphs = 0, is_header = 0): text = string.replace(text,"\r\n", "\n") # remove CRLF def nlrepl(matchobj): if matchobj.group(1) != ' ' and matchobj.group(2) != ' ': repl_with = ' ' else: repl_with = '' return matchobj.group(1) + repl_with + matchobj.group(2) if detect_paragraphs: text = re.sub("([^\n])\n([^\n])",nlrepl,text) body = [] i = 0 j = 0 ltext = len(text) while i