mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update textwrap from 3.13.5 (#5952)
This commit is contained in:
23
Lib/textwrap.py
vendored
23
Lib/textwrap.py
vendored
@@ -63,10 +63,7 @@ class TextWrapper:
|
||||
Append to the last line of truncated text.
|
||||
"""
|
||||
|
||||
unicode_whitespace_trans = {}
|
||||
uspace = ord(' ')
|
||||
for x in _whitespace:
|
||||
unicode_whitespace_trans[ord(x)] = uspace
|
||||
unicode_whitespace_trans = dict.fromkeys(map(ord, _whitespace), ord(' '))
|
||||
|
||||
# This funky little regex is just the trick for splitting
|
||||
# text up into word-wrappable chunks. E.g.
|
||||
@@ -479,13 +476,19 @@ def indent(text, prefix, predicate=None):
|
||||
consist solely of whitespace characters.
|
||||
"""
|
||||
if predicate is None:
|
||||
def predicate(line):
|
||||
return line.strip()
|
||||
# str.splitlines(True) doesn't produce empty string.
|
||||
# ''.splitlines(True) => []
|
||||
# 'foo\n'.splitlines(True) => ['foo\n']
|
||||
# So we can use just `not s.isspace()` here.
|
||||
predicate = lambda s: not s.isspace()
|
||||
|
||||
def prefixed_lines():
|
||||
for line in text.splitlines(True):
|
||||
yield (prefix + line if predicate(line) else line)
|
||||
return ''.join(prefixed_lines())
|
||||
prefixed_lines = []
|
||||
for line in text.splitlines(True):
|
||||
if predicate(line):
|
||||
prefixed_lines.append(prefix)
|
||||
prefixed_lines.append(line)
|
||||
|
||||
return ''.join(prefixed_lines)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user