Skip to content

Commit

Permalink
Fix tab expansion for Python 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
andialbrecht committed Oct 26, 2015
1 parent 6a3effa commit 4aff8c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 7 additions & 5 deletions sqlparse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,15 @@ def add_filter(self, filter_, **options):
filter_ = filter_(**options)
self.filters.append(filter_)

def _expandtabs(self, text):
if self.tabsize > 0:
text = text.expandtabs(self.tabsize)
return text

def _decode(self, text):
if sys.version_info[0] == 3:
if isinstance(text, str):
return text
return self._expandtabs(text)
if self.encoding == 'guess':
try:
text = text.decode('utf-8')
Expand All @@ -243,10 +248,7 @@ def _decode(self, text):
text = text.decode(self.encoding)
except UnicodeDecodeError:
text = text.decode('unicode-escape')

if self.tabsize > 0:
text = text.expandtabs(self.tabsize)
return text
return self._expandtabs(text)

def get_tokens(self, text, unfiltered=False):
"""
Expand Down
2 changes: 0 additions & 2 deletions tests/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def test_negative_numbers(self):
self.assertEqual(tokens[2][0], Number.Integer)
self.assertEqual(tokens[2][1], '-1')

# Somehow this test fails on Python 3.2
@pytest.mark.skipif('sys.version_info >= (3,0)')
def test_tab_expansion(self):
s = "\t"
lex = lexer.Lexer()
Expand Down

0 comments on commit 4aff8c7

Please sign in to comment.