X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/python-afs.git/blobdiff_plain/264e62aff58ab2cdc835cbce60cacca5b4d6236f..5f256964f30b0f7423034048b7911600f8d4c3a9:/afs/pts.py diff --git a/afs/pts.py b/afs/pts.py index cfbfb7d..f99bc8f 100644 --- a/afs/pts.py +++ b/afs/pts.py @@ -1,7 +1,12 @@ import collections -import _pts +from afs import _pts -class PTRelationSet(collections.MutableSet): +try: + SetMixin = collections.MutableSet +except AttributeError: + SetMixin = object + +class PTRelationSet(SetMixin): """Collection class for the groups/members of a PTEntry. This class, which acts like a set, is actually a view of the @@ -45,7 +50,8 @@ class PTRelationSet(collections.MutableSet): Args: elt: The element to add. """ - self._set.add(self._ent._pts.getEntry(elt)) + if hasattr(self, '_set'): + self._set.add(self._ent._pts.getEntry(elt)) def _discard(self, elt): """Remove a PTEntry to this instance's internal representation. @@ -57,7 +63,8 @@ class PTRelationSet(collections.MutableSet): Args: elt: The element to discard. """ - self._set.discard(self._ent._pts.getEntry(elt)) + if hasattr(self, '_set'): + self._set.discard(self._ent._pts.getEntry(elt)) def __len__(self): """Count the members/groups in this set. @@ -165,6 +172,16 @@ class PTRelationSet(collections.MutableSet): self._discard(elt) + def remove(self, elt): + """Remove an entity from a group; it must already be a member. + + If the entity is not a member, raise a KeyError. + """ + if elt not in self: + raise KeyError(elt) + + self.discard(elt) + class PTEntry(object): """An entry in the AFS protection database. @@ -248,6 +265,12 @@ class PTEntry(object): self._name = val name = property(_get_name, _set_name) + def _get_krbname(self): + return self._pts._AfsToKrb5(self.name) + def _set_krbname(self, val): + self.name = self._pts._Krb5ToAfs(val) + krbname = property(_get_krbname, _set_krbname) + def _get_count(self): self._loadEntry() return self._count @@ -354,6 +377,14 @@ class PTS(_pts.PTS): else: return PTEntry(self, id=ident) + def getEntryFromKrbname(self, ident): + """Retrieve a PTEntry matching a given Kerberos v5 principal. + + getEntryFromKrb accepts a krb5 principal, converts it to the + equivalent AFS principal, and returns a PTEntry for that + principal.""" + return self.getEntry(self._Krb5ToAfs(ident)) + def expire(self): """Flush the cache of PTEntry objects.