+ def apply(self, dir, follow=True):
+ """Apply the ACL to a directory"""
+ self._clean()
+ _acl.setAcl(dir, _unparseAcl(self.pos, self.neg), follow)
+ def _clean(self):
+ """Clean an ACL by removing any entries whose bitmask is 0"""
+ for n,a in self.pos.items():
+ if a == 0:
+ del self.pos[n]
+ for n,a in self.neg.items():
+ if a == 0:
+ del self.neg[n]
+ def set(self, user, bitmask, negative=False):
+ """Set the bitmask for a given user"""
+ if bitmask < 0 or bitmask > max(_char2bit.values()):
+ raise ValueError, "Invalid bitmask"
+ if negative:
+ self.neg[user] = bitmask
+ else:
+ self.pos[user] = bitmask
+ def remove(self, user, negative=False):
+ """Convenience function to removeSet the bitmask for a given user"""
+ self.set(user, 0, negative)
+