summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>2002-12-09 16:23:08 (GMT)
committerGreg Ward <gward@python.net>2002-12-09 16:23:08 (GMT)
commit2e74541d7e715f3333a3d2bf0e9cac79f3871e0c (patch)
tree2b1c31ae897a779eee6f591564e36efa5fb32bce /Lib
parentef8b9c6616da75f725edf4c8cf0353cb38068cf4 (diff)
downloadcpython-2e74541d7e715f3333a3d2bf0e9cac79f3871e0c.zip
cpython-2e74541d7e715f3333a3d2bf0e9cac79f3871e0c.tar.gz
cpython-2e74541d7e715f3333a3d2bf0e9cac79f3871e0c.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/textwrap.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/textwrap.py b/Lib/textwrap.py
index 2c9592b..fc93b9b 100644
--- a/Lib/textwrap.py
+++ b/Lib/textwrap.py
@@ -51,6 +51,10 @@ class TextWrapper:
whitespace_trans = string.maketrans(string.whitespace,
' ' * 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.
# "Hello there -- you goof-ball, use the -b option!"
@@ -99,7 +103,10 @@ class TextWrapper:
if self.expand_tabs:
text = text.expandtabs()
if self.replace_whitespace:
- text = text.translate(self.whitespace_trans)
+ if isinstance(text, str):
+ text = text.translate(self.whitespace_trans)
+ elif isinstance(text, unicode):
+ text = text.translate(self.unicode_whitespace_trans)
return text