Skip to content

Commit

Permalink
Be more lenient with string literals from the command line.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed May 9, 2019
1 parent a467eec commit b67c8bc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion simple_rpc/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from argparse import ArgumentParser, FileType, RawDescriptionHelpFormatter
from json import dumps, loads
from json.decoder import JSONDecodeError
from sys import stdout
from time import sleep

Expand Down Expand Up @@ -67,6 +68,13 @@ def _describe_method(method):
return description


def _loads(string):
try:
return loads(string)
except JSONDecodeError:
return string


def rpc_list(handle, device, baudrate, wait):
"""List the device methods.
Expand All @@ -90,7 +98,7 @@ def rpc_call(handle, device, baudrate, wait, name, args):
:arg str name: Method name.
:arg list args: Method parameters.
"""
args_ = list(map(lambda x: _json_utf8_encode(loads(x)), args))
args_ = list(map(lambda x: _json_utf8_encode(_loads(x)), args))

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

0 comments on commit b67c8bc

Please sign in to comment.