Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, message='Invalid request.', data=None):
super(InvalidRequest, self).__init__(INVALID_REQUEST, message, data)
def rpc(self, request):
jsonrpc = request.get('jsonrpc')
id = request.get('id')
method = request.get('method')
params = request.get('params', {})
try:
if jsonrpc != JSONRPC_VERSION or id is None or method is None:
raise InvalidRequest()
if method not in self._methods:
msg = 'Method "%s" not found.' % method
raise MethodNotFound(message=msg, data=method)
func = self._methods[method]
try:
if isinstance(params, list):
result = func(*params)
elif isinstance(params, dict):
result = func(**params)
else:
raise InvalidParams()
except ValueError as vex:
raise InvalidParams(message=str(vex),