Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_client_raises_error_replies(client, mock_protocol, method_name,
method_args, method_kwargs,
one_way_setting):
error_response = RPCErrorResponse()
error_response.error = 'foo'
mock_protocol.parse_reply = Mock(return_value=error_response)
with pytest.raises(RPCError):
client.call(method_name, method_args, method_kwargs, one_way_setting)
def _send_and_handle_reply(self, req):
# sends and waits for reply
reply = self.transport.send_message(req.serialize())
response = self.protocol.parse_reply(reply)
if hasattr(response, 'error'):
raise RPCError('Error calling remote procedure: %s' %\
response.error)
return response
class InvalidRequestError(BadRequestError):
"""A request made was malformed (i.e. violated the specification) and could
not be parsed."""
class InvalidReplyError(BadReplyError):
"""A reply received was malformed (i.e. violated the specification) and
could not be parsed into a response."""
class MethodNotFoundError(RPCError):
"""The desired method was not found."""
class ServerError(RPCError):
"""An internal error in the RPC system occured."""
"""Base class for all excetions thrown by :py:mod:`tinyrpc`."""
class BadRequestError(RPCError):
"""Base class for all errors that caused the processing of a request to
abort before a request object could be instantiated."""
def error_respond(self):
"""Create :py:class:`~tinyrpc.RPCErrorResponse` to respond the error.
:return: A error responce instance or ``None``, if the protocol decides
to drop the error silently."""
raise RuntimeError('Not implemented')
class BadReplyError(RPCError):
"""Base class for all errors that caused processing of a reply to abort
before it could be turned in a response object."""
class InvalidRequestError(BadRequestError):
"""A request made was malformed (i.e. violated the specification) and could
not be parsed."""
class InvalidReplyError(BadReplyError):
"""A reply received was malformed (i.e. violated the specification) and
could not be parsed into a response."""
class MethodNotFoundError(RPCError):
"""The desired method was not found."""
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class RPCError(Exception):
"""Base class for all excetions thrown by :py:mod:`tinyrpc`."""
class BadRequestError(RPCError):
"""Base class for all errors that caused the processing of a request to
abort before a request object could be instantiated."""
def error_respond(self):
"""Create :py:class:`~tinyrpc.RPCErrorResponse` to respond the error.
:return: A error responce instance or ``None``, if the protocol decides
to drop the error silently."""
raise RuntimeError('Not implemented')
class BadReplyError(RPCError):
"""Base class for all errors that caused processing of a reply to abort
before it could be turned in a response object."""
class BadReplyError(RPCError):
"""Base class for all errors that caused processing of a reply to abort
before it could be turned in a response object."""
class InvalidRequestError(BadRequestError):
"""A request made was malformed (i.e. violated the specification) and could
not be parsed."""
class InvalidReplyError(BadReplyError):
"""A reply received was malformed (i.e. violated the specification) and
could not be parsed into a response."""
class MethodNotFoundError(RPCError):
"""The desired method was not found."""
class ServerError(RPCError):
"""An internal error in the RPC system occured."""
def handle_message(context, message):
try:
request = self.protocol.parse_request(message)
except RPCError as e:
response = e.error_respond()
else:
response = self.dispatcher.dispatch(request)
# send reply
self.transport.send_reply(context, response.serialize())