Use .flatten() and avoid StringIO - make the output string directly.
import sys
-try:
- from cStringIO import StringIO
-except ImportError:
- try:
- from StringIO import StringIO
- except ImportError:
- from io import StringIO
def print_tokens(token_list, outfile=sys.stdout):
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())
from sqlparse import parse
from mysql2sql.process_tokens import requote_names
-from mysql2sql.print_tokens import get_tokens_str
+from mysql2sql.print_tokens import tlist2str
from tests import main
def test_requote(self):
parsed = parse("select * from `T`")[0]
requote_names(parsed)
- query = get_tokens_str(parsed)
+ query = tlist2str(parsed)
self.assertEqual(query, 'SELECT * FROM "T"')