from sqlparse.sql import TokenList
-def print_subtree(token_list, outfile=sys.stdout, ident=0):
- for token in token_list:
- outfile.write(" "*ident)
- outfile.write(repr(token))
- outfile.write("\n")
- if isinstance(token, TokenList):
- print_subtree(token, outfile, ident+4)
-
-
def print_tokens(token_list, outfile=sys.stdout, level=0):
for token in token_list:
if not isinstance(token, TokenList):
import sys
from sqlparse import parse
from mysql2sql.process_tokens import requote_names
-from mysql2sql.print_tokens import print_tokens, print_subtree
+from mysql2sql.print_tokens import print_tokens
def test():
for parsed in parse(query):
requote_names(parsed)
print_tokens(parsed)
- print_subtree(parsed)
+ parsed._pprint_tree()
print("----------")
parsed = parse(query)[0]
requote_names(parsed)
print_tokens(parsed)
- print_subtree(parsed)
+ parsed._pprint_tree()
if __name__ == '__main__':
if len(sys.argv) != 2: