#NEWLINE# def follow_messages( so , stdout , stderr ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# resp = follow_events ( so [ 'basedir' ] , 'messages' , catchup = True ) #NEWLINE# if ( resp . status != 200 ) : #NEWLINE# #INDENT# ( ( print >> stderr ) , 'Error:' , resp . status , resp . reason ) #NEWLINE# return 1 #NEWLINE# #UNINDENT# while True : #NEWLINE# #INDENT# ( fieldname , value ) = get_field ( stderr ) #NEWLINE# if ( fieldname == 'data' ) : #NEWLINE# #INDENT# data = json . loads ( value ) #NEWLINE# if ( data [ 'type' ] == 'inbound-messages' ) : #NEWLINE# #INDENT# stdout . write ( render_message ( data [ 'new_value' ] ) ) #NEWLINE# stdout . flush ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except ( KeyboardInterrupt , EOFError ) : #NEWLINE# #INDENT# return 0