From e0687d4f9014919dda15fa41b48d7ce8f6ffa401 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Thu, 2 Oct 2014 12:00:47 +0000 Subject: distbuild: base64-encode exec-output messages JSON can only handle unicode strings, but commands can write anything to stdout/stderr, so let's base64 encode the data. --- distbuild-helper | 5 +++-- distbuild/build_controller.py | 7 +++++-- distbuild/initiator.py | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/distbuild-helper b/distbuild-helper index cdc1873e..40e0f7e7 100755 --- a/distbuild-helper +++ b/distbuild-helper @@ -17,6 +17,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.. +import base64 import cliapp import errno import fcntl @@ -231,8 +232,8 @@ class HelperMachine(distbuild.StateMachine): msg = { 'type': 'exec-output', 'id': event.request_id, - stream: data, - other: '', + stream: base64.standard_b64encode(data), + other: base64.standard_b64encode(''), } logging.debug('JsonMachine: sent to parent: %s', repr(msg)) self.jm.send(msg) diff --git a/distbuild/build_controller.py b/distbuild/build_controller.py index 93f97fac..898bcbc1 100644 --- a/distbuild/build_controller.py +++ b/distbuild/build_controller.py @@ -16,6 +16,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.. +import base64 import logging import httplib import traceback @@ -273,8 +274,10 @@ class BuildController(distbuild.StateMachine): distbuild.crash_point() if event.msg['id'] == self._helper_id: - self._artifact_data.add(event.msg['stdout']) - self._artifact_error.add(event.msg['stderr']) + self._artifact_data.add( + base64.standard_b64decode(event.msg['stdout'])) + self._artifact_error.add( + base64.standard_b64decode(event.msg['stderr'])) def _maybe_finish_graph(self, event_source, event): distbuild.crash_point() diff --git a/distbuild/initiator.py b/distbuild/initiator.py index b60700fd..a803c781 100644 --- a/distbuild/initiator.py +++ b/distbuild/initiator.py @@ -16,6 +16,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.. +import base64 import cliapp import logging import random @@ -145,8 +146,8 @@ class Initiator(distbuild.StateMachine): step_name = msg['step_name'] if step_name in self._step_outputs: f = self._step_outputs[step_name] - f.write(msg['stdout']) - f.write(msg['stderr']) + f.write(base64.standard_b64decode(msg['stdout'])) + f.write(base64.standard_b64decode(msg['stderr'])) f.flush() else: logging.warning( -- cgit v1.2.1