X-Git-Url: https://git.phdru.name/?p=sqlconvert.git;a=blobdiff_plain;f=sqlconvert%2Fprint_tokens.py;h=a0a4f8b05bcbc651b232b5cc636c952c8ab760fc;hp=3e2b0d5cab08be97bba84a777fe52ceddb422fca;hb=6b991d668a6f384e272fb19f09187a2d9407f1b3;hpb=0828f8d2a8cf32c7b3df3f9ee46e7de505a0ed9a diff --git a/sqlconvert/print_tokens.py b/sqlconvert/print_tokens.py index 3e2b0d5..a0a4f8b 100644 --- a/sqlconvert/print_tokens.py +++ b/sqlconvert/print_tokens.py @@ -4,12 +4,15 @@ import sys def print_tokens(token_list, outfile=sys.stdout, encoding=None): if encoding: - outfile = getattr(outfile, 'buffer', outfile) + buffer = getattr(outfile, '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):