command - is the command that raised the exception, expressed as a list of
paths (or subcommands).
"""
+ pass
- def __init__(self, command):
- r"""Initialize the Error object.
+class HandlerError(Error):
+ r"""
+ HandlerError(command) -> HandlerError instance :: Base handlers exception.
- See Error class documentation for more info.
- """
- self.command = command
+ All exceptions raised by the handlers should inherit from this one, so
+ dispatching errors could be separated from real programming errors (bugs).
+ """
+ pass
- def __str__(self):
- return ' '.join(self.command)
class CommandNotFoundError(Error):
r"""
This exception is raised when the command received can't be dispatched
because there is no handlers to process it.
"""
- pass
+
+ def __init__(self, command):
+ r"""Initialize the Error object.
+
+ See Error class documentation for more info.
+ """
+ self.command = command
+
+ def __str__(self):
+ return 'Command not found: "%s"' % ' '.join(self.command)
def handler(f):
f._dispatcher_handler = True
raise CommandNotFoundError(command)
handler = getattr(handler, route[0])
route = route[1:]
- handler(*route)
+ return handler(*route)
if __name__ == '__main__':