add IDirectoryNode.get_child_at_path

This commit is contained in:
Brian Warner
2007-07-06 19:38:37 -07:00
parent 9dc9f59a86
commit 9e42dda6a4
3 changed files with 40 additions and 0 deletions

View File

@ -362,6 +362,20 @@ class ImmutableDirectoryNode:
wk, we, rk, index = hashutil.generate_dirnode_keys_from_readkey(rk)
return "DIR-REFRESH:%s" % idlib.b2a(index)
def get_child_at_path(self, path):
if not path:
return self
if isinstance(path, (str, unicode)):
path = path.split("/")
childname = path[0]
remaining_path = path[1:]
d = self.get(childname)
if remaining_path:
def _got(node):
return node.get_child_at_path(remaining_path)
d.addCallback(_got)
return d
class MutableDirectoryNode(ImmutableDirectoryNode):
implements(IDirectoryNode)