#NEWLINE# def print_msg( timestamp , src , dst , msg , format_opts , prefix = '' , indent = 0 , output = sys . stdout ) : #NEWLINE# #INDENT# timestr = fromtimestamp ( timestamp ) . strftime ( '%H:%M:%S:%f' ) #NEWLINE# def pretty( part ) : #NEWLINE# #INDENT# if format_opts . pretty_printer : #NEWLINE# #INDENT# pp = pprint . PrettyPrinter ( indent = 4 ) #NEWLINE# part = pp . pformat ( part ) #NEWLINE# #UNINDENT# return part #NEWLINE# #UNINDENT# indent = ( ( ' ' * indent ) if indent else '' ) #NEWLINE# if format_opts . show_header : #NEWLINE# #INDENT# header_line = ( '%sheader: %s\n' % ( indent , pretty ( msg . header ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# header_line = '' #NEWLINE# #UNINDENT# if format_opts . show_fields : #NEWLINE# #INDENT# fields_line = ( '%sfields: %s\n' % ( indent , pretty ( msg . args ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fields_line = '' #NEWLINE# #UNINDENT# if format_opts . json : #NEWLINE# #INDENT# parts = { #NEWLINE# #INDENT# 'time' : timestr , #NEWLINE# 'src' : src , #NEWLINE# 'dst' : dst , #NEWLINE# 'method' : msg . method , #NEWLINE# 'type' : msg . type , #NEWLINE# 'seqid' : msg . seqid , #NEWLINE# #UNINDENT# } #NEWLINE# if format_opts . show_header : #NEWLINE# #INDENT# parts [ 'header' ] = msg . header #NEWLINE# #UNINDENT# if format_opts . show_fields : #NEWLINE# #INDENT# parts [ 'fields' ] = msg . args #NEWLINE# #UNINDENT# outputstr = ( json . dumps ( parts , indent = 4 ) + '\n' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# outputstr = ( '%s[%s] %s -> %s: method=%s, type=%s, seqid=%d\n%s%s' % ( prefix , timestr , src , dst , msg . method , msg . type , msg . seqid , header_line , fields_line ) ) #NEWLINE# #UNINDENT# if format_opts . is_color : #NEWLINE# #INDENT# print_color ( outputstr , src . __hash__ ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output . write ( outputstr ) #NEWLINE# output . flush ( )