forked from M-Labs/artiq
pyon: bytes support
This commit is contained in:
parent
dda5c167b8
commit
3c50610f3d
|
@ -32,6 +32,7 @@ _encode_map = {
|
||||||
int: "number",
|
int: "number",
|
||||||
float: "number",
|
float: "number",
|
||||||
str: "str",
|
str: "str",
|
||||||
|
bytes: "bytes",
|
||||||
tuple: "tuple",
|
tuple: "tuple",
|
||||||
list: "list",
|
list: "list",
|
||||||
dict: "dict",
|
dict: "dict",
|
||||||
|
@ -61,9 +62,13 @@ class _Encoder:
|
||||||
return str(x)
|
return str(x)
|
||||||
|
|
||||||
def encode_str(self, x):
|
def encode_str(self, x):
|
||||||
|
# Do not use repr() for JSON compatibility.
|
||||||
tt = {ord("\""): "\\\"", ord("\\"): "\\\\", ord("\n"): "\\n"}
|
tt = {ord("\""): "\\\"", ord("\\"): "\\\\", ord("\n"): "\\n"}
|
||||||
return "\"" + x.translate(tt) + "\""
|
return "\"" + x.translate(tt) + "\""
|
||||||
|
|
||||||
|
def encode_bytes(self, x):
|
||||||
|
return repr(x)
|
||||||
|
|
||||||
def encode_tuple(self, x):
|
def encode_tuple(self, x):
|
||||||
if len(x) == 1:
|
if len(x) == 1:
|
||||||
return "(" + self.encode(x[0]) + ", )"
|
return "(" + self.encode(x[0]) + ", )"
|
||||||
|
|
Loading…
Reference in New Issue