# HG changeset patch # User Steve Losh # Date 1251507956 14400 # Node ID b346af17863f16e0cc6266d722ede5c3cf9f49b5 # Parent d5dc52a44e579d1e28d93c05cbc18a5b8f4dfa18 Add another exception to differentiate Unknown/Ambiguous prefixes. diff -r d5dc52a44e57 -r b346af17863f t.py --- a/t.py Fri Aug 28 20:59:11 2009 -0400 +++ b/t.py Fri Aug 28 21:05:56 2009 -0400 @@ -14,6 +14,10 @@ """Raised when trying to use a prefix that could identify multiple tasks.""" pass +class UnknownPrefix(Exception): + """Raised when trying to use a prefix that does not match any tasks.""" + pass + def _hash(s): """Return a hash of the given string for use as an id. @@ -91,12 +95,15 @@ """Return the unfinished task with the given prefix. If more than one task matches the prefix an AmbiguousPrefix exception - will be raised. + will be raised, if no tasks match it an UnknownPrefix exception will + be raised. """ matched = filter(lambda tid: tid.startswith(prefix), self.tasks.keys()) if len(matched) == 1: return self.tasks[matched[0]] + elif len(matched) == 0: + raise UnknownPrefix else: raise AmbiguousPrefix @@ -109,7 +116,8 @@ """Edit the task with the given prefix. If more than one task matches the prefix an AmbiguousPrefix exception - will be raised. + will be raised, if no tasks match it an UnknownPrefix exception will + be raised. """ task = self[prefix] @@ -124,7 +132,8 @@ """Mark the task with the given prefix as finished. If more than one task matches the prefix an AmbiguousPrefix exception - will be raised. + will be raised, if no tasks match it an UnknownPrefix exception will + be raised. """ self.tasks.pop(self[prefix]['id'])