]> git.phdru.name Git - sqlconvert.git/blob - sqlconvert/print_tokens.py
Fix: flush buffer and outfile
[sqlconvert.git] / sqlconvert / print_tokens.py
1
2 import sys
3
4
5 def print_tokens(token_list, outfile=sys.stdout, encoding=None):
6     if encoding:
7         buffer = getattr(outfile, 'buffer', outfile)
8     for token in token_list.flatten():
9         normalized = token.normalized
10         if encoding:
11             normalized = normalized.encode(encoding)
12         buffer.write(normalized)
13     if buffer is not outfile:
14         buffer.flush()
15     outfile.flush()
16
17
18 def tlist2str(token_list):
19     return u''.join(token.normalized for token in token_list.flatten())