mirror of https://github.com/m-labs/artiq.git
protocols/pyon: set support
This commit is contained in:
parent
8a912105cb
commit
8be0696b39
|
@ -35,6 +35,7 @@ _encode_map = {
|
||||||
bytes: "bytes",
|
bytes: "bytes",
|
||||||
tuple: "tuple",
|
tuple: "tuple",
|
||||||
list: "list",
|
list: "list",
|
||||||
|
set: "set",
|
||||||
dict: "dict",
|
dict: "dict",
|
||||||
wrapping_int: "number",
|
wrapping_int: "number",
|
||||||
Fraction: "fraction",
|
Fraction: "fraction",
|
||||||
|
@ -98,6 +99,12 @@ class _Encoder:
|
||||||
r += "]"
|
r += "]"
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def encode_set(self, x):
|
||||||
|
r = "{"
|
||||||
|
r += ", ".join([self.encode(item) for item in x])
|
||||||
|
r += "}"
|
||||||
|
return r
|
||||||
|
|
||||||
def encode_dict(self, x):
|
def encode_dict(self, x):
|
||||||
r = "{"
|
r = "{"
|
||||||
if not self.pretty or len(x) < 2:
|
if not self.pretty or len(x) < 2:
|
||||||
|
@ -149,9 +156,7 @@ class _Encoder:
|
||||||
|
|
||||||
def encode(x, pretty=False):
|
def encode(x, pretty=False):
|
||||||
"""Serializes a Python object and returns the corresponding string in
|
"""Serializes a Python object and returns the corresponding string in
|
||||||
Python syntax.
|
Python syntax."""
|
||||||
|
|
||||||
"""
|
|
||||||
return _Encoder(pretty).encode(x)
|
return _Encoder(pretty).encode(x)
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,9 +186,7 @@ _eval_dict = {
|
||||||
|
|
||||||
def decode(s):
|
def decode(s):
|
||||||
"""Parses a string in the Python syntax, reconstructs the corresponding
|
"""Parses a string in the Python syntax, reconstructs the corresponding
|
||||||
object, and returns it.
|
object, and returns it."""
|
||||||
|
|
||||||
"""
|
|
||||||
return eval(s, _eval_dict, {})
|
return eval(s, _eval_dict, {})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ from artiq.protocols import pyon
|
||||||
_pyon_test_object = {
|
_pyon_test_object = {
|
||||||
(1, 2): [(3, 4.2), (2, )],
|
(1, 2): [(3, 4.2), (2, )],
|
||||||
Fraction(3, 4): np.linspace(5, 10, 1),
|
Fraction(3, 4): np.linspace(5, 10, 1),
|
||||||
|
{"testing", "sets"},
|
||||||
"a": np.int8(9), "b": np.int16(-98), "c": np.int32(42), "d": np.int64(-5),
|
"a": np.int8(9), "b": np.int16(-98), "c": np.int32(42), "d": np.int64(-5),
|
||||||
"e": np.uint8(8), "f": np.uint16(5), "g": np.uint32(4), "h": np.uint64(9),
|
"e": np.uint8(8), "f": np.uint16(5), "g": np.uint32(4), "h": np.uint64(9),
|
||||||
"x": np.float16(9.0), "y": np.float32(9.0), "z": np.float64(9.0),
|
"x": np.float16(9.0), "y": np.float32(9.0), "z": np.float64(9.0),
|
||||||
|
|
Loading…
Reference in New Issue