X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=sqlconvert%2Fprint_tokens.py;h=6aa6fb4dbf81e229c46cc503f94ae78bcae170b3;hb=f759666e045e7bb0a8b2ff3379b9d46c83c37c67;hp=3e2b0d5cab08be97bba84a777fe52ceddb422fca;hpb=159b4e3d7127e719a0dd12013dd54bf05b276ba9;p=sqlconvert.git diff --git a/sqlconvert/print_tokens.py b/sqlconvert/print_tokens.py index 3e2b0d5..6aa6fb4 100644 --- a/sqlconvert/print_tokens.py +++ b/sqlconvert/print_tokens.py @@ -4,12 +4,17 @@ import sys def print_tokens(token_list, outfile=sys.stdout, encoding=None): if encoding: - outfile = getattr(outfile, 'buffer', outfile) + buffer = getattr(outfile, 'buffer', outfile) + else: + buffer = outfile for token in token_list.flatten(): normalized = token.normalized if encoding: normalized = normalized.encode(encoding) - outfile.write(normalized) + buffer.write(normalized) + if buffer is not outfile: + buffer.flush() + outfile.flush() def tlist2str(token_list):