X-Git-Url: https://git.llucax.com/software/pymin.git/blobdiff_plain/d46203541c7463746edf19344d3ddbd1fb412128..31a4ad5fa2a20910d6faf28e3b481bcb232d3a6d:/dispatcher.py?ds=inline diff --git a/dispatcher.py b/dispatcher.py index addd45f..b78db93 100644 --- a/dispatcher.py +++ b/dispatcher.py @@ -18,16 +18,17 @@ class Error(RuntimeError): 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""" @@ -36,7 +37,16 @@ class CommandNotFoundError(Error): 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 @@ -108,7 +118,7 @@ class Dispatcher: raise CommandNotFoundError(command) handler = getattr(handler, route[0]) route = route[1:] - handler(*route) + return handler(*route) if __name__ == '__main__':