[Python-checkins] python/dist/src/Lib textwrap.py,1.18,1.19

M.-A. Lemburg mal@lemburg.com
Wed, 11 Dec 2002 11:34:14 +0100


Just van Rossum wrote:
> 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)
 >
>>+     unicode_whitespace_trans = {}
>>+     for c in string.whitespace:
>>+         unicode_whitespace_trans[ord(unicode(c))] = ord(u' ')
>>+ 

This should probably read:

uspace = ord(u' ') # no idea what this gives you on non-ASCII machines
for x in map(ord, string.whitespace):
     unicode_whitespace_trans[x] = uspace

Note that Unicode has many more whitespace characters than the
ones mentioned in string.whitespace, so this approach is not
100% correct.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/