From: Oleg Broytman Date: Sun, 14 Aug 2016 12:02:48 +0000 (+0300) Subject: Use .flatten() to avoid recursion X-Git-Tag: 0.0.1~30 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=c3477caa7a2663decd4d363dade4827fc37e18ea;p=sqlconvert.git Use .flatten() to avoid recursion --- diff --git a/mysql2sql/process_tokens.py b/mysql2sql/process_tokens.py index 2e39a2a..ac9930e 100644 --- a/mysql2sql/process_tokens.py +++ b/mysql2sql/process_tokens.py @@ -5,10 +5,8 @@ from sqlparse.tokens import Name, Error def requote_names(token_list): """Remove backticks, quote non-lowercase identifiers""" - for token in token_list: - if isinstance(token, TokenList): - requote_names(token) - elif token.ttype is Name: + for token in token_list.flatten(): + if token.ttype is Name: value = token.value if (value[0] == "`") and (value[-1] == "`"): value = value[1:-1] @@ -20,10 +18,7 @@ def requote_names(token_list): def find_error(token_list): """Find an error""" - for token in token_list: - if isinstance(token, TokenList): - if find_error(token): - return True - elif token.ttype is Error: + for token in token_list.flatten(): + if token.ttype is Error: return True return False