diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2011-06-10 22:08:10 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2011-06-10 22:08:10 +0200 |
| commit | f6f2e20e4c61d50fbd5cbf0e685b03d8c5927a3a (patch) | |
| tree | a7ab16a37315dbace58d6a87e9d4574eb5b382b2 /sqlparse | |
| parent | 47e7f56a52870bdb278225fc05866efcb5e65a1d (diff) | |
| download | sqlparse-f6f2e20e4c61d50fbd5cbf0e685b03d8c5927a3a.tar.gz | |
Fix removal of comments when strip_comments is True (fixes issue38).
Diffstat (limited to 'sqlparse')
| -rw-r--r-- | sqlparse/filters.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py index b4f252e..813be99 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -57,10 +57,16 @@ class IdentifierCaseFilter(_CaseFilter): class StripCommentsFilter(Filter): + def _get_next_comment(self, tlist): + # TODO(andi) Comment types should be unified, see related issue38 + token = tlist.token_next_by_instance(0, sql.Comment) + if token is None: + token = tlist.token_next_by_type(0, T.Comment) + return token + def _process(self, tlist): - clss = set([x.__class__ for x in tlist.tokens]) - while sql.Comment in clss: - token = tlist.token_next_by_instance(0, sql.Comment) + token = self._get_next_comment(tlist) + while token: tidx = tlist.token_index(token) prev = tlist.token_prev(tidx, False) next_ = tlist.token_next(tidx, False) @@ -73,7 +79,7 @@ class StripCommentsFilter(Filter): tlist.tokens[tidx] = sql.Token(T.Whitespace, ' ') else: tlist.tokens.pop(tidx) - clss = set([x.__class__ for x in tlist.tokens]) + token = self._get_next_comment(tlist) def process(self, stack, stmt): [self.process(stack, sgroup) for sgroup in stmt.get_sublists()] |
