[Python-checkins] python/dist/src/Lib textwrap.py,1.18,1.19
gward@users.sourceforge.net
gward@users.sourceforge.net
Mon, 09 Dec 2002 08:23:11 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv26875
Modified Files:
textwrap.py
Log Message:
Fix SF bug #622831 (I think): add unicode_whitespace_trans class
attribute, and modify _munge_whitespace() to recognize Unicode strings
and use unicode_whitespace_trans to munge them. Still need to add a
test to make sure I've really fixed the bug.
Index: textwrap.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/textwrap.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** textwrap.py 22 Oct 2002 18:31:50 -0000 1.18
--- textwrap.py 9 Dec 2002 16:23:08 -0000 1.19
***************
*** 52,55 ****
--- 52,59 ----
' ' * len(string.whitespace))
+ unicode_whitespace_trans = {}
+ for c in string.whitespace:
+ unicode_whitespace_trans[ord(unicode(c))] = ord(u' ')
+
# This funky little regex is just the trick for splitting
# text up into word-wrappable chunks. E.g.
***************
*** 100,104 ****
text = text.expandtabs()
if self.replace_whitespace:
! text = text.translate(self.whitespace_trans)
return text
--- 104,111 ----
text = text.expandtabs()
if self.replace_whitespace:
! if isinstance(text, str):
! text = text.translate(self.whitespace_trans)
! elif isinstance(text, unicode):
! text = text.translate(self.unicode_whitespace_trans)
return text