+20
-19
@@ -11,23 +11,6 @@ from .exceptions import *
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def __handler_execute(handler, query):
|
|
||||||
params = None
|
|
||||||
if 'params' in query:
|
|
||||||
params = query['params']
|
|
||||||
if params is None:
|
|
||||||
response = handler()
|
|
||||||
elif isinstance(params, list):
|
|
||||||
response = handler(*params)
|
|
||||||
elif isinstance(params, dict):
|
|
||||||
response = handler(**params)
|
|
||||||
else:
|
|
||||||
raise InvalidParamsError(
|
|
||||||
id=query['id'],
|
|
||||||
message='Invalid params: {0}'.format(params)
|
|
||||||
)
|
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
class RPC:
|
class RPC:
|
||||||
@@ -113,7 +96,25 @@ class RPC:
|
|||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def __execute(self, query):
|
def __handler_execute(self, handler, query):
|
||||||
|
params = None
|
||||||
|
if 'params' in query:
|
||||||
|
params = query['params']
|
||||||
|
if params is None:
|
||||||
|
response = handler()
|
||||||
|
elif isinstance(params, list):
|
||||||
|
response = handler(*params)
|
||||||
|
elif isinstance(params, dict):
|
||||||
|
response = handler(**params)
|
||||||
|
else:
|
||||||
|
raise InvalidParamsError(
|
||||||
|
id=query['id'],
|
||||||
|
message='Invalid params: {0}'.format(params)
|
||||||
|
)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
def __handler_execute_save(self, query):
|
||||||
"""Выполнение метода
|
"""Выполнение метода
|
||||||
"""
|
"""
|
||||||
result = self.validate(query)
|
result = self.validate(query)
|
||||||
@@ -130,7 +131,7 @@ class RPC:
|
|||||||
handler = self.__handlers[name]
|
handler = self.__handlers[name]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = __handler_execute(handler, query)
|
response = __handler_execute_save(handler, query)
|
||||||
except JSONRPCError as e:
|
except JSONRPCError as e:
|
||||||
log.error(traceback.format_exc())
|
log.error(traceback.format_exc())
|
||||||
response = InternalError(
|
response = InternalError(
|
||||||
|
|||||||
Reference in New Issue
Block a user