Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dispatch(self, request, http_request=None):
ident = request.get('id')
log.debug('Dispatching request ID: %s', ident)
try:
version = request['jsonrpc']
except KeyError:
log.debug('Missing `jsonrpc` key in request payload')
if ident:
return InvalidRequestError(
ident, 'Missing `jsonrpc` key in request object')
else:
return
if not version == '2.0':
log.debug('Requested unsupported JSON-RPC version: %s', version)
if ident:
return InvalidRequestError(
ident, 'Server supports only version 2.0 of '
'the JSON-RPC protocol')
else:
return
try:
method = request['method']
except KeyError:
log.debug('Dispatching request ID: %s', ident)
try:
version = request['jsonrpc']
except KeyError:
log.debug('Missing `jsonrpc` key in request payload')
if ident:
return InvalidRequestError(
ident, 'Missing `jsonrpc` key in request object')
else:
return
if not version == '2.0':
log.debug('Requested unsupported JSON-RPC version: %s', version)
if ident:
return InvalidRequestError(
ident, 'Server supports only version 2.0 of '
'the JSON-RPC protocol')
else:
return
try:
method = request['method']
except KeyError:
log.debug('Missing `method` key in request payload')
if ident:
return InvalidRequestError(
ident, 'Missing `method` key in request object')
else:
return
try:
if not version == '2.0':
log.debug('Requested unsupported JSON-RPC version: %s', version)
if ident:
return InvalidRequestError(
ident, 'Server supports only version 2.0 of '
'the JSON-RPC protocol')
else:
return
try:
method = request['method']
except KeyError:
log.debug('Missing `method` key in request payload')
if ident:
return InvalidRequestError(
ident, 'Missing `method` key in request object')
else:
return
try:
log.debug('Calling method `%s`', method)
method = self._methods[method]
except KeyError:
log.debug('Method not found: `%s`', method)
if ident:
return MethodNotFoundError(ident, method)
else:
return
args = []
kwargs = {}
def __init__(self, id, message, data=None):
super(InvalidRequestError, self).__init__(
id, message, -32600, data=data)