X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mysql2sql%2Fprint_tokens.py;h=0f03d0357f151bc3af02380e9be94bebae0d98a9;hb=51018ab80b945523dc678b80d4dd28191b3fd50c;hp=05af1c1ebbed5697e77c7b6329c743e05f59cfd5;hpb=3289238688d9c3dfefccf143d21f6c406faad9e4;p=sqlconvert.git diff --git a/mysql2sql/print_tokens.py b/mysql2sql/print_tokens.py index 05af1c1..0f03d03 100644 --- a/mysql2sql/print_tokens.py +++ b/mysql2sql/print_tokens.py @@ -1,20 +1,24 @@ import sys +try: + from cStringIO import StringIO +except ImportError: + try: + from StringIO import StringIO + except ImportError: + from io import StringIO from sqlparse.sql import TokenList -def print_subtree(token_list, ident=0): +def print_tokens(token_list, outfile=sys.stdout, level=0): for token in token_list: - print " "*ident, repr(token) + if not isinstance(token, TokenList): + outfile.write(token.normalized) if isinstance(token, TokenList): - print_subtree(token, ident+4) + print_tokens(token, outfile, level+1) -def print_tokens(token_list, level=0): - for token in token_list: - if not isinstance(token, TokenList): - sys.stdout.write(token.normalized) - if isinstance(token, TokenList): - print_tokens(token, level+1) - if level == 0: - print ';' +def get_tokens_str(token_list): + sio = StringIO() + print_tokens(token_list, outfile=sio) + return sio.getvalue()