mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 03:08:27 +08:00
pyon: bytes support
This commit is contained in:
parent
dda5c167b8
commit
3c50610f3d
@ -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]) + ", )"
|
||||
|
Loading…
Reference in New Issue
Block a user