When overridding sys.std* in python2, use binary streams.
authorZac Medico <zmedico@gentoo.org>
Wed, 9 Dec 2009 05:42:26 +0000 (05:42 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 9 Dec 2009 05:42:26 +0000 (05:42 -0000)
svn path=/main/trunk/; revision=14974

pym/_emerge/BinpkgVerifier.py

index 0283883c106a87dda0cbc549cea376e81f54d48d..eebccfa74ede79cc5737e5dc4c236d0d56593474 100644 (file)
@@ -35,13 +35,15 @@ class BinpkgVerifier(AsynchronousTask):
                                # so that we get the right class (otherwise our
                                # code that expects the 'buffer' attribute
                                # will break).
-                               open_func = open
+                               log_file = open(_unicode_encode(self.logfile,
+                                       encoding=_encodings['fs'], errors='strict'),
+                                       mode='a', encoding=_encodings['content'],
+                                       errors='backslashreplace')
                        else:
-                               open_func = codecs.open
-                       log_file = open_func(_unicode_encode(self.logfile,
-                               encoding=_encodings['fs'], errors='strict'),
-                               mode='a', encoding=_encodings['content'],
-                               errors='backslashreplace')
+                               # For python2, sys.std* are expected to be binary streams.
+                               log_file = open(_unicode_encode(self.logfile,
+                                       encoding=_encodings['fs'], errors='strict'),
+                                       mode='ab')
                try:
                        if log_file is not None:
                                sys.stdout = log_file