summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorVictor Uriarte <victor.m.uriarte@intel.com>2016-06-07 21:13:33 -0700
committerVictor Uriarte <victor.m.uriarte@intel.com>2016-06-09 20:37:18 -0700
commit5468b0a14e082c07c5db4f9d3c7f157c1df920a3 (patch)
tree589798c3e861c658055dcad21c7084dffedcf4df /sqlparse
parent5cfb6ae1e3ee164c8048df0e58840db34da4e2e6 (diff)
downloadsqlparse-5468b0a14e082c07c5db4f9d3c7f157c1df920a3.tar.gz
Clean-up flatten upto
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters/reindent.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/sqlparse/filters/reindent.py b/sqlparse/filters/reindent.py
index 7d0e23a..8b3f7fa 100644
--- a/sqlparse/filters/reindent.py
+++ b/sqlparse/filters/reindent.py
@@ -22,19 +22,20 @@ class ReindentFilter(object):
self._last_stmt = None
def _flatten_up_to_token(self, token):
- """Yields all tokens up to token plus the next one."""
- # helper for _get_offset
- iterator = self._curr_stmt.flatten()
- for t in iterator:
+ """Yields all tokens up to token but excluding current."""
+ if token.is_group():
+ token = next(token.flatten())
+
+ for t in self._curr_stmt.flatten():
yield t
if t == token:
raise StopIteration
def _get_offset(self, token):
raw = ''.join(map(text_type, self._flatten_up_to_token(token)))
- line = raw.splitlines()[-1]
+ line = (raw or '\n').splitlines()[-1]
# Now take current offset into account and return relative offset.
- full_offset = len(line) - len(self.char * (self.width * self.indent))
+ full_offset = len(line) - len(self.char * self.width * self.indent)
return full_offset - self.offset
def nl(self):