]> git.phdru.name Git - sqlconvert.git/commitdiff
Fix: flush buffer and outfile
authorOleg Broytman <phd@phdru.name>
Wed, 7 Sep 2016 19:48:38 +0000 (22:48 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 7 Sep 2016 19:50:28 +0000 (22:50 +0300)
sqlconvert/print_tokens.py

index 3e2b0d5cab08be97bba84a777fe52ceddb422fca..a0a4f8b05bcbc651b232b5cc636c952c8ab760fc 100644 (file)
@@ -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):