+ self.fileobj = fileobj
+ self.fileobj.inc_use()
+
+ def release(self):
+ self.fileobj.dec_use()
+
+
+class DirectoryHandle(object):
+ """Connects a numeric file handle to a Directory object that has
+ been opened by the client."""
+
+ def __init__(self, fh, dirobj, entries):
+ self.fh = fh
+ self.entries = entries
+ self.dirobj = dirobj
+ self.dirobj.inc_use()
+
+ def release(self):
+ self.dirobj.dec_use()
+
+
+class ObjectCache(object):
+ def __init__(self, cap):
+ self._entries = collections.OrderedDict()
+ self._counter = itertools.count(1)
+ self.cap = cap
+
+ def cap_cache(self):
+ if len(self._entries) > self.cap:
+ ent = iter(self._entries)
+ ents = [next(ent) for i in xrange(0, len(self._entries) - self.cap)]
+ for key in ents:
+ capobj = self._entries[key]
+ if capobj.clear():
+ del self._entries[key]
+
+ def manage(self, obj):
+ obj._cache_priority = next(self._counter)
+ self._entries[obj._cache_priority] = obj
+ self.cap_cache()
+
+ def touch(self, obj):
+ if obj._cache_priority in self._entries:
+ del self._entries[obj._cache_priority]
+ self.manage(obj)
+
+ def unmanage(self, obj):
+ if obj._cache_priority in self._entries:
+ if obj.clear():
+ del self._entries[obj._cache_priority]