|
12 | 12 |
|
13 | 13 | import string, re |
14 | 14 |
|
| 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 | + |
15 | 25 | class TextWrapper: |
16 | 26 | """ |
17 | 27 | Object for wrapping/filling text. The public interface consists of |
@@ -48,12 +58,11 @@ class TextWrapper: |
48 | 58 | be broken, and some lines might be longer than 'width'. |
49 | 59 | """ |
50 | 60 |
|
51 | | - whitespace_trans = string.maketrans(string.whitespace, |
52 | | - ' ' * len(string.whitespace)) |
| 61 | + whitespace_trans = string.maketrans(whitespace, ' ' * len(whitespace)) |
53 | 62 |
|
54 | 63 | unicode_whitespace_trans = {} |
55 | 64 | uspace = ord(u' ') |
56 | | - for x in map(ord, string.whitespace): |
| 65 | + for x in map(ord, whitespace): |
57 | 66 | unicode_whitespace_trans[x] = uspace |
58 | 67 |
|
59 | 68 | # This funky little regex is just the trick for splitting |
|
0 commit comments