This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: textwrap fails on unicode using defaults
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gward Nosy List: gward, loewis, r.david.murray
Priority: normal Keywords:

Created on 2002-10-14 04:07 by r.david.murray, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (5)
msg12767 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2002-10-14 04:07
I don't know if this is a module bug or a documentation bug.  I'm
using the documentation from the manual on python.org.

>>> x = TextWrapper()
>>> x.wrap(u'abcd')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.3/textwrap.py", line 239, in wrap
    text = self._munge_whitespace(text)
  File "/usr/local/lib/python2.3/textwrap.py", line 99, in _munge_whitespace
    text = text.translate(self.whitespace_trans)
TypeError: character mapping must return integer, None or unicode

If you do x.replace_whitespace = True, then it will wrap the text.

So either whitespace replacement needs to be fixed, or the docs
need to be updated to note that you have to set replace_whitespace
to false if you want to wrap unicode.
msg12768 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-10-14 12:48
Logged In: YES 
user_id=21627

Greg, can you take a look?
msg12769 - (view) Author: Greg Ward (gward) (Python committer) Date: 2002-10-22 18:30
Logged In: YES 
user_id=14422

I'm almost competely ignorant of Unicode, and so is textwrap.py.  
I'll try to get help on python-dev to fix this, or figure it out myself.  
Failing that, the inability to handle Unicode should be documented.
msg12770 - (view) Author: Greg Ward (gward) (Python committer) Date: 2002-12-09 16:24
Logged In: YES 
user_id=14422

Hopefully fixed in rev 1.19 of textwrap.py.  Not in test
suite yet, so I'm leaving this one "pending".
msg12771 - (view) Author: Greg Ward (gward) (Python committer) Date: 2002-12-09 16:33
Logged In: YES 
user_id=14422

OK, tested in rev 1.18 of test/test_textwrap.py.
History
Date User Action Args
2022-04-10 16:05:45adminsetgithub: 37320
2002-10-14 04:07:44rdmurraycreate