[Python-checkins] python/dist/src/Lib textwrap.py,1.18,1.19
Just van Rossum
just@letterror.com
Wed, 11 Dec 2002 10:40:33 +0100
This checkin makes textwrap fail for me when running python -S ("don't run
site.py"):
Python 2.3a0 (#42, Dec 11 2002, 10:33:42)
[GCC 3.1 20020420 (prerelease)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import textwrap
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/Users/just/code/python_cvs/Lib/textwrap.py", line 15, in ?
class TextWrapper:
File "/Users/just/code/python_cvs/Lib/textwrap.py", line 56, in TextWrapper
unicode_whitespace_trans[ord(unicode(c))] = ord(u' ')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal
not in range(128)
>>>
Just
gward@users.sourceforge.net wrote:
> 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
>
>
>
>
> _______________________________________________
> Python-checkins mailing list
> Python-checkins@python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>