mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
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.
This commit is contained in:
parent
ef8b9c6616
commit
2e74541d7e
1 changed files with 8 additions and 1 deletions
|
@ -51,6 +51,10 @@ class TextWrapper:
|
||||||
whitespace_trans = string.maketrans(string.whitespace,
|
whitespace_trans = string.maketrans(string.whitespace,
|
||||||
' ' * len(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
|
# This funky little regex is just the trick for splitting
|
||||||
# text up into word-wrappable chunks. E.g.
|
# text up into word-wrappable chunks. E.g.
|
||||||
# "Hello there -- you goof-ball, use the -b option!"
|
# "Hello there -- you goof-ball, use the -b option!"
|
||||||
|
@ -99,7 +103,10 @@ class TextWrapper:
|
||||||
if self.expand_tabs:
|
if self.expand_tabs:
|
||||||
text = text.expandtabs()
|
text = text.expandtabs()
|
||||||
if self.replace_whitespace:
|
if self.replace_whitespace:
|
||||||
|
if isinstance(text, str):
|
||||||
text = text.translate(self.whitespace_trans)
|
text = text.translate(self.whitespace_trans)
|
||||||
|
elif isinstance(text, unicode):
|
||||||
|
text = text.translate(self.unicode_whitespace_trans)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue