forked from M-Labs/artiq
1
0
Fork 0

pyon: bytes support

This commit is contained in:
Yann Sionneau 2015-02-18 11:18:46 -07:00 committed by Sebastien Bourdeauducq
parent dda5c167b8
commit 3c50610f3d
1 changed files with 5 additions and 0 deletions

View File

@ -32,6 +32,7 @@ _encode_map = {
int: "number",
float: "number",
str: "str",
bytes: "bytes",
tuple: "tuple",
list: "list",
dict: "dict",
@ -61,9 +62,13 @@ class _Encoder:
return str(x)
def encode_str(self, x):
# Do not use repr() for JSON compatibility.
tt = {ord("\""): "\\\"", ord("\\"): "\\\\", ord("\n"): "\\n"}
return "\"" + x.translate(tt) + "\""
def encode_bytes(self, x):
return repr(x)
def encode_tuple(self, x):
if len(x) == 1:
return "(" + self.encode(x[0]) + ", )"