Base class for key, value containers where the values are sequences.
| 106 | |
| 107 | |
| 108 | class Storage(ABC): |
| 109 | '''Base class for key, value containers where the values are sequences.''' |
| 110 | def __getitem__(self, key): |
| 111 | return self.get(key) |
| 112 | |
| 113 | def __delitem__(self, key): |
| 114 | return self.remove(key) |
| 115 | |
| 116 | def __len__(self): |
| 117 | return self.size() |
| 118 | |
| 119 | def __iter__(self): |
| 120 | for key in self.keys(): |
| 121 | yield key |
| 122 | |
| 123 | def __contains__(self, item): |
| 124 | return self.has_key(item) |
| 125 | |
| 126 | @abstractmethod |
| 127 | def keys(self): |
| 128 | '''Return an iterator on keys in storage''' |
| 129 | return [] |
| 130 | |
| 131 | @abstractmethod |
| 132 | def get(self, key): |
| 133 | '''Get list of values associated with a key |
| 134 | |
| 135 | Returns empty list ([]) if `key` is not found |
| 136 | ''' |
| 137 | pass |
| 138 | |
| 139 | def getmany(self, *keys): |
| 140 | return [self.get(key) for key in keys] |
| 141 | |
| 142 | @abstractmethod |
| 143 | def insert(self, key, *vals, **kwargs): |
| 144 | '''Add `val` to storage against `key`''' |
| 145 | pass |
| 146 | |
| 147 | @abstractmethod |
| 148 | def remove(self, *keys): |
| 149 | '''Remove `keys` from storage''' |
| 150 | pass |
| 151 | |
| 152 | @abstractmethod |
| 153 | def remove_val(self, key, val): |
| 154 | '''Remove `val` from list of values under `key`''' |
| 155 | pass |
| 156 | |
| 157 | @abstractmethod |
| 158 | def size(self): |
| 159 | '''Return size of storage with respect to number of keys''' |
| 160 | pass |
| 161 | |
| 162 | @abstractmethod |
| 163 | def itemcounts(self, **kwargs): |
| 164 | '''Returns the number of items stored under each key''' |
| 165 | pass |
nothing calls this directly
no outgoing calls
no test coverage detected