X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mysql2sql%2Fprint_tokens.py;h=142391fbe05196497b25396a571072765d099ea5;hb=031cc0d6a41717d4c5d7c4659290e05810202eb9;hp=2024c67a948b5fa9c61ce8310f8e65160aea83d4;hpb=3f72ae846b3948ffd4b15416c8e84439d015424c;p=sqlconvert.git diff --git a/mysql2sql/print_tokens.py b/mysql2sql/print_tokens.py index 2024c67..142391f 100644 --- a/mysql2sql/print_tokens.py +++ b/mysql2sql/print_tokens.py @@ -1,26 +1,11 @@ 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_tokens(token_list, outfile=sys.stdout, level=0): - for token in token_list: - if not isinstance(token, TokenList): - outfile.write(token.normalized) - if isinstance(token, TokenList): - print_tokens(token, outfile, level+1) - if level == 0: - outfile.write(';\n') +def print_tokens(token_list, outfile=sys.stdout): + for token in token_list.flatten(): + outfile.write(token.normalized) -def get_tokens_str(token_list): - sio = StringIO() - print_tokens(token_list, outfile=sio) - return sio.getvalue() +def tlist2str(token_list): + return ''.join(token.normalized for token in token_list.flatten())