]> git.phdru.name Git - sqlconvert.git/blobdiff - sqlconvert/print_tokens.py
Fix: flush buffer and outfile
[sqlconvert.git] / 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):