#NEWLINE# def echo_json_response( response , pretty , limit = None ) : #NEWLINE# #INDENT# "Wrapper to echo JSON with optional 'pretty' printing. If pretty is not\n    provided explicity and stdout is a terminal (and not redirected or piped),\n    the default will be to indent and sort keys" #NEWLINE# indent = None #NEWLINE# sort_keys = False #NEWLINE# if ( pretty or ( ( pretty is None ) and sys . stdout . isatty ( ) ) ) : #NEWLINE# #INDENT# indent = 2 #NEWLINE# sort_keys = True #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if hasattr ( response , 'json_encode' ) : #NEWLINE# #INDENT# response . json_encode ( click . get_text_stream ( 'stdout' ) , limit = sort_keys , indent = indent , sort_keys = sort_keys ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# res = response . get_raw ( ) #NEWLINE# res = json . dumps ( json . loads ( res ) , indent = 2 , sort_keys = True ) #NEWLINE# click . echo ( res ) #NEWLINE# #UNINDENT# #UNINDENT# except IOError as ioe : #NEWLINE# #INDENT# raise click . ClickException ( str ( ioe ) )