This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: textwrap wordsep_re
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: gward Nosy List: gward, quarl
Priority: normal Keywords: patch

Created on 2005-02-23 01:10 by quarl, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
textwrap-numbers.patch quarl, 2005-02-27 18:29
Messages (3)
msg47844 - (view) Author: Karl Chen (quarl) Date: 2005-02-23 01:10
The following patch makes textwrap not consider strings
of numbers with dashes to be wrappable hyphenated words.

For example, this code:
    print textwrap.fill('aaaaaaaaaa 2005-02-21', 18)
previously produces:
    aaaaaaaaaa 2005-
    02-21

but with patch:
    aaaaaaaaaa
    2005-02-21


--- /usr/lib/python2.4/textwrap.py	2005-02-09
04:02:11.000000000 -0800
+++ /tmp/textwrap.py	2005-02-22 17:07:19.000000000 -0800
@@ -79,7 +79,7 @@
     #   Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/
/the/ /-b/ /option!
     # (after stripping out empty strings).
     wordsep_re = re.compile(r'(\s+|'                 
# any whitespace
-                           
r'[^\s\w]*\w{2,}-(?=\w{2,})|' # hyphenated words
+                           
r'[^\s\w]*\w+[a-zA-Z]-(?=\w+[a-zA-Z])|' # hyphenated words
                            
r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))')   # em-dash
 
     # XXX this is not locale- or charset-aware --
string.lowercase
msg47845 - (view) Author: Karl Chen (quarl) Date: 2005-02-27 18:29
Logged In: YES 
user_id=599526

Assigned to gward as requested.

The attached patch also contains an additional unit test
that fails without this fix.

To apply: cd Python-2.4 && patch -p6 < testwrap.patch
msg47846 - (view) Author: Greg Ward (gward) (Python committer) Date: 2005-03-05 02:58
Logged In: YES 
user_id=14422

Thank you!  Checked in on release24-maint branch:
  Lib/textwrap.py rev 1.35.4.1
  Lib/test/test_textwrap.py,v rev 1.27.4.1

Merged onto trunk:
  Lib/textwrap.py rev 1.37
  Lib/test/test_textwrap.py,v rev 1.28
History
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41617
2005-02-23 01:10:48quarlcreate