summaryrefslogtreecommitdiff
path: root/distbuild
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-07-11 15:09:14 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-07-11 15:09:14 +0000
commit1a5e3e748a5ea4f48e3e88fa3859db4c186d6ba5 (patch)
treea3748d413eaee6a24dffd6246aa4ec106fc090bf /distbuild
parentce1fedb4e5ab82105853c4f3a8e05fb83f62c18e (diff)
downloadmorph-baserock/richardmaw/bugfix/unicode-safe-json.tar.gz
Make our use of json binary path safebaserock/richardmaw/bugfix/unicode-safe-json
json only accepts unicode. Various APIs such as file paths and environment variables allow binary data, so we need to support this properly. This patch changes every[1] use of json.load or json.dump to escape non-unicode data strings. This appears exactly as it used to if the input was valid unicode, if it isn't it will insert \xabcd escapes in the place of non-unicode data. When loading back in, if json.load is told to unescape it with `encoding='unicode-escape'` then it will convert it back correctly. This change was primarily to support file paths that weren't valid unicode, where this would choke and die. Now it works, but any tools that parsed the metadata need to unescape the paths. [1]: The interface to the remote repo cache uses json data, but I haven't changes its json.load calls to unescape the data, since the repo caches haven't been made to escape the data.
Diffstat (limited to 'distbuild')
-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 987f01f4..e0aec24e 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),
+ body=json.dumps(artifact_names, encoding='unicode-escape'),
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'])
+ cache_state = json.loads(event.msg['body'], encoding='unicode-escape')
map_build_graph(self._artifact, set_status)
self.mainloop.queue_event(self, _Annotated())
diff --git a/distbuild/jm.py b/distbuild/jm.py
index 69fa5bd1..97ee1a0f 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))
+ self.sockbuf.write('%s\n' % json.dumps(msg, encoding='unicode-escape'))
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)
+ msg = json.loads(line, encoding='unicode-escape')
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 44d96eee..914c3ae4 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})
+ 'artifacts': encoded_artifacts}, encoding='unicode-escape')
def deserialise_artifact(encoded):
@@ -210,7 +210,7 @@ def deserialise_artifact(encoded):
return artifact
- le_dicts = json.loads(encoded)
+ le_dicts = json.loads(encoded, encoding='unicode-escape')
artifacts_dict = le_dicts['artifacts']
sources_dict = le_dicts['sources']