]> git.phdru.name Git - sqlconvert.git/commitdiff
Use .flatten() to avoid recursion
authorOleg Broytman <phd@phdru.name>
Sun, 14 Aug 2016 12:02:48 +0000 (15:02 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 14 Aug 2016 12:02:48 +0000 (15:02 +0300)
mysql2sql/process_tokens.py

index 2e39a2a7d8a4677de1052fa64639c088beaa579e..ac9930eb81963b1e0c376ff67af035aaaca37679 100644 (file)
@@ -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