[Python-bugs-list] [ python-Bugs-797650 ] Infinite loop in textwrap.py.

SourceForge.net noreply at sourceforge.net
Sat Aug 30 08:53:49 EDT 2003


Bugs item #797650, was opened at 2003-08-29 21:59
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=797650&group_id=5470

Category: Python Library
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Jeremy Fincher (jemfinch)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Infinite loop in textwrap.py.

Initial Comment:
It seems that textwrap.{wrap,fill} both loop 
infinitely if they're given a subsequent_indent with 
a length greater than the size of the line they're 
trying to construct. 
 
>>> import textwrap 
>>> textwrap.fill('', subsequent_indent=' '*70) 
'' 
>>> textwrap.fill('a', subsequent_indent=' '*70) 
'a' 
>>> textwrap.fill('a'*70, subsequent_indent=' 
'*70) 
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 
>>> textwrap.fill('a'*71, subsequent_indent=' 
'*70) 
Traceback (most recent call last): 
  File "<stdin>", line 1, in ? 
  File "/usr/lib/python2.3/textwrap.py", line 313, in 
fill 
    return w.fill(text) 
  File "/usr/lib/python2.3/textwrap.py", line 285, in 
fill 
    return "\n".join(self.wrap(text)) 
  File "/usr/lib/python2.3/textwrap.py", line 276, in 
wrap 
    return self._wrap_chunks(chunks) 
  File "/usr/lib/python2.3/textwrap.py", line 229, in 
_wrap_chunks 
    while chunks: 
KeyboardInterrupt 
 
Yes, it is stupid for a user to give an indent value 
larger than the size of the line you're accepting, 
but at the very least ValueError should be raised in 
those cases -- it took me awhile to find the bug in 
my code that was causing this :) 
 

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-08-30 09:53

Message:
Logged In: YES 
user_id=80475

Fixed.

See:
  Lib/textwrap.py 1.33 and 1.32.8.1
  Lib/test/test_textwrap.py 1.23 and 1.22.8.1

Thanks for the clear bug report.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=797650&group_id=5470



More information about the Python-bugs-list mailing list