From 0691a8c8a38485745098b21cf46f8dac655a0b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22Piranna=22?= Date: Wed, 21 Mar 2012 18:38:39 +0100 Subject: Clean-up and comments of StripWhitespace --- sqlparse/filters.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/filters.py b/sqlparse/filters.py index d54105e..a639f7a 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -76,23 +76,30 @@ class StripComments(Filter): def StripWhitespace(stream): - """Strip the whitespaces from a stream""" + """Strip the whitespaces from a stream leaving only one between tokens""" last_type = None for token_type, value in stream: - if last_type == None: - if token_type not in Whitespace + Punctuation: - yield token_type, value - last_type = token_type + print repr(token_type), repr(value) + # We got a previous token + if last_type: + print '\t 1', repr(token_type), repr(value) - else: if token_type in Whitespace: - if last_type not in Whitespace: - yield token_type, ' ' - else: - yield token_type, value + if last_type in Whitespace: + continue + value = ' ' + + # Ignore first empty spaces and dot-commas + elif token_type in Whitespace + Punctuation: + continue + + # There's no previous token + else: + print '\t 2', repr(token_type), repr(value) - last_type = token_type + yield token_type, value + last_type = token_type class IncludeStatement(Filter): -- cgit v1.2.1