-
Notifications
You must be signed in to change notification settings - Fork 0
/
creator.py
75 lines (59 loc) · 2.24 KB
/
creator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pickle
class Subscription:
def __init__(self, sid: str, email: str, component: str):
self.__sid = sid
self.__email = email
self.__component = component
@property
def sid(self):
return self.__sid
@property
def email(self):
return self.__email
@property
def component(self):
return self.__component
def __eq__(self, other):
if isinstance(other, Subscription):
return self.sid == other.sid and \
self.email == other.email and \
self.component == other.component
return NotImplemented
def __ne__(self, other):
if isinstance(other, Subscription):
return self.sid != other.sid or \
self.email != other.email or \
self.component != other.component
return NotImplemented
def __lt__(self, other):
if isinstance(other, Subscription):
return '/'.join([self.sid, self.component, self.email]) \
< '/'.join([other.sid, other.component, other.email])
return NotImplemented
def __gt__(self, other):
if isinstance(other, Subscription):
return '/'.join([self.sid, self.component, self.email]) \
> '/'.join([other.sid, other.component, other.email])
return NotImplemented
def __le__(self, other):
if isinstance(other, Subscription):
return '/'.join([self.sid, self.component, self.email]) \
<= '/'.join([other.sid, other.component, other.email])
return NotImplemented
def __ge__(self, other):
if isinstance(other, Subscription):
return '/'.join([self.sid, self.component, self.email]) \
>= '/'.join([other.sid, other.component, other.email])
return NotImplemented
def __hash__(self):
return hash((self.sid, self.email, self.component))
def main():
res = []
res.append(Subscription("a", "[email protected]", "compa"))
res.append(Subscription("b", "[email protected]", "compa"))
res.append(Subscription("c", "[email protected]", "compa"))
dbfile = open('examplePickle', 'ab')
pickle.dump(res, dbfile)
dbfile.close()
if __name__ == "__main__":
main()