[Python-checkins] r60093 - in python/trunk: Lib/test/test_textwrap.py Lib/textwrap.py Misc/NEWS
georg.brandl
python-checkins at python.org
Sat Jan 19 20:48:19 CET 2008
Author: georg.brandl
Date: Sat Jan 19 20:48:19 2008
New Revision: 60093
Modified:
python/trunk/Lib/test/test_textwrap.py
python/trunk/Lib/textwrap.py
python/trunk/Misc/NEWS
Log:
Fix #1146: TextWrap vs words 1-character shorter than the width.
Patch by Quentin Gallet-Gilles.
Modified: python/trunk/Lib/test/test_textwrap.py
==============================================================================
--- python/trunk/Lib/test/test_textwrap.py (original)
+++ python/trunk/Lib/test/test_textwrap.py Sat Jan 19 20:48:19 2008
@@ -398,6 +398,19 @@
' o'],
subsequent_indent = ' '*15)
+ # bug 1146. Prevent a long word to be wrongly wrapped when the
+ # preceding word is exactly one character shorter than the width
+ self.check_wrap(self.text, 12,
+ ['Did you say ',
+ '"supercalifr',
+ 'agilisticexp',
+ 'ialidocious?',
+ '" How *do*',
+ 'you spell',
+ 'that odd',
+ 'word,',
+ 'anyways?'])
+
def test_nobreak_long(self):
# Test with break_long_words disabled
self.wrapper.break_long_words = 0
Modified: python/trunk/Lib/textwrap.py
==============================================================================
--- python/trunk/Lib/textwrap.py (original)
+++ python/trunk/Lib/textwrap.py Sat Jan 19 20:48:19 2008
@@ -173,7 +173,12 @@
Handle a chunk of text (most likely a word, not whitespace) that
is too long to fit in any line.
"""
- space_left = max(width - cur_len, 1)
+ # Figure out when indent is larger than the specified width, and make
+ # sure at least one character is stripped off on every pass
+ if width < 1:
+ space_left = 1
+ else:
+ space_left = width - cur_len
# If we're allowed to break long words, then do so: put as much
# of the next chunk onto the current line as will fit.
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sat Jan 19 20:48:19 2008
@@ -369,6 +369,9 @@
Library
-------
+- #1146: fix how textwrap breaks a long word that would start in the
+ last column of a line.
+
- #1693149: trace.py --ignore-module - accept multiple comma-separated
modules to be given.
More information about the Python-checkins
mailing list