Commit 42599971 by Őry Máté

check for command args to be supplied in a dict

parent 6faa8044
...@@ -347,17 +347,11 @@ class SerialLineReceiver(SerialLineReceiverBase): ...@@ -347,17 +347,11 @@ class SerialLineReceiver(SerialLineReceiverBase):
self.send_response(response='status', self.send_response(response='status',
args=args) args=args)
def _get_command(self, command, args): def _check_args(self, func, args):
if not isinstance(command, basestring) or command.startswith('_'): if not isinstance(args, dict):
raise AttributeError(u'Invalid command: %s' % command) raise TypeError("Arguments should be all keyword-arguments in a "
try: "dict for command %s instead of %s." %
func = getattr(Context, command) (self._pretty_fun(func), type(args).__name__))
except AttributeError as e:
raise AttributeError(u'Command not found: %s (%s)' % (command, e))
if not isfunction(func):
raise AttributeError("Command refers to non-static method %s." %
self._pretty_fun(func))
# check for unexpected keyword arguments # check for unexpected keyword arguments
argspec = getargspec(func) argspec = getargspec(func)
...@@ -376,6 +370,19 @@ class SerialLineReceiver(SerialLineReceiverBase): ...@@ -376,6 +370,19 @@ class SerialLineReceiver(SerialLineReceiverBase):
raise TypeError("Command %s missing arguments: %s" % ( raise TypeError("Command %s missing arguments: %s" % (
self._pretty_fun(func), ", ".join(missing_kwargs))) self._pretty_fun(func), ", ".join(missing_kwargs)))
def _get_command(self, command, args):
if not isinstance(command, basestring) or command.startswith('_'):
raise AttributeError(u'Invalid command: %s' % command)
try:
func = getattr(Context, command)
except AttributeError as e:
raise AttributeError(u'Command not found: %s (%s)' % (command, e))
if not isfunction(func):
raise AttributeError("Command refers to non-static method %s." %
self._pretty_fun(func))
self._check_args(func, args)
return func return func
@staticmethod @staticmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment