Bug 991866 - Decode mozprocess output before printing to stdout, r=gps
☠☠ backed out by ad91b00b5af9 ☠ ☠
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 04 Jun 2014 15:00:01 -0400
changeset 206977 12536416d070ca1cfc4e2bdf0e9b1ec5d426c61a
parent 206976 504404fcc7dc988b88c4a7bcadbea79e83c64a04
child 206978 d8b1d6c4dd4eed28ff92a78b182b66d902f89514
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs991866
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 991866 - Decode mozprocess output before printing to stdout, r=gps
testing/mozbase/mozprocess/mozprocess/processhandler.py
--- a/testing/mozbase/mozprocess/mozprocess/processhandler.py
+++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py
@@ -903,24 +903,34 @@ class StoreOutput(object):
     def __init__(self):
         self.output = []
 
     def __call__(self, line):
         self.output.append(line)
 
 class StreamOutput(object):
     """pass output to a stream and flush"""
+    encodings = ['utf-8', 'iso8859-1']
 
     def __init__(self, stream):
         self.stream = stream
 
     def __call__(self, line):
-        self.stream.write(line + '\n')
+        self.stream.write(self.decode(line) + '\n')
         self.stream.flush()
 
+    def decode(self, line):
+        exc_info = None
+        for encoding in self.encodings:
+            try:
+                return line.decode(encoding, 'replace')
+            except UnicodeDecodeError:
+                exc_info = sys.exc_info()
+        raise exc_info[0], exc_info[1], exc_info[2]
+
 class LogOutput(StreamOutput):
     """pass output to a file"""
 
     def __init__(self, filename):
         self.file_obj = open(filename, 'a')
         StreamOutput.__init__(self, self.file_obj)
 
     def __del__(self):