X-Git-Url: https://git.phdru.name/?p=sqlconvert.git;a=blobdiff_plain;f=mysql2sql%2Fprint_tokens.py;h=3e2b0d5cab08be97bba84a777fe52ceddb422fca;hp=142391fbe05196497b25396a571072765d099ea5;hb=4c93c3d89685aba33fc45082022373eb93b6583e;hpb=c86449d39cde438e153055e0f7731f0d15b62964 diff --git a/mysql2sql/print_tokens.py b/mysql2sql/print_tokens.py index 142391f..3e2b0d5 100644 --- a/mysql2sql/print_tokens.py +++ b/mysql2sql/print_tokens.py @@ -2,10 +2,15 @@ import sys -def print_tokens(token_list, outfile=sys.stdout): +def print_tokens(token_list, outfile=sys.stdout, encoding=None): + if encoding: + outfile = getattr(outfile, 'buffer', outfile) for token in token_list.flatten(): - outfile.write(token.normalized) + normalized = token.normalized + if encoding: + normalized = normalized.encode(encoding) + outfile.write(normalized) def tlist2str(token_list): - return ''.join(token.normalized for token in token_list.flatten()) + return u''.join(token.normalized for token in token_list.flatten())