web: use KeyError (rather than IndexError) to signal a missing child

This commit is contained in:
Brian Warner 2007-07-06 19:40:08 -07:00
parent a34040df99
commit 71c04fc2e7
2 changed files with 9 additions and 9 deletions

View File

@ -78,7 +78,7 @@ class VirtualDriveServer(service.MultiService, Referenceable):
for (H_key, E_key, E_write, E_read) in data[1]:
if H_key == key:
return (E_write, E_read)
raise IndexError("unable to find key %s" % idlib.b2a(key))
raise KeyError("unable to find key %s" % idlib.b2a(key))
remote_get = get
def list(self, index):
@ -97,7 +97,7 @@ class VirtualDriveServer(service.MultiService, Referenceable):
del data[1][i]
self._write_to_file(index, data)
return
raise IndexError("unable to find key %s" % idlib.b2a(key))
raise KeyError("unable to find key %s" % idlib.b2a(key))
remote_delete = delete
def set(self, index, write_enabler, key, name, write, read):
@ -240,9 +240,9 @@ class ImmutableDirectoryNode:
H_name = self._hash_name(name)
d = self._rref.callRemote("get", self._index, H_name)
def _check_index_error(f):
f.trap(IndexError)
raise IndexError("get(index=%s): unable to find child named '%s'"
% (idlib.b2a(self._index), name))
f.trap(KeyError)
raise KeyError("get(index=%s): unable to find child named '%s'"
% (idlib.b2a(self._index), name))
d.addErrback(_check_index_error)
d.addCallback(lambda (E_write, E_read):
self._decrypt_child(E_write, E_read))

View File

@ -46,7 +46,7 @@ class DirectoryNode(unittest.TestCase):
("write1", "read1"))
self.failUnlessEqual(vds.get(index, "key2"),
("", "read2"))
self.failUnlessRaises(IndexError,
self.failUnlessRaises(KeyError,
vds.get, index, "key3")
self.failUnlessEqual(sorted(vds.list(index)),
@ -61,7 +61,7 @@ class DirectoryNode(unittest.TestCase):
[ ("name1", "write1", "read1"),
("name2", "", "read2"),
])
self.failUnlessRaises(IndexError,
self.failUnlessRaises(KeyError,
vds.delete,
index, we, "key3")
@ -69,7 +69,7 @@ class DirectoryNode(unittest.TestCase):
self.failUnlessEqual(sorted(vds.list(index)),
[ ("name2", "", "read2"),
])
self.failUnlessRaises(IndexError,
self.failUnlessRaises(KeyError,
vds.get, index, "key1")
self.failUnlessEqual(vds.get(index, "key2"),
("", "read2"))
@ -197,7 +197,7 @@ class Test(unittest.TestCase):
d.addCallback(lambda res: rootnode.get("missing"))
# this should raise an exception
d.addBoth(self.shouldFail, IndexError, "get('missing')",
d.addBoth(self.shouldFail, KeyError, "get('missing')",
"unable to find child named 'missing'")
d.addCallback(lambda res: rootnode.create_empty_directory("bar"))