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
1 changed files with 2 additions and 2 deletions

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))