forked from hyperledger/indy-plenum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstashing_deque.py
92 lines (65 loc) · 2.48 KB
/
stashing_deque.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from collections import deque
# TODO: Remove it if its not needed anymore
class StashingDeque:
def __init__(self):
super().__init__()
self.main = deque()
self.stashed = deque()
self._stashEverything = False
@property
def stashEverything(self):
return self._stashEverything
@stashEverything.setter
def stashEverything(self, value):
self._stashEverything = value
if not self._stashEverything:
self.unstashAll()
# manually stash an item
def stash(self, item):
self.stashed.append(item)
# manually unstash all items
def unstashAll(self):
self.main.extend(self.stashed)
def enterStashMode(self):
self.stashEverything = True
def leaveStashMode(self):
self.stashEverything = False
def _curDeq(self):
return self.stashed if self._stashEverything else self.main
def append(self, *args, **kwargs):
return self._curDeq().append(*args, **kwargs)
def appendleft(self, *args, **kwargs):
return self._curDeq().appendLeft(*args, **kwargs)
def clear(self, *args, **kwargs):
self.main.clear(*args, **kwargs)
self.stashed.clear(*args, **kwargs)
def extend(self, *args, **kwargs):
return self._curDeq().extend(*args, **kwargs)
def extendleft(self, *args, **kwargs):
return self._curDeq().extendLeft(*args, **kwargs)
def pop(self, *args, **kwargs):
return self.main.pop(*args, **kwargs)
def popleft(self, *args, **kwargs):
return self.main.popLeft(*args, **kwargs)
def remove(self, value):
return self.main.pop(value)
def reverse(self):
return self.main.reverse()
def rotate(self, *args, **kwargs):
return self.main.rotate(*args, **kwargs)
def __contains__(self, *args, **kwargs):
return self.main.__contains__(*args, **kwargs)
def __delitem__(self, *args, **kwargs):
return self.main.__delitem__(*args, **kwargs)
def __getitem__(self, *args, **kwargs):
return self.main.__getitem__(*args, **kwargs)
def __iter__(self, *args, **kwargs):
return self.main.__iter__(*args, **kwargs)
def __len__(self, *args, **kwargs):
return self.main.__len__(*args, **kwargs)
def __reversed__(self):
return self.main.__reversed__()
def __setitem__(self, *args, **kwargs):
return self.main.__setitem__(*args, **kwargs)
def __sizeof__(self):
return self.main.__sizeof__()