@@ -39,8 +39,11 @@ class TextWrapper:
3939 of wrapped output; also counts towards each line's width.
4040 expand_tabs (default: true)
4141 Expand tabs in input text to spaces before further processing.
42- Each tab will become 1 .. 8 spaces, depending on its position in
43- its line. If false, each tab is treated as a single character.
42+ Each tab will become 0 .. 'tabsize' spaces, depending on its position
43+ in its line. If false, each tab is treated as a single character.
44+ tabsize (default: 8)
45+ Expand tabs in input text to 0 .. 'tabsize' spaces, unless
46+ 'expand_tabs' is false.
4447 replace_whitespace (default: true)
4548 Replace all whitespace characters in the input text by spaces
4649 after tab expansion. Note that if expand_tabs is false and
@@ -100,7 +103,8 @@ def __init__(self,
100103 fix_sentence_endings = False ,
101104 break_long_words = True ,
102105 drop_whitespace = True ,
103- break_on_hyphens = True ):
106+ break_on_hyphens = True ,
107+ tabsize = 8 ):
104108 self .width = width
105109 self .initial_indent = initial_indent
106110 self .subsequent_indent = subsequent_indent
@@ -110,6 +114,7 @@ def __init__(self,
110114 self .break_long_words = break_long_words
111115 self .drop_whitespace = drop_whitespace
112116 self .break_on_hyphens = break_on_hyphens
117+ self .tabsize = tabsize
113118
114119
115120 # -- Private methods -----------------------------------------------
@@ -123,7 +128,7 @@ def _munge_whitespace(self, text):
123128 becomes " foo bar baz".
124129 """
125130 if self .expand_tabs :
126- text = text .expandtabs ()
131+ text = text .expandtabs (self . tabsize )
127132 if self .replace_whitespace :
128133 text = text .translate (self .unicode_whitespace_trans )
129134 return text
0 commit comments