From 590354dbc84fc1c93844c17b4129136fbc6eee15 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 27 Jan 2016 20:43:42 +0100 Subject: [PATCH] pyon: handle \r --- artiq/protocols/pyon.py | 5 ++++- artiq/test/serialization.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/artiq/protocols/pyon.py b/artiq/protocols/pyon.py index 8c4afbbdc..238ff2198 100644 --- a/artiq/protocols/pyon.py +++ b/artiq/protocols/pyon.py @@ -74,7 +74,10 @@ class _Encoder: def encode_str(self, x): # Do not use repr() for JSON compatibility. - tt = {ord("\""): "\\\"", ord("\\"): "\\\\", ord("\n"): "\\n"} + tt = { + ord("\""): "\\\"", ord("\\"): "\\\\", + ord("\n"): "\\n", ord("\r"): "\\r" + } return "\"" + x.translate(tt) + "\"" def encode_bytes(self, x): diff --git a/artiq/test/serialization.py b/artiq/test/serialization.py index 7bcbed5eb..88cf9b18e 100644 --- a/artiq/test/serialization.py +++ b/artiq/test/serialization.py @@ -26,7 +26,7 @@ class PYON(unittest.TestCase): _json_test_object = { "a": "b", "x": [1, 2, {}], - "foo\nbaz\\qux\"": ["bar", 1.2, {"x": "y"}], + "foo\nbaz\\qux\"\r2": ["bar", 1.2, {"x": "y"}], "bar": [True, False, None] }