Comments
Patch
@@ -933,3 +933,37 @@ def finddirs(path):
while pos != -1:
yield path[:pos]
pos = path.rfind('/', 0, pos)
+
+class dirs(object):
+ def __init__(self, m, skip=None):
+ self._dirs = {}
+ addpath = self.addpath
+ if util.safehasattr(m, 'iteritems') and skip is not None:
+ for f, s in m.iteritems():
+ if s[0] != skip:
+ addpath(f)
+ else:
+ for f in m:
+ addpath(f)
+
+ def addpath(self, path):
+ dirs = self._dirs
+ for base in finddirs(path):
+ if base in dirs:
+ dirs[base] += 1
+ return
+ dirs[base] = 1
+
+ def delpath(self, path):
+ dirs = self._dirs
+ for base in finddirs(path):
+ if dirs[base] > 1:
+ dirs[base] -= 1
+ return
+ del dirs[base]
+
+ def __iter__(self):
+ return self._dirs.iterkeys()
+
+ def __contains__(self, d):
+ return d in self._dirs