Issue 18725: Multiline shortening - Python tracker (original) (raw)

Created on 2013-08-13 10:12 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
textwrap_max_lines.patch serhiy.storchaka,2013-09-13 07:47 review
textwrap_max_lines_2.patch serhiy.storchaka,2013-10-06 08:29 review
Messages (12)
msg195065 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-08-13 10:12
Functions in the textwrap module works with multiline text except a newly added (in ) the shorten() function. Wrapping and shortening a multiline text using existing textwrap function is not a trivial job. I propose to add two new parameters to the TextWrap class and wrap() and fill() functions: max_lines and placeholder. If the max_lines argument is specified then wrapped text truncated to max_lines and the last line shortened to the width argument. >>>print(textwrap('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', width=40, max_lines=3)) Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore (...) The shorten() function then will be just a particular case of fill() with max_lines=1.
msg195066 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-08-13 10:15
Sounds like a reasonable enhancement to me.
msg195074 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-08-13 13:30
What about newline keyword argument? Are we forcing the newline to be '\n'? Alternate newlines will be useful for Windows platform ('\r\n') and HTML platform ('
').
msg195075 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-08-13 13:49
fill(...) is just '\n'.join(wrap(...)). Directly use wrap() if you need nonstandard newlines.
msg197557 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-09-13 07:47
Here is a patch. It get rid of TextWrap.shorten() because TextWrap.fill() supersedes it and because "placeholder" now a parameter of TextWrap. Module level shorten() is left but I doubt about it.
msg198891 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-03 12:08
Could anyone please review the patch?
msg199046 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-06 08:29
In updated patch fixed a bug with final spaces.
msg200010 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-10-15 18:24
New changeset 2e8c424dc638 by Serhiy Storchaka in branch 'default': Issue #18725: The textwrap module now supports truncating multiline text. http://hg.python.org/cpython/rev/2e8c424dc638
msg200011 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-15 18:25
Antoine has approved this on IRC. Thank you Ezio and Antoine for your reviews.
msg200046 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-10-16 09:47
Serhiy, you forgot to add shorten to __all__.
msg200049 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-10-16 10:08
New changeset 0bd257cd3e88 by Serhiy Storchaka in branch 'default': Add shorten to __all_ (issues #18585 and #18725). http://hg.python.org/cpython/rev/0bd257cd3e88
msg200051 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-16 10:09
Thank you Vajrasky. It's Antoine forgot. ;)
History
Date User Action Args
2022-04-11 14:57:49 admin set github: 62925
2013-10-16 10:09:30 serhiy.storchaka set messages: +
2013-10-16 10:08:46 python-dev set messages: +
2013-10-16 09:47:44 vajrasky set messages: +
2013-10-15 18:25:55 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2013-10-15 18:24:37 python-dev set messages: +
2013-10-06 08:29:49 serhiy.storchaka set files: + textwrap_max_lines_2.patchassignee: serhiy.storchakamessages: +
2013-10-03 12:08:33 serhiy.storchaka set keywords: + needs reviewmessages: +
2013-09-13 07:47:47 serhiy.storchaka set files: + textwrap_max_lines.patchkeywords: + patchmessages: + stage: test needed -> patch review
2013-08-13 13:49:57 serhiy.storchaka set messages: +
2013-08-13 13:30:04 vajrasky set messages: +
2013-08-13 10:38:18 serhiy.storchaka set stage: test needed
2013-08-13 10:15:19 pitrou set messages: +
2013-08-13 10:12:58 serhiy.storchaka create