From 033aa33c9e789afedb018c74a339deda71e8381e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 15 Jun 2016 19:18:46 +0800 Subject: [PATCH] pyon: support slices --- artiq/protocols/pyon.py | 5 +++++ artiq/test/test_serialization.py | 1 + artiq/test/test_sync_struct.py | 1 + 3 files changed, 7 insertions(+) diff --git a/artiq/protocols/pyon.py b/artiq/protocols/pyon.py index 28ee7e904..20a89e355 100644 --- a/artiq/protocols/pyon.py +++ b/artiq/protocols/pyon.py @@ -40,6 +40,7 @@ _encode_map = { list: "list", set: "set", dict: "dict", + slice: "slice", wrapping_int: "number", Fraction: "fraction", OrderedDict: "ordereddict", @@ -134,6 +135,9 @@ class _Encoder: r += "}" return r + def encode_slice(self, x): + return repr(x) + def encode_fraction(self, x): return "Fraction({}, {})".format(self.encode(x.numerator), self.encode(x.denominator)) @@ -186,6 +190,7 @@ _eval_dict = { "null": None, "false": False, "true": True, + "slice": slice, "int": wrapping_int, "Fraction": Fraction, diff --git a/artiq/test/test_serialization.py b/artiq/test/test_serialization.py index 369c36fd2..e54234e00 100644 --- a/artiq/test/test_serialization.py +++ b/artiq/test/test_serialization.py @@ -9,6 +9,7 @@ from artiq.protocols import pyon _pyon_test_object = { (1, 2): [(3, 4.2), (2, )], + "slice": slice(3), Fraction(3, 4): np.linspace(5, 10, 1), "set": {"testing", "sets"}, "a": np.int8(9), "b": np.int16(-98), "c": np.int32(42), "d": np.int64(-5), diff --git a/artiq/test/test_sync_struct.py b/artiq/test/test_sync_struct.py index e5e950535..fbc199e0f 100644 --- a/artiq/test/test_sync_struct.py +++ b/artiq/test/test_sync_struct.py @@ -18,6 +18,7 @@ def write_test_data(test_dict): test_dict[key] = value test_dict[1.5] = 1.5 test_dict["list"] = [] + test_dict["list"][:] = [34, 31] test_dict["list"].append(42) test_dict["list"].insert(1, 1) test_dict[100] = 0