-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpoc-05.py
executable file
·78 lines (54 loc) · 1.59 KB
/
poc-05.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
76
77
78
#!/usr/bin/python3
#
# https://github.com/OfflineIMAP/imapfw/wiki/sync-05
#
class Message(object):
def __init__(self, uid=None, body=None, flags=['unread']):
self.uid = uid
self.body = body
self.flags = flags
def __repr__(self):
return "<Message %s [%s] '%s'>"% (self.uid,
','.join(self.flags), self.body)
# Messages
m1 = Message(1, "1 body")
m2 = Message(2, "2 body")
m3 = Message(3, "3 body")
m4 = Message(4, "4 body")
class Messages(list):
"""Enable collections of messages the easy way."""
pass
class LeftDriver(object):
def __init__(self):
self.messages = Messages([m1, m2])
def search(self):
return self.messages
class RightDriver(object):
def __init__(self):
self.messages = Messages([m1, m3])
def search(self):
return self.messages
class StateController(object):
def __init__(self, driver):
self.driver = driver
def search(self):
messages = self.driver.search()
messages.append(m4)
return messages
def __getattr__(self, name):
return getattr(self.driver, name)
class Engine(object):
"""The engine."""
def __init__(self):
self.left = LeftDriver()
self.right = RightDriver()
def run(self):
# Driver will need API to work on chained controllers.
self.right = StateController(self.right)
leftMessages = self.left.search()
rightMessages = self.right.search()
print(leftMessages)
print(rightMessages)
if __name__ == '__main__':
engine = Engine()
engine.run()