diff -r 8ed6a627a834 Lib/test/test_textwrap.py --- a/Lib/test/test_textwrap.py Tue Oct 11 04:06:47 2011 +0200 +++ b/Lib/test/test_textwrap.py Tue Oct 11 14:57:01 2011 +0200 @@ -91,6 +91,14 @@ result = wrapper.fill(text) self.check(result, '\n'.join(expect)) + text = "Test\tdefault\t\ttabsize." + expect = ["Test default tabsize."] + self.check_wrap(text, 80, expect) + + text = "Test\tcustom\t\ttabsize." + expect = ["Test custom tabsize."] + self.check_wrap(text, 80, expect, tabsize=4) + def test_fix_sentence_endings(self): wrapper = TextWrapper(60, fix_sentence_endings=True) diff -r 8ed6a627a834 Lib/textwrap.py --- a/Lib/textwrap.py Tue Oct 11 04:06:47 2011 +0200 +++ b/Lib/textwrap.py Tue Oct 11 14:57:01 2011 +0200 @@ -39,8 +39,11 @@ of wrapped output; also counts towards each line's width. expand_tabs (default: true) Expand tabs in input text to spaces before further processing. - Each tab will become 1 .. 8 spaces, depending on its position in - its line. If false, each tab is treated as a single character. + Each tab will become 0 .. 'tabsize' spaces, depending on its position + in its line. If false, each tab is treated as a single character. + tabsize (default: 8) + Expand tabs in input text to 0 .. 'tabsize' spaces, unless + 'expand_tabs' is false. replace_whitespace (default: true) Replace all whitespace characters in the input text by spaces after tab expansion. Note that if expand_tabs is false and @@ -96,6 +99,7 @@ initial_indent="", subsequent_indent="", expand_tabs=True, + tabsize=8, replace_whitespace=True, fix_sentence_endings=False, break_long_words=True, @@ -105,6 +109,7 @@ self.initial_indent = initial_indent self.subsequent_indent = subsequent_indent self.expand_tabs = expand_tabs + self.tabsize = tabsize self.replace_whitespace = replace_whitespace self.fix_sentence_endings = fix_sentence_endings self.break_long_words = break_long_words @@ -123,7 +128,7 @@ becomes " foo bar baz". """ if self.expand_tabs: - text = text.expandtabs() + text = text.expandtabs(self.tabsize) if self.replace_whitespace: text = text.translate(self.unicode_whitespace_trans) return text