summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-10-02 12:00:47 +0000
committerRichard Maw <richard.maw@gmail.com>2014-10-08 12:14:03 +0000
commit2f981e4a5908cdab10d2d0dc2801c5454c2f78d4 (patch)
tree4231edebb47755ec94f737e96779db8611fe36ad
parent5aad0f5a8249f1f20f802aa094343fb9df1a1656 (diff)
downloadmorph-2f981e4a5908cdab10d2d0dc2801c5454c2f78d4.tar.gz
distbuild: yaml-encode messages before json encoding
JSON can only handle unicode strings, but commands can write anything to stdout/stderr, so we do the same trick as for the serialise, and json encode yaml.
-rw-r--r--distbuild/jm.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/distbuild/jm.py b/distbuild/jm.py
index 513c69fa..615100e4 100644
--- a/distbuild/jm.py
+++ b/distbuild/jm.py
@@ -22,6 +22,7 @@ import logging
import os
import socket
import sys
+import yaml
from sm import StateMachine
from stringbuffer import StringBuffer
@@ -79,7 +80,12 @@ class JsonMachine(StateMachine):
def send(self, msg):
'''Send a message to the other side.'''
- self.sockbuf.write('%s\n' % json.dumps(msg))
+ if self.debug_json:
+ logging.debug('JsonMachine: Sending message %s' % repr(msg))
+ s = json.dumps(yaml.safe_dump(msg))
+ if self.debug_json:
+ logging.debug('JsonMachine: As %s' % repr(s))
+ self.sockbuf.write('%s\n' % s)
def close(self):
'''Tell state machine it should shut down.
@@ -103,7 +109,7 @@ class JsonMachine(StateMachine):
line = line.rstrip()
if self.debug_json:
logging.debug('JsonMachine: line: %s' % repr(line))
- msg = json.loads(line)
+ msg = yaml.load(json.loads(line))
self.mainloop.queue_event(self, JsonNewMessage(msg))
def _send_eof(self, event_source, event):