From 6b991d668a6f384e272fb19f09187a2d9407f1b3 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 7 Sep 2016 22:48:38 +0300 Subject: [PATCH] Fix: flush buffer and outfile --- sqlconvert/print_tokens.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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): -- 2.39.5