shep

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

commit 488687a8d85c23b60dfd10e924eb1ec8cf113b77
parent a95a25f7456171b6e2c561e2f55a6cd22eec1733
Author: lash <dev@holbrook.no>
Date:   Thu,  3 Feb 2022 10:05:59 +0000

ADd method to resolve name string to state property

Diffstat:
MCHANGELOG | 4++++
Msetup.cfg | 2+-
Mshep/persist.py | 2++
Mshep/state.py | 11++++++++---
Mtests/test_state.py | 6++++++
5 files changed, 21 insertions(+), 4 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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()