shep

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

commit 60dee4167e5b968306882784fb00acf0ee2725c5
parent 2a09b508b376aa644cfb8c7adba4a69799a21ed3
Author: lash <dev@holbrook.no>
Date:   Tue,  1 Feb 2022 09:55:12 +0000

Add list by state

Diffstat:
MCHANGELOG | 3+++
Msetup.cfg | 2+-
Mshep/persist.py | 7-------
Mshep/state.py | 8+++++++-
Mtests/test_file.py | 18++++++++++++++++++
5 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,6 @@ +- 0.0.9 + * Add optional overwrite of contents + * Add list all keys by state - 0.0.8 * Add single bit transition to aliases - 0.0.7 diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = shep -version = 0.0.8 +version = 0.0.9 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 @@ -47,10 +47,3 @@ class PersistedState(State): self.__stores[k].remove(key) super(PersistedState, self).purge(key) - - - def get(self, key=None): - state = self.state(key) - k = self.name(state) - - return self.__stores[k].get(key) diff --git a/shep/state.py b/shep/state.py @@ -249,5 +249,11 @@ class State: return state - def get(self, key): + def get(self, key=None): return self.__contents.get(key) + + + def list(self, state): + if self.__reverse.get(state) == None: + raise StateInvalid(state) + return self.__keys[state] diff --git a/tests/test_file.py b/tests/test_file.py @@ -50,5 +50,23 @@ class TestStateReport(unittest.TestCase): self.assertEqual(self.states.get('abcd'), 'bar') + def test_list(self): + self.states.put('abcd', state=self.states.FOO) + self.states.put('xx!', state=self.states.FOO) + self.states.put('1234', state=self.states.BAR) + keys = self.states.list(self.states.FOO) + self.assertIn('abcd', keys) + self.assertIn('xx!', keys) + self.assertNotIn('1234', keys) + + self.states.alias('xyzzy', self.states.BAR | self.states.FOO) + self.states.put('yyy', state=self.states.XYZZY) + + keys = self.states.list(self.states.XYZZY) + self.assertIn('yyy', keys) + self.assertNotIn('1234', keys) + self.assertNotIn('xx!', keys) + + if __name__ == '__main__': unittest.main()