summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-07-18 09:53:27 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-07-18 09:53:27 +0000
commit4be1620dca24d539573027831b65ffc040bc1ebb (patch)
treefdd50f947baa072f77db990e1feaf082c2de9083
parente8adedb8f3f27d9212caf277b8e8f7c6792a20c2 (diff)
downloadmorph-4be1620dca24d539573027831b65ffc040bc1ebb.tar.gz
Revert distbuild parts of "Make our use of json binary path safe"baserock/richardmaw/bugfix/stop-decoding-distbuild-comms
The "unicode fix" worked for the subset of cases relevant, and only broke distbuild because its tests have not been integrated with ./check, so the fact that it broke for any string ending with a \ escaped notice, if you will excuse the pun. During json.load, the encode option is for specifying the character encoding of the file or string that is being loaded. During json.dump, the encode option is for the encoding of `str` keys and values. The fact that it worked for the set of cases we cared about is a small mystery, probably caused by the strings we happened to give it being valid unicode-escape encoded `str`ings. A full fix would require either converting all these cases to a different format, such as YAML, which will handle input data not being valid Unicode, or pre-processing the data that is passed to `json.dump` to convert all `str` instances to an appropriately escaped `unicode`, and converting back on `json.load`, but this is a quick fix to get the distbuild code working again.
-rw-r--r--distbuild/build_controller.py4
-rw-r--r--distbuild/jm.py4
-rw-r--r--distbuild/serialise.py4
3 files changed, 6 insertions, 6 deletions
diff --git a/distbuild/build_controller.py b/distbuild/build_controller.py
index e0aec24e..987f01f4 100644
--- a/distbuild/build_controller.py
+++ b/distbuild/build_controller.py
@@ -340,7 +340,7 @@ class BuildController(distbuild.StateMachine):
id=self._helper_id,
url=url,
headers={'Content-type': 'application/json'},
- body=json.dumps(artifact_names, encoding='unicode-escape'),
+ body=json.dumps(artifact_names),
method='POST')
request = distbuild.HelperRequest(msg)
@@ -369,7 +369,7 @@ class BuildController(distbuild.StateMachine):
_AnnotationFailed(http_status_code, error_msg))
return
- cache_state = json.loads(event.msg['body'], encoding='unicode-escape')
+ cache_state = json.loads(event.msg['body'])
map_build_graph(self._artifact, set_status)
self.mainloop.queue_event(self, _Annotated())
diff --git a/distbuild/jm.py b/distbuild/jm.py
index 97ee1a0f..69fa5bd1 100644
--- a/distbuild/jm.py
+++ b/distbuild/jm.py
@@ -67,7 +67,7 @@ class JsonMachine(StateMachine):
def send(self, msg):
'''Send a message to the other side.'''
- self.sockbuf.write('%s\n' % json.dumps(msg, encoding='unicode-escape'))
+ self.sockbuf.write('%s\n' % json.dumps(msg))
def close(self):
'''Tell state machine it should shut down.
@@ -91,7 +91,7 @@ class JsonMachine(StateMachine):
line = line.rstrip()
if self.debug_json:
logging.debug('JsonMachine: line: %s' % repr(line))
- msg = json.loads(line, encoding='unicode-escape')
+ msg = json.loads(line)
self.mainloop.queue_event(self, JsonNewMessage(msg))
def _send_eof(self, event_source, event):
diff --git a/distbuild/serialise.py b/distbuild/serialise.py
index 914c3ae4..44d96eee 100644
--- a/distbuild/serialise.py
+++ b/distbuild/serialise.py
@@ -130,7 +130,7 @@ def serialise_artifact(artifact):
encoded_artifacts['_root'] = str(id(artifact))
return json.dumps({'sources': encoded_sources,
- 'artifacts': encoded_artifacts}, encoding='unicode-escape')
+ 'artifacts': encoded_artifacts})
def deserialise_artifact(encoded):
@@ -210,7 +210,7 @@ def deserialise_artifact(encoded):
return artifact
- le_dicts = json.loads(encoded, encoding='unicode-escape')
+ le_dicts = json.loads(encoded)
artifacts_dict = le_dicts['artifacts']
sources_dict = le_dicts['sources']