Skip to content

Commit b67c8bc

Browse files
committed
Be more lenient with string literals from the command line.
1 parent a467eec commit b67c8bc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

simple_rpc/cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter
22
from json import dumps, loads
3+
from json.decoder import JSONDecodeError
34
from sys import stdout
45
from time import sleep
56

@@ -67,6 +68,13 @@ def _describe_method(method):
6768
return description
6869

6970

71+
def _loads(string):
72+
try:
73+
return loads(string)
74+
except JSONDecodeError:
75+
return string
76+
77+
7078
def rpc_list(handle, device, baudrate, wait):
7179
"""List the device methods.
7280
@@ -90,7 +98,7 @@ def rpc_call(handle, device, baudrate, wait, name, args):
9098
:arg str name: Method name.
9199
:arg list args: Method parameters.
92100
"""
93-
args_ = list(map(lambda x: _json_utf8_encode(loads(x)), args))
101+
args_ = list(map(lambda x: _json_utf8_encode(_loads(x)), args))
94102

95103
with Interface(device, baudrate, wait) as interface:
96104
result = interface.call_method(name, *args_)

0 commit comments

Comments
 (0)