#NEWLINE# def __main_loop( self ) : #NEWLINE# #INDENT# 'The main program loop, reads JSON requests from stdin,\n        writes JSON responses to stdout\n\n        ' #NEWLINE# while True : #NEWLINE# #INDENT# self . result = False #NEWLINE# self . log = [ ] #NEWLINE# self . __request = self . __reader . readline ( ) . rstrip ( ) #NEWLINE# self . _start_time = time . time ( ) #NEWLINE# if ( self . __request == '' ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# obj = json . loads ( self . __request ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# self . log . append ( 'error: cannot parse input "{}"' . format ( self . __request ) ) #NEWLINE# self . __write_response ( ) #NEWLINE# return #NEWLINE# #UNINDENT# method_name = 'do_{}' . format ( obj [ 'method' ] ) #NEWLINE# try : #NEWLINE# #INDENT# method = getattr ( self , method_name ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# self . result = False #NEWLINE# self . log . append ( 'warning: method "{}" is not implemented' . format ( method_name , self . __request ) ) #NEWLINE# self . __write_response ( ) #NEWLINE# continue #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# method ( obj [ 'parameters' ] ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# self . result = False #NEWLINE# self . log . append ( 'error: method "{}" failed to execute' . format ( method_name , self . __request ) ) #NEWLINE# self . __write_response ( ) #NEWLINE# continue #NEWLINE# #UNINDENT# self . __write_response ( )