当前位置: 首页>>代码示例>>Python>>正文


Python jsonrpc.JSONRPCResponseManager类代码示例

本文整理汇总了Python中jsonrpc.JSONRPCResponseManager的典型用法代码示例。如果您正苦于以下问题:Python JSONRPCResponseManager类的具体用法?Python JSONRPCResponseManager怎么用?Python JSONRPCResponseManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JSONRPCResponseManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: application

def application(request):
    # Dispatcher is dictionary {<method_name>: callable}
    dispatcher["Say.Hello"] = lambda s: "hello " + s["name"]

    response = JSONRPCResponseManager.handle(
        request.data, dispatcher)
    return Response(response.json, mimetype='application/json')
开发者ID:ForkedRepoSnaphy,项目名称:micro,代码行数:7,代码来源:sidecar_server.py

示例2: index

 def index(self):
     try:
         data = cherrypy.request.body.read().decode('utf-8')
     except ValueError:
         raise cherrypy.HTTPError(400, 'Invalid JSON document')
     response = JSONRPCResponseManager.handle(data, dispatcher)
     return response.json
开发者ID:CryptoEquity,项目名称:counterpartyd,代码行数:7,代码来源:api.py

示例3: process

    def process(self, blocking=False):
        """
        Each time this method is called, the socket tries to retrieve data and passes
        it to the JSONRPCResponseManager, which in turn passes the RPC to the
        ExposedObjectCollection.

        In case no data are available, the method does nothing. This behavior is required for
        Lewis where everything is running in one thread. The central loop can call process
        at some point to process remote calls, so the RPC-server does not introduce its own
        infinite processing loop.

        If the server has not been started yet (via :meth:`start_server`), a RuntimeError
        is raised.

        :param blocking: If True, this function will block until it has received data or a timeout
                         is triggered. Default is False to preserve behavior of prior versions.
        """
        if self._socket is None:
            raise RuntimeError('The server has not been started yet, use start_server to do so.')

        try:
            request = self._socket.recv_unicode(flags=zmq.NOBLOCK if not blocking else 0)

            self.log.debug('Got request %s', request)

            try:
                response = JSONRPCResponseManager.handle(request, self._exposed_object)
                self._socket.send_unicode(response.json)

                self.log.debug('Sent response %s', response.json)
            except TypeError as e:
                self._socket.send_json(
                    self._unhandled_exception_response(json.loads(request)['id'], e))
        except zmq.Again:
            pass
开发者ID:DMSC-Instrument-Data,项目名称:plankton,代码行数:35,代码来源:control_server.py

示例4: application

def application(request):
     # Dispatcher is dictionary {<method_name>: callable}
    for func in [get_balance, get_transactions, broadcast_transaction]:
        dispatcher[func.__name__] = func

    response = JSONRPCResponseManager.handle(request.data, dispatcher)
    return Response(response.json, mimetype='application/json')
开发者ID:eudemonia-research,项目名称:mincoin,代码行数:7,代码来源:mockrpc.py

示例5: application

def application(request):
    dispatcher["echo"] = lambda s: s
    dispatcher["barcode"] = processBarcodeImg

    response = JSONRPCResponseManager.handle(
        request.get_data(cache=False, as_text=True), dispatcher)
    return Response(response.json, mimetype='application/json') 
开发者ID:valsallop,项目名称:mii-1516-g1,代码行数:7,代码来源:main.py

示例6: application

def application(request):

    # default status dispatch method (returns "OK")
    dispatcher["Status.Ping"] = lambda: "OK"

    # if we pass in the arg "tictactoe" then we know to accept tictactoe messages
    if sys.argv[1] == "tictactoe":  

        if json.loads(request.data)['params'] is not None:
            jsonLoad = json.loads(request.data)
            gamestate = jsonLoad['params']['gamestate']

        dispatcher["TicTacToe.Error"] = TicTacToe.Error
        dispatcher["TicTacToe.NextMove"] = TicTacToe.NextMove
        dispatcher["TicTacToe.Complete"] = TicTacToe.Complete
    elif sys.argv[1] == 'scrabble':
        s = Scrabble()
        dispatcher["Scrabble.Ping"] = Scrabble.Ping
        pass
        #todo - put scrabble functions in here

    response = JSONRPCResponseManager.handle(
        request.data, dispatcher)
    
    return Response(response.json, mimetype='application/json')
开发者ID:tombasche,项目名称:py-jnr,代码行数:25,代码来源:server.py

示例7: application

def application(request):
    dispatcher["echo"] = lambda s: s
    dispatcher["add"] = lambda a, b: a + b

    response = JSONRPCResponseManager.handle(
        request.data, dispatcher)
    return Response(response.json, mimetype='application/json')
开发者ID:zzpnm003,项目名称:stress_level,代码行数:7,代码来源:jsonserver.py

示例8: serveApplication

    def serveApplication(self, request):
        try:
            rjson = json.loads(request.data.decode("ascii"))
        except:
            apiresponse = Response({}, mimetype="application/json")
            apiresponse.headers.add("Access-Control-Allow-Origin", "*")
            apiresponse.headers.add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,PATCH")
            apiresponse.headers.add("Access-Control-Allow-Headers", "Content-Type, Authorization")
            return apiresponse

        if rjson["method"] in self.RPCDispatcher:
            nargs = len(inspect.getargspec(self.RPCDispatcher[rjson["method"]]).args) - 1

            if len(rjson["params"]) != nargs:
                logger.error('Client invalid request arguments: "%s" %s', rjson["method"], str(rjson["params"]))
            else:
                if rjson["method"].find("get") == -1 and rjson["method"].find("info") == -1:
                    logger.debug("Client request: %s", rjson["method"])
        else:
            logger.error('Client invalid request: "%s" %s', rjson["method"], str(rjson["params"]))

        response = JSONRPCResponseManager.handle(request.data, self.RPCDispatcher)
        apiresponse = Response(response.json, mimetype="application/json")
        apiresponse.headers.add("Access-Control-Allow-Origin", "*")
        apiresponse.headers.add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,PATCH")
        apiresponse.headers.add("Access-Control-Allow-Headers", "Content-Type, Authorization")
        return apiresponse
开发者ID:rmeloni17,项目名称:contractvmd,代码行数:27,代码来源:api.py

示例9: handle

	def handle(self):
		request = recvBytes(self.request)
		self._logger.info("Received request")
		response = JSONRPCResponseManager.handle(request, self.dispatcher)
		sendBytes(self.request, response.json)
		if response.error is not None:
			self._logger.info("Received request, ERROR [%s] %s",
					response.error['code'], response.error['message'])
开发者ID:seoester,项目名称:vycodi,代码行数:8,代码来源:jsonrpc.py

示例10: handle

	def handle(self):
		self.data = self.rfile.readline()
		print("{} wrote:".format(self.client_address[0]))
		print(self.data)
		# msg = json.loads(self.data)
		# meth = msg["method"]
		response = JSONRPCResponseManager.handle(self.data, dispatcher)
		self.wfile.write(response.json.encode("utf-8"))
开发者ID:koo5,项目名称:new_shit,代码行数:8,代码来源:jsonrpc_server.py

示例11: run

 def run(self):
     try:
         while True:
             message = self.rpc_socket.recv_string()
             response = JSONRPCResponseManager.handle(message, self.dispatcher)
             self.rpc_socket.send_string(response.json)
     finally:
         self.gpio_manager.clean_up()
开发者ID:projectweekend,项目名称:pi-gpio-core,代码行数:8,代码来源:core.py

示例12: receive

    def receive(self, request):
        response = None
        try:
            response = JSONRPCResponseManager.handle(
                request.data, dispatcher)
        except Exception:
            response = "Not Found"

        return Response(response.json, mimetype='application/json')
开发者ID:juanjosepablos,项目名称:pineboo,代码行数:9,代码来源:dgi_jsonrpc.py

示例13: select_task

 def select_task(self, data):
     if data:
         data_split = data.splitlines()
         for line in data_split:
             if line:
                 try:
                     self.transport.write(JSONRPCResponseManager.handle(line, dispatcher).json.encode())
                 except TypeError as te:
                     log.warning("Can't send response: %s", te)
开发者ID:LED-Freaks,项目名称:LedD,代码行数:9,代码来源:daemon.py

示例14: application

	def application(self,request):
		# Dispatcher is dictionary {<method_name>: callable}
		dispatcher["echo"] = lambda s: s
		dispatcher["cl2ct_report"] = self.recv_report
		print 'revice data',request.data

		response = JSONRPCResponseManager.handle(
			request.data, dispatcher)
		return Response(response.json, mimetype='application/json')
开发者ID:maomaochonghuang,项目名称:mo_spider,代码行数:9,代码来源:center.py

示例15: on_message

 def on_message(self, message):
     """
     Passes an incoming JSON-RPC message to the dispatcher for processing.
     """
     LOGGER.debug('Message received from {0}: {1}'.format(
         self.request.remote_ip, message))
     response = JSONRPCResponseManager.handle(message, self.dispatcher)
     LOGGER.debug('Sending response to {0}: {1}'.format(
             self.request.remote_ip, response._data))
     self.write_message(response.json)
开发者ID:yeomps,项目名称:opengb,代码行数:10,代码来源:server.py


注:本文中的jsonrpc.JSONRPCResponseManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。