Add another exception to differentiate Unknown/Ambiguous prefixes.
author |
Steve Losh <steve@stevelosh.com> |
date |
Fri, 28 Aug 2009 21:05:56 -0400 |
parents |
d5dc52a44e57
|
children |
8cc8f8b24bb3
|
branches/tags |
(none) |
files |
t.py |
Changes
--- 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'])