#NEWLINE# def run( self ) : #NEWLINE# #INDENT# self . socket = self . context . socket ( zmq . REP ) #NEWLINE# self . socket . connect ( self . uri ) #NEWLINE# try : #NEWLINE# #INDENT# while True : #NEWLINE# #INDENT# ( cmd , uid , args ) = protocol . msg . extract_request ( self . socket . recv ( ) ) #NEWLINE# try : #NEWLINE# #INDENT# if ( cmd in self . db_commands ) : #NEWLINE# #INDENT# db = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# db = self . databases . get ( uid ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# resp = protocol . msg . format_response ( uid , status = protocol . status . NO_DB ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if db : #NEWLINE# #INDENT# resp = self . handle_cmd ( db , self . commands , cmd , args ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# resp = self . handle_cmd ( None , self . db_commands , cmd , args ) #NEWLINE# #UNINDENT# #UNINDENT# if isinstance ( resp , Multipart ) : #NEWLINE# #INDENT# self . socket . send_multipart ( resp ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . socket . send ( resp ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except zmq . ZMQError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except RuntimeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# self . socket . close ( linger = 0 )