if name == "." or name == ".." or "/" in name:
raise DeadDirectoryNodeError("bad filename component")
- # this is private
- def get_child(self, name):
- self.validate_name(name)
- absname = os.path.join(self._basedir, name)
- if os.path.isdir(absname):
- return self.make_subnode(absname)
- raise DeadDirectoryNodeError("no such directory")
-
# these are the public methods, available to anyone who holds a reference
def list(self):
return results
remote_list = list
+ def get(self, name):
+ self.validate_name(name)
+ absname = os.path.join(self._basedir, name)
+ if os.path.isdir(absname):
+ return self.make_subnode(absname)
+ elif os.path.isfile(absname):
+ f = open(absname, "rb")
+ data = f.read()
+ f.close()
+ return data
+ else:
+ raise BadFileError("there is nothing named '%s' in this directory"
+ % name)
+ remote_get = get
+
def add_directory(self, name):
self.validate_name(name)
absname = os.path.join(self._basedir, name)
self.failUnlessRaises(BadFileError, root.remove, "two")
self.failUnlessRaises(BadFileError, root.remove, "three")
+ self.failUnlessEqual(root.get("one"), "vid-one")
+ self.failUnlessRaises(BadFileError, root.get, "missing")
+
# now play with directories
subdir1 = root.add_directory("subdir1")
self.failUnless(isinstance(subdir1, MutableDirectoryNode))
+ subdir1a = root.get("subdir1")
+ self.failUnless(isinstance(subdir1a, MutableDirectoryNode))
+ self.failUnlessEqual(subdir1a._basedir, subdir1._basedir)
entries = root.list()
self.failUnlessEqual(len(entries), 2)
one_index = entries.index( ("one", "vid-one") )