Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/lxml/html/_setmixin.py
811 views
1
try:
2
from collections.abc import MutableSet
3
except ImportError:
4
from collections import MutableSet
5
6
7
class SetMixin(MutableSet):
8
9
"""
10
Mix-in for sets. You must define __iter__, add, remove
11
"""
12
13
def __len__(self):
14
length = 0
15
for item in self:
16
length += 1
17
return length
18
19
def __contains__(self, item):
20
for has_item in self:
21
if item == has_item:
22
return True
23
return False
24
25
issubset = MutableSet.__le__
26
issuperset = MutableSet.__ge__
27
28
union = MutableSet.__or__
29
intersection = MutableSet.__and__
30
difference = MutableSet.__sub__
31
symmetric_difference = MutableSet.__xor__
32
33
def copy(self):
34
return set(self)
35
36
def update(self, other):
37
self |= other
38
39
def intersection_update(self, other):
40
self &= other
41
42
def difference_update(self, other):
43
self -= other
44
45
def symmetric_difference_update(self, other):
46
self ^= other
47
48
def discard(self, item):
49
try:
50
self.remove(item)
51
except KeyError:
52
pass
53
54
@classmethod
55
def _from_iterable(cls, it):
56
return set(it)
57
58