Package ldaptor :: Module attributeset
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.attributeset

 1  import sets 
 2  from copy import deepcopy 
 3   
4 -class LDAPAttributeSet(sets.Set):
5 - def __init__(self, key, *a, **kw):
6 self.key = key 7 super(LDAPAttributeSet, self).__init__(*a, **kw)
8
9 - def __repr__(self):
10 values=list(self) 11 values.sort() 12 attributes=', '.join([repr(x) for x in values]) 13 return '%s(%r, [%s])' % ( 14 self.__class__.__name__, 15 self.key, 16 attributes)
17
18 - def __eq__(self, other):
19 """ 20 Note that LDAPAttributeSets can also be compared against any 21 iterator. In that case the attributeType will be ignored. 22 """ 23 if isinstance(other, LDAPAttributeSet): 24 if self.key != other.key: 25 return False 26 return super(LDAPAttributeSet, self).__eq__(other) 27 else: 28 me=list(self) 29 me.sort() 30 him=list(other) 31 him.sort() 32 return me == him
33
34 - def __ne__(self, other):
35 return not self==other
36
37 - def difference(self, other):
38 return sets.Set(self) - sets.Set(other)
39
40 - def union(self, other):
41 return sets.Set(self) | sets.Set(other)
42
43 - def intersection(self, other):
44 return sets.Set(self) & sets.Set(other)
45
46 - def symmetric_difference(self, other):
47 return sets.Set(self) ^ sets.Set(other)
48
49 - def copy(self):
50 result = self.__class__(self.key) 51 result.update(self) 52 return result
53 __copy__ = copy 54
55 - def __deepcopy__(self, memo):
56 result = self.__class__(self.key) 57 memo[id(self)] = result 58 data = deepcopy(sets.Set(self), memo) 59 result.update(data) 60 return result
61