diff --git a/CHANGELOG b/CHANGELOG index 00ac77b..0cd2071 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +- 0.0.17 + * Add reverse lookup method for name to state property +- 0.0.16 + * Ensure store is present if path query for NEW is fired before any put - 0.0.15 * Add missing store module in setup - 0.0.14 diff --git a/setup.cfg b/setup.cfg index 24284bb..ae5d287 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = shep -version = 0.0.15 +version = 0.0.17 description = Multi-state key stores using bit masks author = Louis Holbrook author_email = dev@holbrook.no diff --git a/shep/persist.py b/shep/persist.py index caa1be9..a5c9386 100644 --- a/shep/persist.py +++ b/shep/persist.py @@ -87,6 +87,8 @@ class PersistedState(State): def sync(self, state): k = self.name(state) + self.__ensure_store(k) + for o in self.__stores[k].list(): self.__ensure_store(k) try: diff --git a/shep/state.py b/shep/state.py index 27b4c27..ae440e6 100644 --- a/shep/state.py +++ b/shep/state.py @@ -35,12 +35,12 @@ class State: def __check_name_valid(self, k): if not k.isalpha(): raise ValueError('only alpha') + return k.upper() def __check_name(self, k): - self.__check_name_valid(k) - - k = k.upper() + k = self.__check_name_valid(k) + try: getattr(self, k) raise StateExists(k) @@ -140,6 +140,11 @@ class State: return k + def from_name(self, k): + k = self.__check_name_valid(k) + return getattr(self, k) + + def match(self, v, pure=False): alias = None if not pure: diff --git a/tests/test_state.py b/tests/test_state.py index ec2c9b2..d6bab80 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -93,5 +93,11 @@ class TestState(unittest.TestCase): self.assertEqual(states.peek('abcd')) + def test_from_name(self): + states = State(3) + states.add('foo') + self.assertEqual(states.from_name('foo'), states.FOO) + + if __name__ == '__main__': unittest.main()