summaryrefslogtreecommitdiff
path: root/sqlparse/sql.py
diff options
context:
space:
mode:
authorVictor Uriarte <victor.m.uriarte@intel.com>2016-06-12 21:02:11 -0700
committerVictor Uriarte <victor.m.uriarte@intel.com>2016-06-14 03:28:18 -0700
commit0bcb34cc1514d77446a29c2c636a3f9a653588f2 (patch)
tree318316d80e4c0b70a275ab18807fb82f7e37c58b /sqlparse/sql.py
parenta7ffa646e9c2839999217cc181544a8a4bb9a5fd (diff)
downloadsqlparse-0bcb34cc1514d77446a29c2c636a3f9a653588f2.tar.gz
Remove unused code from sql.py and style up some changes
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r--sqlparse/sql.py45
1 files changed, 7 insertions, 38 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index 54f7d4f..027228d 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -338,16 +338,6 @@ class TokenList(Token):
start = start if isinstance(start, int) else self.token_index(start)
return start + self.tokens[start:].index(token)
- def tokens_between(self, start, end, include_end=True):
- """Return all tokens between (and including) start and end.
-
- If *include_end* is ``False`` (default is ``True``) the end token
- is excluded.
- """
- start_idx = self.token_index(start)
- end_idx = include_end + self.token_index(end)
- return self.tokens[start_idx:end_idx]
-
def group_tokens_between(self, grp_cls, start, end, include_end=True,
extend=False):
"""Replace tokens by an instance of *grp_cls*."""
@@ -357,8 +347,12 @@ class TokenList(Token):
else:
start_idx = self.token_index(start)
- end_idx = self.token_index(end) if not isinstance(end, int) else end
- end_idx += include_end
+ end = end if isinstance(end, int) else self.token_index(end, start_idx)
+ end_idx = end + include_end
+
+ # will be needed later for new group_clauses
+ # while skip_ws and tokens and tokens[-1].is_whitespace():
+ # tokens = tokens[:-1]
if extend and isinstance(start, grp_cls):
subtokens = self.tokens[start_idx + 1:end_idx]
@@ -366,7 +360,7 @@ class TokenList(Token):
grp = start
grp.tokens.extend(subtokens)
del self.tokens[start_idx + 1:end_idx]
- grp.value = start.__str__()
+ grp.value = text_type(start)
else:
subtokens = self.tokens[start_idx:end_idx]
grp = grp_cls(subtokens)
@@ -378,31 +372,6 @@ class TokenList(Token):
return grp
- def group_tokens(self, grp_cls, tokens, skip_ws=False, extend=False):
- """Replace tokens by an instance of *grp_cls*."""
-
- while skip_ws and tokens and tokens[-1].is_whitespace():
- tokens = tokens[:-1]
-
- left = tokens[0]
- idx = self.token_index(left)
-
- if extend and isinstance(left, grp_cls):
- grp = left
- grp.tokens.extend(tokens[1:])
- else:
- grp = grp_cls(tokens)
-
- for token in tokens:
- token.parent = grp
-
- # Improve performance. LOOP(list.remove()) is O(n**2) operation
- self.tokens = [token for token in self.tokens if token not in tokens]
-
- self.tokens.insert(idx, grp)
- grp.parent = self
- return grp
-
def insert_before(self, where, token):
"""Inserts *token* before *where*."""
token.parent = self