From 8984e550b07df5e490ebcac4194ee87fc6927844 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Wed, 9 Dec 2015 00:30:16 +0100 Subject: [PATCH] Read from stdin in binary mode an let XML parser deal with encoding. Also write to stdout in binary mode as the output is already encoded. --- scour/scour.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scour/scour.py b/scour/scour.py index a62ee58..cb2d386 100644 --- a/scour/scour.py +++ b/scour/scour.py @@ -3239,11 +3239,20 @@ def parse_args(args=None, ignore_additional_args=False): # GZ: could catch a raised IOError here and report else: # GZ: could sniff for gzip compression here - infile = sys.stdin + # + # open the binary buffer of stdin and let XML parser handle decoding + try: + infile = sys.stdin.buffer + except AttributeError: + infile = sys.stdin if options.outfilename: outfile = maybe_gziped_file(options.outfilename, "wb") else: - outfile = sys.stdout + # open the binary buffer of stdout as the output is already encoded + try: + outfile = sys.stdout.buffer + except AttributeError: + outfile = sys.stdout return options, [infile, outfile]