1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 11:28:14 +00:00

use isinstance to detect whether result is protobuf message

This commit is contained in:
Pavol Rusnak 2017-07-10 18:20:32 +02:00
parent 1727b9a9b6
commit 5ffc700f0c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -75,8 +75,8 @@ def cli(ctx, transport, path, verbose, is_json):
@cli.resultcallback()
def print_result(res, transport, path, verbose, is_json):
if is_json:
if hasattr(res, '__module__') and res.__module__ == 'messages_pb2':
from google.protobuf import json_format
from google.protobuf import json_format, message
if isinstance(res, message.Message):
click.echo(json_format.MessageToJson(res, preserving_proto_field_name=True))
else:
click.echo(json.dumps(res, sort_keys=True, indent=4))