summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-06-10 13:22:28 +0200
committerJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-06-10 13:22:28 +0200
commit0269aced73a295dea0a57c49dd77ff73031fcdd0 (patch)
tree5cd807efd410ab1d3fddd6e6bb91b810da6e5b92 /sqlparse
parent63f6fc8fc8a2ab19f56cfc8cb8e88ec9fab7c305 (diff)
downloadsqlparse-0269aced73a295dea0a57c49dd77ff73031fcdd0.tar.gz
Added _gentabs() method
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index b075d39..3bd492b 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -289,17 +289,21 @@ class ReindentFilter:
full_offset = len(line) - len(self.char * self.width * self.indent)
return full_offset - self.offset
+ def _gentabs(self, offset):
+ result = ''
+ if self.char == '\t':
+ tabs, offset = divmod(offset, self.width)
+ result += self.char * tabs
+ result += ' ' * offset
+
+ return result
+
def nl(self):
"""
Return an indented new line token
"""
# TODO: newline character should be configurable
- ws = '\n'
- offset = self.indent * self.width + self.offset
- if self.char == '\t':
- tabs, offset = divmod(offset, self.width)
- ws += self.char * tabs
- ws += ' ' * offset
+ ws = '\n' + self._gentabs(self.indent * self.width + self.offset)
return sql.Token(T.Whitespace, ws)
def _split_kwds(self, tlist):
@@ -471,8 +475,9 @@ class ReindentFilter:
ignore = False
for token in identifiers:
if not ignore and not token.ttype:
+ ws = self._gentabs(offset)
tlist.insert_before(token, sql.Token(T.Whitespace,
- " " * offset))
+ ws))
ignore = token.ttype
# Decrease offset the size of the first token