Ejemplo n.º 1
0
 def __call__(self, message, transport, protocol):
     # Handle a new request. This is the handler called by JsonRpcProtocol.
     method = message.get('method')
     if method is None:
         return
     mtype = jsonrpc.message_type(message)
     ismethod = mtype == 'methodcall'
     # Find the right handler
     handler = self._routes.get(method)
     if handler and (handler.request_type is None or handler.request_type != mtype):
         handler = None
     # Export request data to handlers
     self._local.message = message
     self._local.protocol = protocol
     self._local.transport = transport
     self._local.delay_response = False
     # Call into the handlers
     try:
         try:
             params = message.get('params', [])
             self.pre_request_hook(method, *params)
             if handler:
                 if handler.args:
                     handler.args.validate(params)
                 result = handler(*params)
             else:
                 result = self.method_not_found(method, *params)
             if result is not None and not ismethod:
                 self._log.warning('handler returned a value for notification')
             if ismethod:
                 response = jsonrpc.create_response(message, result)
             self.post_request_hook(result)
         except Exception as e:
             self.uncaught_exception(e)
             raise
     except RpcError as e:
         response = jsonrpc.create_error(message, e.code, e.message, e.data)
     except Exception as e:
         response = jsonrpc.create_error(message, jsonrpc.SERVER_ERROR)
     if ismethod and not self._local.delay_response:
         self.protocol.send_message(response)
Ejemplo n.º 2
0
 def method_timeout():
     reply = jsonrpc.create_error(message, jsonrpc.SERVER_ERROR, "Method call timed out")
     replies.append(reply)
Ejemplo n.º 3
0
def echo_app(message, transport, protocol):
    if message.get('method') != 'echo':
        message = jsonrpc.create_error(message, jsonrpc.METHOD_NOT_FOUND)
    else:
        message = jsonrpc.create_response(message, message['params'])
    protocol.send_message(message)
Ejemplo n.º 4
0
def echo_app(message, transport, protocol):
    if message.get('method') != 'echo':
        message = jsonrpc.create_error(message, jsonrpc.METHOD_NOT_FOUND)
    else:
        message = jsonrpc.create_response(message, message['params'])
    protocol.send_message(message)