mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-04 04:45:16 +00:00
decode json args after sendind over socket
This commit is contained in:
parent
c7f5e3c2d5
commit
8b7a8b1337
1 changed files with 9 additions and 7 deletions
16
electrum
16
electrum
|
@ -258,6 +258,13 @@ def run_command(config, network, password):
|
||||||
wallet = Wallet(storage) if cmd.requires_wallet else None
|
wallet = Wallet(storage) if cmd.requires_wallet else None
|
||||||
# arguments passed to function
|
# arguments passed to function
|
||||||
args = map(lambda x: config.get(x), cmd.params)
|
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
|
# options
|
||||||
args += map(lambda x: config.get(x), cmd.options)
|
args += map(lambda x: config.get(x), cmd.options)
|
||||||
|
|
||||||
|
@ -434,12 +441,7 @@ if __name__ == '__main__':
|
||||||
for i, arg in enumerate(sys.argv):
|
for i, arg in enumerate(sys.argv):
|
||||||
if arg == '-':
|
if arg == '-':
|
||||||
if not sys.stdin.isatty():
|
if not sys.stdin.isatty():
|
||||||
pipe_data = sys.stdin.read()
|
sys.argv[i] = sys.stdin.read()
|
||||||
try:
|
|
||||||
pipe_data = json.loads(pipe_data)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
sys.argv[i] = pipe_data
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise BaseException('Cannot get argument from stdin')
|
raise BaseException('Cannot get argument from stdin')
|
||||||
|
@ -506,7 +508,7 @@ if __name__ == '__main__':
|
||||||
if type(result) in [str, unicode]:
|
if type(result) in [str, unicode]:
|
||||||
print_msg(result)
|
print_msg(result)
|
||||||
elif result is not None:
|
elif result is not None:
|
||||||
if result.get('error'):
|
if type(result) is dir and result.get('error'):
|
||||||
print_stderr(result.get('error'))
|
print_stderr(result.get('error'))
|
||||||
else:
|
else:
|
||||||
print_json(result)
|
print_json(result)
|
||||||
|
|
Loading…
Add table
Reference in a new issue