Package lxml :: Package html :: Module setmixin
[hide private]
[frames] | no frames]

Source Code for Module lxml.html.setmixin

1 -class SetMixin(object):
2 3 """ 4 Mix-in for sets. You must define __iter__, add, remove 5 """ 6
7 - def __len__(self):
8 return len(list(self))
9
10 - def __contains__(self, item):
11 for has_item in self: 12 if item == has_item: 13 return True 14 return False
15
16 - def issubset(self, other):
17 for item in other: 18 if item not in self: 19 return False 20 return True
21 22 __le__ = issubset 23
24 - def issuperset(self, other):
25 for item in self: 26 if item not in other: 27 return False 28 return True
29 30 __ge__ = issuperset 31
32 - def union(self, other):
33 return self | other
34
35 - def __or__(self, other):
36 new = self.copy() 37 new |= other 38 return new
39
40 - def intersection(self, other):
41 return self & other
42
43 - def __and__(self, other):
44 new = self.copy() 45 new &= other 46 return new
47
48 - def difference(self, other):
49 return self - other
50
51 - def __sub__(self, other):
52 new = self.copy() 53 new -= other 54 return new
55
56 - def symmetric_difference(self, other):
57 return self ^ other
58
59 - def __xor__(self, other):
60 new = self.copy() 61 new ^= other 62 return new
63
64 - def copy(self):
65 return set(self)
66
67 - def update(self, other):
68 for item in other: 69 self.add(item)
70 71 __ior__ = update 72
73 - def intersection_update(self, other):
74 for item in self: 75 if item not in other: 76 self.remove(item)
77 78 __iand__ = intersection_update 79
80 - def difference_update(self, other):
81 for item in other: 82 if item in self: 83 self.remove(item)
84 85 __isub__ = difference_update 86
87 - def symmetric_difference_update(self, other):
88 for item in other: 89 if item in self: 90 self.remove(item) 91 else: 92 self.add(item)
93 94 __ixor__ = symmetric_difference_update 95
96 - def discard(self, item):
97 try: 98 self.remove(item) 99 except KeyError: 100 pass
101
102 - def clear(self):
103 for item in list(self): 104 self.remove(item)
105