summaryrefslogtreecommitdiff
path: root/sqlparse/sql.py
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2011-04-13 16:04:56 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2011-04-13 16:04:56 +0200
commit47e7f56a52870bdb278225fc05866efcb5e65a1d (patch)
tree1b35d2b9e25a375cbc256fc406c0d55ac979f120 /sqlparse/sql.py
parentea2b23a46b4dacf1d76cdbdaa172e25e3b733466 (diff)
downloadsqlparse-47e7f56a52870bdb278225fc05866efcb5e65a1d.tar.gz
Don't group trailing whitepsace in WHERE clauses (fixes issue35).
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r--sqlparse/sql.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index 8e2e82b..722204d 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -287,16 +287,21 @@ class TokenList(Token):
If *exclude_end* is ``True`` (default is ``False``) the end token
is included too.
"""
+ # FIXME(andi): rename exclude_end to inlcude_end
if exclude_end:
offset = 0
else:
offset = 1
- return self.tokens[
- self.token_index(start):self.token_index(end) + offset]
+ end_idx = self.token_index(end) + offset
+ start_idx = self.token_index(start)
+ return self.tokens[start_idx:end_idx]
- def group_tokens(self, grp_cls, tokens):
+ def group_tokens(self, grp_cls, tokens, ignore_ws=False):
"""Replace tokens by an instance of *grp_cls*."""
idx = self.token_index(tokens[0])
+ if ignore_ws:
+ while tokens and tokens[-1].is_whitespace():
+ tokens = tokens[:-1]
for t in tokens:
self.tokens.remove(t)
grp = grp_cls(tokens)