Don't let the linewrapping algorithm churn infinitely.

- Legacy-Id: 3198
This commit is contained in:
Henrik Levkowetz 2011-07-23 12:03:04 +00:00
parent 9766ab39e5
commit 5ae20efdd5

View file

@ -289,10 +289,13 @@ def wrap_text(text, width=72):
else:
wrapped = False
while (len(line) > width) and (" " in line[:width]):
linelength = len(line)
wrapped = True
breakpoint = line.rfind(" ",0,width)
filled += [ line[:breakpoint] ]
line = indent + line[breakpoint+1:]
if len(line) >= linelength:
break
filled += [ line.rstrip() ]
prev_indent = indent
return "\n".join(filled)