Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit afd44de

Browse files
committed
Hardcode the recognized whitespace characters to the US-ASCII whitespace
chars. See the comment for rationale.
1 parent b5bfb9f commit afd44de

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

Lib/textwrap.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212

1313
import string, re
1414

15+
# Hardcode the recognized whitespace characters to the US-ASCII
16+
# whitespace characters. The main reason for doing this is that in
17+
# ISO-8859-1, 0xa0 is non-breaking whitespace, so in certain locales
18+
# that character winds up in string.whitespace. Respecting
19+
# string.whitespace in those cases would 1) make textwrap treat 0xa0 the
20+
# same as any other whitespace char, which is clearly wrong (it's a
21+
# *non-breaking* space), 2) possibly cause problems with Unicode,
22+
# since 0xa0 is not in range(128).
23+
whitespace = '\t\n\x0b\x0c\r '
24+
1525
class TextWrapper:
1626
"""
1727
Object for wrapping/filling text. The public interface consists of
@@ -48,12 +58,11 @@ class TextWrapper:
4858
be broken, and some lines might be longer than 'width'.
4959
"""
5060

51-
whitespace_trans = string.maketrans(string.whitespace,
52-
' ' * len(string.whitespace))
61+
whitespace_trans = string.maketrans(whitespace, ' ' * len(whitespace))
5362

5463
unicode_whitespace_trans = {}
5564
uspace = ord(u' ')
56-
for x in map(ord, string.whitespace):
65+
for x in map(ord, whitespace):
5766
unicode_whitespace_trans[x] = uspace
5867

5968
# This funky little regex is just the trick for splitting

0 commit comments

Comments
 (0)