Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def receive_packet(socket, header_len=12):
"""Reads the header to get the payload length, then reads the payload."""
header_buf = receive(socket, header_len)
header = dsi.header.parse(header_buf)
payload_buf = receive(socket, header.payload_length)
return dsi.packet.parse(header_buf + payload_buf)
def _read_packet(self):
"""Read a single packet from the data source.
Returns
-------
dict-like object
"""
assert self._socket is not None
# Reads the header to get the payload length, then reads the payload.
header_buf = util.receive(self._socket, dsi.header_len)
header = dsi.header.parse(header_buf)
payload_buf = util.receive(self._socket, header.payload_length)
return dsi.packet.parse(header_buf + payload_buf)
def receive_packet(socket, header_len=12):
"""Reads the header to get the payload length, then reads the payload."""
header_buf = receive(socket, header_len)
header = dsi.header.parse(header_buf)
payload_buf = receive(socket, header.payload_length)
return dsi.packet.parse(header_buf + payload_buf)
def _read_packet(self):
"""Read a single packet from the data source.
Returns
-------
dict-like object
"""
assert self._socket is not None
# Reads the header to get the payload length, then reads the payload.
header_buf = util.receive(self._socket, dsi.header_len)
header = dsi.header.parse(header_buf)
payload_buf = util.receive(self._socket, header.payload_length)
return dsi.packet.parse(header_buf + payload_buf)
def _read_packet(self):
"""Read a single packet from the data source.
Returns
-------
dict-like object
"""
assert self._socket is not None
# Reads the header to get the payload length, then reads the payload.
header_buf = util.receive(self._socket, dsi.header_len)
header = dsi.header.parse(header_buf)
payload_buf = util.receive(self._socket, header.payload_length)
return dsi.packet.parse(header_buf + payload_buf)
def _read_packet(self):
"""Read a single packet from the data source.
Returns
-------
dict-like object
"""
assert self._socket is not None
# Reads the header to get the payload length, then reads the payload.
header_buf = util.receive(self._socket, dsi.header_len)
header = dsi.header.parse(header_buf)
payload_buf = util.receive(self._socket, header.payload_length)
return dsi.packet.parse(header_buf + payload_buf)
error['data'] = self.data
return error
class ParseError(JsonRpcError):
def __init__(self, message='Parse error.', data=None):
super(ParseError, self).__init__(PARSE_ERROR, message, data)
class InvalidRequest(JsonRpcError):
def __init__(self, message='Invalid request.', data=None):
super(InvalidRequest, self).__init__(INVALID_REQUEST, message, data)
class MethodNotFound(JsonRpcError):
def __init__(self, message='Method not found.', data=None):
super(MethodNotFound, self).__init__(METHOD_NOT_FOUND, message, data)
class InvalidParams(JsonRpcError):
def __init__(self, message='Invalid parameters.', data=None):
super(InvalidParams, self).__init__(INVALID_PARAMS, message, data)
class InternalError(JsonRpcError):
def __init__(self, message='Internal error.', data=None):
super(InternalError, self).__init__(INTERNAL_ERROR, message, data)
class ServerError(JsonRpcError):
def __init__(self, message='Server error.', data=None):
self.message = message
self.data = data
def to_json(self):
error = {
'code': self.code,
'message': self.message,
}
if self.data:
error['data'] = self.data
return error
class ParseError(JsonRpcError):
def __init__(self, message='Parse error.', data=None):
super(ParseError, self).__init__(PARSE_ERROR, message, data)
class InvalidRequest(JsonRpcError):
def __init__(self, message='Invalid request.', data=None):
super(InvalidRequest, self).__init__(INVALID_REQUEST, message, data)
class MethodNotFound(JsonRpcError):
def __init__(self, message='Method not found.', data=None):
super(MethodNotFound, self).__init__(METHOD_NOT_FOUND, message, data)
class InvalidParams(JsonRpcError):
def __init__(self, message='Invalid parameters.', data=None):
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),
data=json.dumps(traceback.format_exc()))
except Exception as ex:
raise ServerError(message=str(ex),
data=json.dumps(traceback.format_exc()))
return self._response(id, result)
except JsonRpcError as err:
return jsonrpc_message({
'id': id,
'error': err.to_json()
})
class ParseError(JsonRpcError):
def __init__(self, message='Parse error.', data=None):
super(ParseError, self).__init__(PARSE_ERROR, message, data)
class InvalidRequest(JsonRpcError):
def __init__(self, message='Invalid request.', data=None):
super(InvalidRequest, self).__init__(INVALID_REQUEST, message, data)
class MethodNotFound(JsonRpcError):
def __init__(self, message='Method not found.', data=None):
super(MethodNotFound, self).__init__(METHOD_NOT_FOUND, message, data)
class InvalidParams(JsonRpcError):
def __init__(self, message='Invalid parameters.', data=None):
super(InvalidParams, self).__init__(INVALID_PARAMS, message, data)
class InternalError(JsonRpcError):
def __init__(self, message='Internal error.', data=None):
super(InternalError, self).__init__(INTERNAL_ERROR, message, data)
class ServerError(JsonRpcError):
def __init__(self, message='Server error.', data=None):
super(ServerError, self).__init__(SERVER_ERROR, message, data)
class JsonRpcHandler(object):
def __init__(self, path):