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