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

Source Code for Module ldaptor.attributeset

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