[Python-checkins] python/dist/src/Lib textwrap.py,1.21,1.22

gward@users.sourceforge.net gward@users.sourceforge.net
Thu, 12 Dec 2002 09:24:37 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv19256

Modified Files:
	textwrap.py 
Log Message:
Hardcode the recognized whitespace characters to the US-ASCII whitespace
chars.  See the comment for rationale.


Index: textwrap.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/textwrap.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** textwrap.py	11 Dec 2002 13:54:20 -0000	1.21
--- textwrap.py	12 Dec 2002 17:24:35 -0000	1.22
***************
*** 13,16 ****
--- 13,26 ----
  import string, re
  
+ # Hardcode the recognized whitespace characters to the US-ASCII
+ # whitespace characters.  The main reason for doing this is that in
+ # ISO-8859-1, 0xa0 is non-breaking whitespace, so in certain locales
+ # that character winds up in string.whitespace.  Respecting
+ # string.whitespace in those cases would 1) make textwrap treat 0xa0 the
+ # same as any other whitespace char, which is clearly wrong (it's a
+ # *non-breaking* space), 2) possibly cause problems with Unicode,
+ # since 0xa0 is not in range(128).
+ whitespace = '\t\n\x0b\x0c\r '
+ 
  class TextWrapper:
      """
***************
*** 49,58 ****
      """
  
!     whitespace_trans = string.maketrans(string.whitespace,
!                                         ' ' * len(string.whitespace))
  
      unicode_whitespace_trans = {}
      uspace = ord(u' ')
!     for x in map(ord, string.whitespace):
          unicode_whitespace_trans[x] = uspace
  
--- 59,67 ----
      """
  
!     whitespace_trans = string.maketrans(whitespace, ' ' * len(whitespace))
  
      unicode_whitespace_trans = {}
      uspace = ord(u' ')
!     for x in map(ord, whitespace):
          unicode_whitespace_trans[x] = uspace