--- Lib/textwrap.py 2008-12-13 23:20:54 +++ Lib/textwrap.py 2010-11-23 20:13:23 @@ -5,7 +5,7 @@ # Copyright (C) 2002, 2003 Python Software Foundation. # Written by Greg Ward -__revision__ = "$Id: textwrap.py 67747 2008-12-13 23:20:54Z antoine.pitrou $" +__revision__ = "$Id: textwrap.py 75232 2009-10-04 14:54:52Z benjamin.peterson $" import string, re @@ -75,7 +75,7 @@ # Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option! # (after stripping out empty strings). wordsep_re = re.compile( - r'(\s+|' # any whitespace + r'(\n|(?:\s(? [string] Split the text to wrap into indivisible chunks. Chunks are - not quite the same as words; see wrap_chunks() for full + not quite the same as words; see _wrap_chunks() for full details. As an example, the text Look, goof-ball -- use the -b option! breaks into the following chunks: @@ -146,7 +146,7 @@ 'use', ' ', 'the', ' ', '-b', ' ', option!' otherwise. """ - if self.break_on_hyphens is True: + if self.break_on_hyphens: chunks = self.wordsep_re.split(text) else: chunks = self.wordsep_simple_re.split(text) @@ -247,6 +247,10 @@ del chunks[-1] while chunks: + if chunks[-1] == '\n': + chunks.pop() + break + l = len(chunks[-1]) # Can at least squeeze this chunk onto the current line.