From 8b7a8b13379612eef6a8e142c69006491811523e Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sun, 30 Aug 2015 17:46:51 +0200 Subject: [PATCH] decode json args after sendind over socket --- electrum | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/electrum b/electrum index 5bd54e1e..66d1e750 100755 --- a/electrum +++ b/electrum @@ -258,6 +258,13 @@ def run_command(config, network, password): wallet = Wallet(storage) if cmd.requires_wallet else None # arguments passed to function args = map(lambda x: config.get(x), cmd.params) + # decode json arguments + def json_decode(x): + try: + return json.loads(x) + except: + return x + args = map(json_decode, args) # options args += map(lambda x: config.get(x), cmd.options) @@ -434,12 +441,7 @@ if __name__ == '__main__': for i, arg in enumerate(sys.argv): if arg == '-': if not sys.stdin.isatty(): - pipe_data = sys.stdin.read() - try: - pipe_data = json.loads(pipe_data) - except: - pass - sys.argv[i] = pipe_data + sys.argv[i] = sys.stdin.read() break else: raise BaseException('Cannot get argument from stdin') @@ -506,7 +508,7 @@ if __name__ == '__main__': if type(result) in [str, unicode]: print_msg(result) elif result is not None: - if result.get('error'): + if type(result) is dir and result.get('error'): print_stderr(result.get('error')) else: print_json(result)