本文整理汇总了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')
示例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
示例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
示例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')
示例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')
示例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')
示例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')
示例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
示例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'])
示例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"))
示例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()
示例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')
示例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)
示例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')
示例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)