shep

Multi-state key stores using bit masks for python3
git clone git://git.defalsify.org/shep.git
Log | Files | Refs | LICENSE

commit aff0da4d841f6ada07725539b556e389ef1bcf24
parent 3de0ad8ee357c2e77f6e7c400bdf04d4fe85d808
Author: lash <dev@holbrook.no>
Date:   Tue,  1 Feb 2022 06:29:51 +0000

Rename items to keys in state file

Diffstat:
Mshep/state.py | 56+++++++++++++++++++++++++++++---------------------------
1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/shep/state.py b/shep/state.py @@ -16,8 +16,9 @@ class State: self.NEW = 0 self.__reverse = {0: self.NEW} - self.__items = {self.NEW: []} - self.__items_reverse = {} + self.__keys = {self.NEW: []} + self.__keys_reverse = {} + self.__contents = {} def __is_pure(self, v): @@ -72,16 +73,16 @@ class State: self.__c += 1 - def __check_item(self, item): - if self.__items_reverse.get(item) != None: + def __check_key(self, item): + if self.__keys_reverse.get(item) != None: raise StateItemExists(item) def __add_state_list(self, state, item): - if self.__items.get(state) == None: - self.__items[state] = [] - self.__items[state].append(item) - self.__items_reverse[item] = state + if self.__keys.get(state) == None: + self.__keys[state] = [] + self.__keys[state].append(item) + self.__keys_reverse[item] = state def __state_list_index(self, item, state_list): @@ -152,53 +153,54 @@ class State: return (alias, r,) - def put(self, item, state=None): + def put(self, key, state=None, contents=None): if state == None: state = self.NEW elif self.__reverse.get(state) == None: raise StateInvalid(state) - self.__check_item(item) - self.__add_state_list(state, item) + self.__check_key(key) + self.__add_state_list(state, key) + self.__contents[key] = contents - def move(self, item, to_state): - current_state = self.__items_reverse.get(item) + def move(self, key, to_state): + current_state = self.__keys_reverse.get(key) if current_state == None: - raise StateItemNotFound(item) + raise StateItemNotFound(key) new_state = self.__reverse.get(to_state) if new_state == None: raise StateInvalid(to_state) - current_state_list = self.__items.get(current_state) + current_state_list = self.__keys.get(current_state) if current_state_list == None: raise StateCorruptionError(current_state) - idx = self.__state_list_index(item, current_state_list) + idx = self.__state_list_index(key, current_state_list) - new_state_list = self.__items.get(to_state) + new_state_list = self.__keys.get(to_state) if current_state_list == None: raise StateCorruptionError(to_state) - self.__add_state_list(to_state, item) + self.__add_state_list(to_state, key) current_state_list.pop(idx) - def purge(self, item): - current_state = self.__items_reverse.get(item) + def purge(self, key): + current_state = self.__keys_reverse.get(key) if current_state == None: - raise StateItemNotFound(item) - del self.__items_reverse[item] + raise StateItemNotFound(key) + del self.__keys_reverse[key] - current_state_list = self.__items.get(current_state) + current_state_list = self.__keys.get(current_state) - idx = self.__state_list_index(item, current_state_list) + idx = self.__state_list_index(key, current_state_list) current_state_list.pop(idx) - def state(self, item): - state = self.__items_reverse.get(item) + def state(self, key): + state = self.__keys_reverse.get(key) if state == None: - raise StateItemNotFound(item) + raise StateItemNotFound(key) return state