Fix the default placeholder in textwrap.shorten() to be " [...]".

For some reason I forgot to do it before committing the patch in issue #18585.
This commit is contained in:
Antoine Pitrou 2013-08-16 22:31:12 +02:00
parent 05eafa887b
commit c593056744
3 changed files with 11 additions and 11 deletions

View File

@ -40,7 +40,7 @@ functions should be good enough; otherwise, you should use an instance of
:func:`wrap`. :func:`wrap`.
.. function:: shorten(text, width=70, *, placeholder=" (...)") .. function:: shorten(text, width=70, *, placeholder=" [...]")
Collapse and truncate the given text to fit in the given width. Collapse and truncate the given text to fit in the given width.
@ -51,7 +51,7 @@ functions should be good enough; otherwise, you should use an instance of
>>> textwrap.shorten("Hello world!", width=12) >>> textwrap.shorten("Hello world!", width=12)
'Hello world!' 'Hello world!'
>>> textwrap.shorten("Hello world!", width=11) >>> textwrap.shorten("Hello world!", width=11)
'Hello (...)' 'Hello [...]'
>>> textwrap.shorten("Hello world", width=10, placeholder="...") >>> textwrap.shorten("Hello world", width=10, placeholder="...")
'Hello...' 'Hello...'
@ -268,7 +268,7 @@ hyphenated words; only then will long words be broken if necessary, unless
containing the wrapped paragraph. containing the wrapped paragraph.
.. function:: shorten(text, *, placeholder=" (...)") .. function:: shorten(text, *, placeholder=" [...]")
Collapse and truncate the given text to fit in :attr:`width` Collapse and truncate the given text to fit in :attr:`width`
characters. characters.

View File

@ -786,11 +786,11 @@ class ShortenTestCase(BaseTestCase):
# Simple case: just words, spaces, and a bit of punctuation # Simple case: just words, spaces, and a bit of punctuation
text = "Hello there, how are you this fine day? I'm glad to hear it!" text = "Hello there, how are you this fine day? I'm glad to hear it!"
self.check_shorten(text, 18, "Hello there, (...)") self.check_shorten(text, 18, "Hello there, [...]")
self.check_shorten(text, len(text), text) self.check_shorten(text, len(text), text)
self.check_shorten(text, len(text) - 1, self.check_shorten(text, len(text) - 1,
"Hello there, how are you this fine day? " "Hello there, how are you this fine day? "
"I'm glad to (...)") "I'm glad to [...]")
def test_placeholder(self): def test_placeholder(self):
text = "Hello there, how are you this fine day? I'm glad to hear it!" text = "Hello there, how are you this fine day? I'm glad to hear it!"
@ -816,13 +816,13 @@ class ShortenTestCase(BaseTestCase):
"breaks and tabs too.") "breaks and tabs too.")
self.check_shorten(text, 61, self.check_shorten(text, 61,
"This is a paragraph that already has line " "This is a paragraph that already has line "
"breaks and (...)") "breaks and [...]")
self.check_shorten("hello world! ", 12, "hello world!") self.check_shorten("hello world! ", 12, "hello world!")
self.check_shorten("hello world! ", 11, "hello (...)") self.check_shorten("hello world! ", 11, "hello [...]")
# The leading space is trimmed from the placeholder # The leading space is trimmed from the placeholder
# (it would be ugly otherwise). # (it would be ugly otherwise).
self.check_shorten("hello world! ", 10, "(...)") self.check_shorten("hello world! ", 10, "[...]")
def test_width_too_small_for_placeholder(self): def test_width_too_small_for_placeholder(self):
wrapper = TextWrapper(width=8) wrapper = TextWrapper(width=8)
@ -831,7 +831,7 @@ class ShortenTestCase(BaseTestCase):
wrapper.shorten("x" * 20, placeholder="(.......)") wrapper.shorten("x" * 20, placeholder="(.......)")
def test_first_word_too_long_but_placeholder_fits(self): def test_first_word_too_long_but_placeholder_fits(self):
self.check_shorten("Helloo", 5, "(...)") self.check_shorten("Helloo", 5, "[...]")
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -19,7 +19,7 @@ __all__ = ['TextWrapper', 'wrap', 'fill', 'dedent', 'indent']
# since 0xa0 is not in range(128). # since 0xa0 is not in range(128).
_whitespace = '\t\n\x0b\x0c\r ' _whitespace = '\t\n\x0b\x0c\r '
_default_placeholder = ' (...)' _default_placeholder = ' [...]'
class TextWrapper: class TextWrapper:
""" """
@ -376,7 +376,7 @@ def shorten(text, width, *, placeholder=_default_placeholder, **kwargs):
>>> textwrap.shorten("Hello world!", width=12) >>> textwrap.shorten("Hello world!", width=12)
'Hello world!' 'Hello world!'
>>> textwrap.shorten("Hello world!", width=11) >>> textwrap.shorten("Hello world!", width=11)
'Hello (...)' 'Hello [...]'
""" """
w = TextWrapper(width=width, **kwargs) w = TextWrapper(width=width, **kwargs)
return w.shorten(text, placeholder=placeholder) return w.shorten(text, placeholder=placeholder)